From: Hongbo Li <lihongbo22@huawei.com>
To: <davem@davemloft.net>, <edumazet@google.com>, <kuba@kernel.org>,
<pabeni@redhat.com>, <dsahern@kernel.org>, <ralf@linux-mips.org>,
<jmaloy@redhat.com>, <ying.xue@windriver.com>
Cc: <netdev@vger.kernel.org>, <linux-hams@vger.kernel.org>,
<netfilter-devel@vger.kernel.org>
Subject: [PATCH net-next 6/6] net/ipv4: net: prefer strscpy over strcpy
Date: Tue, 27 Aug 2024 19:35:27 +0800 [thread overview]
Message-ID: <20240827113527.4019856-7-lihongbo22@huawei.com> (raw)
In-Reply-To: <20240827113527.4019856-1-lihongbo22@huawei.com>
The deprecated helper 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].
Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy [1]
Signed-off-by: Hongbo Li <lihongbo22@huawei.com>
---
net/ipv4/ip_tunnel.c | 2 +-
net/ipv4/netfilter/arp_tables.c | 2 +-
net/ipv4/netfilter/ip_tables.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c
index 5cffad42fe8c..1c33fcbc0827 100644
--- a/net/ipv4/ip_tunnel.c
+++ b/net/ipv4/ip_tunnel.c
@@ -1326,7 +1326,7 @@ int ip_tunnel_init(struct net_device *dev)
tunnel->dev = dev;
tunnel->net = dev_net(dev);
- strcpy(tunnel->parms.name, dev->name);
+ strscpy(tunnel->parms.name, dev->name, sizeof(tunnel->parms.name));
iph->version = 4;
iph->ihl = 5;
diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
index 14365b20f1c5..2fa6ea78db9e 100644
--- a/net/ipv4/netfilter/arp_tables.c
+++ b/net/ipv4/netfilter/arp_tables.c
@@ -826,7 +826,7 @@ static int get_info(struct net *net, void __user *user, const int *len)
sizeof(info.underflow));
info.num_entries = private->number;
info.size = private->size;
- strcpy(info.name, name);
+ strscpy(info.name, name, sizeof(info.name));
if (copy_to_user(user, &info, *len) != 0)
ret = -EFAULT;
diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
index fe89a056eb06..d853070432c6 100644
--- a/net/ipv4/netfilter/ip_tables.c
+++ b/net/ipv4/netfilter/ip_tables.c
@@ -981,7 +981,7 @@ static int get_info(struct net *net, void __user *user, const int *len)
sizeof(info.underflow));
info.num_entries = private->number;
info.size = private->size;
- strcpy(info.name, name);
+ strscpy(info.name, name, sizeof(info.name));
if (copy_to_user(user, &info, *len) != 0)
ret = -EFAULT;
--
2.34.1
prev parent reply other threads:[~2024-08-27 11:27 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-27 11:35 [PATCH net-next 0/6] replace deprecated strcpy with strscpy Hongbo Li
2024-08-27 11:35 ` [PATCH net-next 1/6] net: prefer strscpy over strcpy Hongbo Li
2024-08-27 12:30 ` Dan Carpenter
2024-08-28 7:43 ` Hongbo Li
2024-08-28 8:54 ` Dan Carpenter
2024-08-27 11:35 ` [PATCH net-next 2/6] net/ipv6: replace deprecated strcpy with strscpy Hongbo Li
2024-08-27 11:35 ` [PATCH net-next 3/6] net/netrom: prefer strscpy over strcpy Hongbo Li
2024-08-27 11:35 ` [PATCH net-next 4/6] net/netfilter: replace deprecated strcpy with strscpy Hongbo Li
2024-08-27 11:35 ` [PATCH net-next 5/6] net/tipc: " Hongbo Li
2024-08-27 11:35 ` Hongbo Li [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240827113527.4019856-7-lihongbo22@huawei.com \
--to=lihongbo22@huawei.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=jmaloy@redhat.com \
--cc=kuba@kernel.org \
--cc=linux-hams@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=ralf@linux-mips.org \
--cc=ying.xue@windriver.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox