Skip to content

Commit 5eae7a8

Browse files
matttbekuba-moo
authored andcommitted
mptcp: prefer strscpy over strcpy
strcpy() performs no bounds checking on the destination buffer. This could result in linear overflows beyond the end of the buffer, leading to all kinds of misbehaviors. The safe replacement is strscpy() [1]. This is in preparation of a possible future step where all strcpy() uses will be removed in favour of strscpy() [2]. This fixes CheckPatch warnings: WARNING: Prefer strscpy over strcpy Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy [1] Link: KSPP#88 [2] Reviewed-by: Geliang Tang <[email protected]> Signed-off-by: Matthieu Baerts (NGI0) <[email protected]> Signed-off-by: Mat Martineau <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 73c900a commit 5eae7a8

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

net/mptcp/ctrl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static void mptcp_pernet_set_defaults(struct mptcp_pernet *pernet)
9292
pernet->allow_join_initial_addr_port = 1;
9393
pernet->stale_loss_cnt = 4;
9494
pernet->pm_type = MPTCP_PM_TYPE_KERNEL;
95-
strcpy(pernet->scheduler, "default");
95+
strscpy(pernet->scheduler, "default", sizeof(pernet->scheduler));
9696
}
9797

9898
#ifdef CONFIG_SYSCTL

net/mptcp/protocol.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2814,7 +2814,8 @@ static void mptcp_ca_reset(struct sock *sk)
28142814
struct inet_connection_sock *icsk = inet_csk(sk);
28152815

28162816
tcp_assign_congestion_control(sk);
2817-
strcpy(mptcp_sk(sk)->ca_name, icsk->icsk_ca_ops->name);
2817+
strscpy(mptcp_sk(sk)->ca_name, icsk->icsk_ca_ops->name,
2818+
sizeof(mptcp_sk(sk)->ca_name));
28182819

28192820
/* no need to keep a reference to the ops, the name will suffice */
28202821
tcp_cleanup_congestion_control(sk);
@@ -4169,7 +4170,7 @@ int __init mptcp_proto_v6_init(void)
41694170
int err;
41704171

41714172
mptcp_v6_prot = mptcp_prot;
4172-
strcpy(mptcp_v6_prot.name, "MPTCPv6");
4173+
strscpy(mptcp_v6_prot.name, "MPTCPv6", sizeof(mptcp_v6_prot.name));
41734174
mptcp_v6_prot.slab = NULL;
41744175
mptcp_v6_prot.obj_size = sizeof(struct mptcp6_sock);
41754176
mptcp_v6_prot.ipv6_pinfo_offset = offsetof(struct mptcp6_sock, np);

net/mptcp/sockopt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ static int mptcp_setsockopt_sol_tcp_congestion(struct mptcp_sock *msk, sockptr_t
616616
}
617617

618618
if (ret == 0)
619-
strcpy(msk->ca_name, name);
619+
strscpy(msk->ca_name, name, sizeof(msk->ca_name));
620620

621621
release_sock(sk);
622622
return ret;

0 commit comments

Comments
 (0)