Skip to content

Commit 81b1f04

Browse files
tobluxaxboe
authored andcommitted
drbd: Replace deprecated strcpy with strscpy
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 [1] 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>
1 parent ab14036 commit 81b1f04

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

drivers/block/drbd/drbd_main.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <linux/memcontrol.h>
3333
#include <linux/mm_inline.h>
3434
#include <linux/slab.h>
35+
#include <linux/string.h>
3536
#include <linux/random.h>
3637
#include <linux/reboot.h>
3738
#include <linux/notifier.h>
@@ -732,9 +733,9 @@ int drbd_send_sync_param(struct drbd_peer_device *peer_device)
732733
}
733734

734735
if (apv >= 88)
735-
strcpy(p->verify_alg, nc->verify_alg);
736+
strscpy(p->verify_alg, nc->verify_alg);
736737
if (apv >= 89)
737-
strcpy(p->csums_alg, nc->csums_alg);
738+
strscpy(p->csums_alg, nc->csums_alg);
738739
rcu_read_unlock();
739740

740741
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
745746
struct drbd_socket *sock;
746747
struct p_protocol *p;
747748
struct net_conf *nc;
749+
size_t integrity_alg_len;
748750
int size, cf;
749751

750752
sock = &connection->data;
@@ -762,8 +764,10 @@ int __drbd_send_protocol(struct drbd_connection *connection, enum drbd_packet cm
762764
}
763765

764766
size = sizeof(*p);
765-
if (connection->agreed_pro_version >= 87)
766-
size += strlen(nc->integrity_alg) + 1;
767+
if (connection->agreed_pro_version >= 87) {
768+
integrity_alg_len = strlen(nc->integrity_alg) + 1;
769+
size += integrity_alg_len;
770+
}
767771

768772
p->protocol = cpu_to_be32(nc->wire_protocol);
769773
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
778782
p->conn_flags = cpu_to_be32(cf);
779783

780784
if (connection->agreed_pro_version >= 87)
781-
strcpy(p->integrity_alg, nc->integrity_alg);
785+
strscpy(p->integrity_alg, nc->integrity_alg, integrity_alg_len);
782786
rcu_read_unlock();
783787

784788
return __conn_send_command(connection, sock, cmd, size, NULL, 0);

drivers/block/drbd/drbd_receiver.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3801,14 +3801,14 @@ static int receive_SyncParam(struct drbd_connection *connection, struct packet_i
38013801
*new_net_conf = *old_net_conf;
38023802

38033803
if (verify_tfm) {
3804-
strcpy(new_net_conf->verify_alg, p->verify_alg);
3804+
strscpy(new_net_conf->verify_alg, p->verify_alg);
38053805
new_net_conf->verify_alg_len = strlen(p->verify_alg) + 1;
38063806
crypto_free_shash(peer_device->connection->verify_tfm);
38073807
peer_device->connection->verify_tfm = verify_tfm;
38083808
drbd_info(device, "using verify-alg: \"%s\"\n", p->verify_alg);
38093809
}
38103810
if (csums_tfm) {
3811-
strcpy(new_net_conf->csums_alg, p->csums_alg);
3811+
strscpy(new_net_conf->csums_alg, p->csums_alg);
38123812
new_net_conf->csums_alg_len = strlen(p->csums_alg) + 1;
38133813
crypto_free_shash(peer_device->connection->csums_tfm);
38143814
peer_device->connection->csums_tfm = csums_tfm;

0 commit comments

Comments
 (0)