drivers/net/tun.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
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)
Signed-off-by: Miguel García <miguelgarciaroman8@gmail.com>
---
v2:
- Dropped third argument from strscpy(), inferred from field size.
v1: https://lore.kernel.org/netdev/20250811112207.97371-1-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
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) > > Signed-off-by: Miguel García <miguelgarciaroman8@gmail.com> Reviewed-by: Willem de Bruijn <willemb@google.com>
Thanks Willem. Should I resend with your Reviewed-by tag or will it be picked up when applied? El mié, 13 ago 2025 a las 15:06, Willem de Bruijn (<willemdebruijn.kernel@gmail.com>) escribió: > > 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) > > > > Signed-off-by: Miguel García <miguelgarciaroman8@gmail.com> > > Reviewed-by: Willem de Bruijn <willemb@google.com>
Miguel García Román wrote: > Thanks Willem. Should I resend with your Reviewed-by tag or will it be > picked up when applied? No need. Also see other patches under review, and especially read https://www.kernel.org/doc/html/next/process/submitting-patches.html Note the comment on top posting. > El mié, 13 ago 2025 a las 15:06, Willem de Bruijn > (<willemdebruijn.kernel@gmail.com>) escribió: > > > > 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) > > > > > > Signed-off-by: Miguel García <miguelgarciaroman8@gmail.com> > > > > Reviewed-by: Willem de Bruijn <willemb@google.com>
© 2016 - 2025 Red Hat, Inc.