* [PATCH] net: tun: replace strcpy with strscpy for ifr_name
@ 2025-08-11 11:22 Miguel García
2025-08-11 14:27 ` Willem de Bruijn
0 siblings, 1 reply; 4+ messages in thread
From: Miguel García @ 2025-08-11 11:22 UTC (permalink / raw)
To: netdev
Cc: linux-kernel, willemdebruijn.kernel, jasowang, andrew+netdev,
davem, edumazet, kuba, pabeni, skhan, Miguel García
Replace the strcpy() calls that copy the device name into ifr->ifr_name
with strscpy() to avoid potential overflows and guarantee NUL termination.
Destination is ifr->ifr_name (size IFNAMSIZ).
Tested in QEMU (BusyBox rootfs):
- Created TUN devices via TUNSETIFF helper
- Set addresses and brought links up
- Verified long interface names are safely truncated (IFNAMSIZ-1)
Signed-off-by: Miguel García <miguelgarciaroman8@gmail.com>
---
drivers/net/tun.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index f8c5e2fd04df..e4c6c1118acb 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -2800,13 +2800,13 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
if (netif_running(tun->dev))
netif_tx_wake_all_queues(tun->dev);
- strcpy(ifr->ifr_name, tun->dev->name);
+ strscpy(ifr->ifr_name, tun->dev->name, IFNAMSIZ);
return 0;
}
static void tun_get_iff(struct tun_struct *tun, struct ifreq *ifr)
{
- strcpy(ifr->ifr_name, tun->dev->name);
+ strscpy(ifr->ifr_name, tun->dev->name, IFNAMSIZ);
ifr->ifr_flags = tun_flags(tun);
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] net: tun: replace strcpy with strscpy for ifr_name
2025-08-11 11:22 [PATCH] net: tun: replace strcpy with strscpy for ifr_name Miguel García
@ 2025-08-11 14:27 ` Willem de Bruijn
2025-08-11 20:33 ` [PATCH v2] " Miguel García
0 siblings, 1 reply; 4+ messages in thread
From: Willem de Bruijn @ 2025-08-11 14:27 UTC (permalink / raw)
To: Miguel García, netdev
Cc: linux-kernel, willemdebruijn.kernel, jasowang, andrew+netdev,
davem, edumazet, kuba, pabeni, skhan, Miguel García
[PATCH net-next]
Miguel García wrote:
> Replace the strcpy() calls that copy the device name into ifr->ifr_name
> with strscpy() to avoid potential overflows and guarantee NUL termination.
NULL
> Destination is ifr->ifr_name (size IFNAMSIZ).
>
> Tested in QEMU (BusyBox rootfs):
> - Created TUN devices via TUNSETIFF helper
> - Set addresses and brought links up
> - Verified long interface names are safely truncated (IFNAMSIZ-1)
>
> Signed-off-by: Miguel García <miguelgarciaroman8@gmail.com>
> ---
> drivers/net/tun.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> index f8c5e2fd04df..e4c6c1118acb 100644
> --- a/drivers/net/tun.c
> +++ b/drivers/net/tun.c
> @@ -2800,13 +2800,13 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
> if (netif_running(tun->dev))
> netif_tx_wake_all_queues(tun->dev);
>
> - strcpy(ifr->ifr_name, tun->dev->name);
> + strscpy(ifr->ifr_name, tun->dev->name, IFNAMSIZ);
Since both dst and src are arrays of IFNAMSIZ, can drop the third
argument. Then it is inferred from the field sizes, which is more
robust.
> return 0;
> }
>
> static void tun_get_iff(struct tun_struct *tun, struct ifreq *ifr)
> {
> - strcpy(ifr->ifr_name, tun->dev->name);
> + strscpy(ifr->ifr_name, tun->dev->name, IFNAMSIZ);
>
> ifr->ifr_flags = tun_flags(tun);
>
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] net: tun: replace strcpy with strscpy for ifr_name
2025-08-11 14:27 ` Willem de Bruijn
@ 2025-08-11 20:33 ` Miguel García
2025-08-12 1:05 ` Jakub Kicinski
0 siblings, 1 reply; 4+ messages in thread
From: Miguel García @ 2025-08-11 20:33 UTC (permalink / raw)
To: netdev
Cc: linux-kernel, willemdebruijn.kernel, jasowang, andrew+netdev,
davem, edumazet, kuba, pabeni, skhan, Miguel García
Replace the strcpy() calls that copy the device name into ifr->ifr_name
with strscpy() to avoid potential overflows and guarantee NULL termination.
Destination is ifr->ifr_name (size IFNAMSIZ).
Tested in QEMU (BusyBox rootfs):
- Created TUN devices via TUNSETIFF helper
- Set addresses and brought links up
- Verified long interface names are safely truncated (IFNAMSIZ-1)
v2:
- Dropped third argument from strscpy(), inferred from field size.
Signed-off-by: Miguel García <miguelgarciaroman8@gmail.com>
---
drivers/net/tun.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index f8c5e2fd04df..ad33b16224e2 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -2800,13 +2800,13 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
if (netif_running(tun->dev))
netif_tx_wake_all_queues(tun->dev);
- strcpy(ifr->ifr_name, tun->dev->name);
+ strscpy(ifr->ifr_name, tun->dev->name);
return 0;
}
static void tun_get_iff(struct tun_struct *tun, struct ifreq *ifr)
{
- strcpy(ifr->ifr_name, tun->dev->name);
+ strscpy(ifr->ifr_name, tun->dev->name);
ifr->ifr_flags = tun_flags(tun);
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] net: tun: replace strcpy with strscpy for ifr_name
2025-08-11 20:33 ` [PATCH v2] " Miguel García
@ 2025-08-12 1:05 ` Jakub Kicinski
0 siblings, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2025-08-12 1:05 UTC (permalink / raw)
To: Miguel García
Cc: netdev, linux-kernel, willemdebruijn.kernel, jasowang,
andrew+netdev, davem, edumazet, pabeni, skhan
On Mon, 11 Aug 2025 22:33:29 +0200 Miguel García wrote:
> Replace the strcpy() calls that copy the device name into ifr->ifr_name
> with strscpy() to avoid potential overflows and guarantee NULL termination.
>
> Destination is ifr->ifr_name (size IFNAMSIZ).
>
> Tested in QEMU (BusyBox rootfs):
> - Created TUN devices via TUNSETIFF helper
> - Set addresses and brought links up
> - Verified long interface names are safely truncated (IFNAMSIZ-1)
>
> v2:
> - Dropped third argument from strscpy(), inferred from field size.
Please don't post new patches in reply to old ones. Please read:
https://www.kernel.org/doc/html/next/process/maintainer-netdev.html
there are multiple other problems with your submissions.
Please fix and repost.
--
pw-bot: cr
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-08-12 1:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-11 11:22 [PATCH] net: tun: replace strcpy with strscpy for ifr_name Miguel García
2025-08-11 14:27 ` Willem de Bruijn
2025-08-11 20:33 ` [PATCH v2] " Miguel García
2025-08-12 1:05 ` Jakub Kicinski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).