]> www.infradead.org Git - users/hch/misc.git/commitdiff
mptcp: prefer strscpy over strcpy
authorMatthieu Baerts (NGI0) <matttbe@kernel.org>
Tue, 14 May 2024 01:13:29 +0000 (18:13 -0700)
committerJakub Kicinski <kuba@kernel.org>
Tue, 14 May 2024 01:29:23 +0000 (18:29 -0700)
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
Link: https://github.com/KSPP/linux/issues/88
Reviewed-by: Geliang Tang <geliang@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: Mat Martineau <martineau@kernel.org>
Link: https://lore.kernel.org/r/20240514011335.176158-6-martineau@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/mptcp/ctrl.c
net/mptcp/protocol.c
net/mptcp/sockopt.c

index 542555ba474cb9b9337e3036671b9f43fd9dd9d1..98b1dd498ff664923f20ef2b33cccc963f00fdc1 100644 (file)
@@ -92,7 +92,7 @@ static void mptcp_pernet_set_defaults(struct mptcp_pernet *pernet)
        pernet->allow_join_initial_addr_port = 1;
        pernet->stale_loss_cnt = 4;
        pernet->pm_type = MPTCP_PM_TYPE_KERNEL;
-       strcpy(pernet->scheduler, "default");
+       strscpy(pernet->scheduler, "default", sizeof(pernet->scheduler));
 }
 
 #ifdef CONFIG_SYSCTL
index bb8f96f2b86fe03e37c601711b957613c7c1fc13..a42494d3a71b6d5a104a054384b45c2db5471788 100644 (file)
@@ -2814,7 +2814,8 @@ static void mptcp_ca_reset(struct sock *sk)
        struct inet_connection_sock *icsk = inet_csk(sk);
 
        tcp_assign_congestion_control(sk);
-       strcpy(mptcp_sk(sk)->ca_name, icsk->icsk_ca_ops->name);
+       strscpy(mptcp_sk(sk)->ca_name, icsk->icsk_ca_ops->name,
+               sizeof(mptcp_sk(sk)->ca_name));
 
        /* no need to keep a reference to the ops, the name will suffice */
        tcp_cleanup_congestion_control(sk);
@@ -4169,7 +4170,7 @@ int __init mptcp_proto_v6_init(void)
        int err;
 
        mptcp_v6_prot = mptcp_prot;
-       strcpy(mptcp_v6_prot.name, "MPTCPv6");
+       strscpy(mptcp_v6_prot.name, "MPTCPv6", sizeof(mptcp_v6_prot.name));
        mptcp_v6_prot.slab = NULL;
        mptcp_v6_prot.obj_size = sizeof(struct mptcp6_sock);
        mptcp_v6_prot.ipv6_pinfo_offset = offsetof(struct mptcp6_sock, np);
index a77b33488176289a997826619fe12f94ca1c0f43..f9a4fb17b5b78d5945243a326e5222000c6fa2c6 100644 (file)
@@ -616,7 +616,7 @@ static int mptcp_setsockopt_sol_tcp_congestion(struct mptcp_sock *msk, sockptr_t
        }
 
        if (ret == 0)
-               strcpy(msk->ca_name, name);
+               strscpy(msk->ca_name, name, sizeof(msk->ca_name));
 
        release_sock(sk);
        return ret;