]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-client.git/commitdiff
drbd: Replace deprecated strcpy with strscpy
authorThorsten Blum <thorsten.blum@linux.dev>
Mon, 12 Jan 2026 17:04:12 +0000 (18:04 +0100)
committerJens Axboe <axboe@kernel.dk>
Thu, 19 Feb 2026 15:22:02 +0000 (08:22 -0700)
strcpy() has been deprecated [1] because it performs no bounds checking
on the destination buffer, which can lead to buffer overflows. Replace
it with the safer strscpy().  No functional changes.

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Reviewed-by: Christoph Böhmwalder <christoph.boehmwalder@linbit.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/drbd/drbd_main.c
drivers/block/drbd/drbd_receiver.c

index 1f6ac9202b66a14e9973d9d087081e0799aa0005..ba00b5f21a496615b3e1f25c24f7f2acb41c090f 100644 (file)
@@ -32,6 +32,7 @@
 #include <linux/memcontrol.h>
 #include <linux/mm_inline.h>
 #include <linux/slab.h>
+#include <linux/string.h>
 #include <linux/random.h>
 #include <linux/reboot.h>
 #include <linux/notifier.h>
@@ -732,9 +733,9 @@ int drbd_send_sync_param(struct drbd_peer_device *peer_device)
        }
 
        if (apv >= 88)
-               strcpy(p->verify_alg, nc->verify_alg);
+               strscpy(p->verify_alg, nc->verify_alg);
        if (apv >= 89)
-               strcpy(p->csums_alg, nc->csums_alg);
+               strscpy(p->csums_alg, nc->csums_alg);
        rcu_read_unlock();
 
        return drbd_send_command(peer_device, sock, cmd, size, NULL, 0);
@@ -745,6 +746,7 @@ int __drbd_send_protocol(struct drbd_connection *connection, enum drbd_packet cm
        struct drbd_socket *sock;
        struct p_protocol *p;
        struct net_conf *nc;
+       size_t integrity_alg_len;
        int size, cf;
 
        sock = &connection->data;
@@ -762,8 +764,10 @@ int __drbd_send_protocol(struct drbd_connection *connection, enum drbd_packet cm
        }
 
        size = sizeof(*p);
-       if (connection->agreed_pro_version >= 87)
-               size += strlen(nc->integrity_alg) + 1;
+       if (connection->agreed_pro_version >= 87) {
+               integrity_alg_len = strlen(nc->integrity_alg) + 1;
+               size += integrity_alg_len;
+       }
 
        p->protocol      = cpu_to_be32(nc->wire_protocol);
        p->after_sb_0p   = cpu_to_be32(nc->after_sb_0p);
@@ -778,7 +782,7 @@ int __drbd_send_protocol(struct drbd_connection *connection, enum drbd_packet cm
        p->conn_flags    = cpu_to_be32(cf);
 
        if (connection->agreed_pro_version >= 87)
-               strcpy(p->integrity_alg, nc->integrity_alg);
+               strscpy(p->integrity_alg, nc->integrity_alg, integrity_alg_len);
        rcu_read_unlock();
 
        return __conn_send_command(connection, sock, cmd, size, NULL, 0);
index 3de919b6f0e144f5cfb9bc2e95da3bb8df0cba5f..3d0a061b6c40ca70836cc3b2192e88e1c1f60de5 100644 (file)
@@ -3801,14 +3801,14 @@ static int receive_SyncParam(struct drbd_connection *connection, struct packet_i
                        *new_net_conf = *old_net_conf;
 
                        if (verify_tfm) {
-                               strcpy(new_net_conf->verify_alg, p->verify_alg);
+                               strscpy(new_net_conf->verify_alg, p->verify_alg);
                                new_net_conf->verify_alg_len = strlen(p->verify_alg) + 1;
                                crypto_free_shash(peer_device->connection->verify_tfm);
                                peer_device->connection->verify_tfm = verify_tfm;
                                drbd_info(device, "using verify-alg: \"%s\"\n", p->verify_alg);
                        }
                        if (csums_tfm) {
-                               strcpy(new_net_conf->csums_alg, p->csums_alg);
+                               strscpy(new_net_conf->csums_alg, p->csums_alg);
                                new_net_conf->csums_alg_len = strlen(p->csums_alg) + 1;
                                crypto_free_shash(peer_device->connection->csums_tfm);
                                peer_device->connection->csums_tfm = csums_tfm;