netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: "Miguel García" <miguelgarciaroman8@gmail.com>, netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, willemdebruijn.kernel@gmail.com,
	jasowang@redhat.com, andrew+netdev@lunn.ch, davem@davemloft.net,
	edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
	skhan@linuxfoundation.org,
	"Miguel García" <miguelgarciaroman8@gmail.com>
Subject: Re: [PATCH] net: tun: replace strcpy with strscpy for ifr_name
Date: Mon, 11 Aug 2025 10:27:47 -0400	[thread overview]
Message-ID: <6899fde3dbfd6_532b129461@willemb.c.googlers.com.notmuch> (raw)
In-Reply-To: <20250811112207.97371-1-miguelgarciaroman8@gmail.com>

[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
> 



  reply	other threads:[~2025-08-11 14:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2025-08-11 20:33   ` [PATCH v2] " Miguel García
2025-08-12  1:05     ` Jakub Kicinski

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=6899fde3dbfd6_532b129461@willemb.c.googlers.com.notmuch \
    --to=willemdebruijn.kernel@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=jasowang@redhat.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miguelgarciaroman8@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=skhan@linuxfoundation.org \
    /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;
as well as URLs for NNTP newsgroup(s).