All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhu Yanjun <yanjun.zhu@linux.dev>
To: Baris Can Goral <goralbaris@gmail.com>, allison.henderson@oracle.com
Cc: davem@davemloft.net, edumazet@google.com, horms@kernel.org,
	kuba@kernel.org, linux-rdma@vger.kernel.org,
	michal.swiatkowski@linux.intel.com, netdev@vger.kernel.org,
	pabeni@redhat.com, shankari.ak0208@gmail.com,
	skhan@linuxfoundation.org
Subject: Re: [PATCH v5 net-next: rds] replace strncpy with strscpy_pad
Date: Tue, 20 May 2025 23:13:39 +0200	[thread overview]
Message-ID: <f0ee3606-1068-4899-8e66-a5e7ec716b0d@linux.dev> (raw)
In-Reply-To: <20250520162342.6144-1-goralbaris@gmail.com>

在 2025/5/20 18:23, Baris Can Goral 写道:
> The strncpy() function is actively dangerous to use since it may not
> NULL-terminate the destination string, resulting in potential memory
> content exposures, unbounded reads, or crashes.
> Link: https://github.com/KSPP/linux/issues/90
> 
> In addition, strscpy_pad is more appropriate because it also zero-fills
> any remaining space in the destination if the source is shorter than
> the provided buffer size.

Please don't reply to an old thread when starting a new version.

It is better to start a new thread with the new version.

Zhu Yanjun
> 
> Signed-off-by: Baris Can Goral <goralbaris@gmail.com>
> ---
>   net/rds/connection.c | 6 ++----
>   1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/net/rds/connection.c b/net/rds/connection.c
> index c749c5525b40..d62f486ab29f 100644
> --- a/net/rds/connection.c
> +++ b/net/rds/connection.c
> @@ -749,8 +749,7 @@ static int rds_conn_info_visitor(struct rds_conn_path *cp, void *buffer)
>   	cinfo->laddr = conn->c_laddr.s6_addr32[3];
>   	cinfo->faddr = conn->c_faddr.s6_addr32[3];
>   	cinfo->tos = conn->c_tos;
> -	strncpy(cinfo->transport, conn->c_trans->t_name,
> -		sizeof(cinfo->transport));
> +	strscpy_pad(cinfo->transport, conn->c_trans->t_name);
>   	cinfo->flags = 0;
>   
>   	rds_conn_info_set(cinfo->flags, test_bit(RDS_IN_XMIT, &cp->cp_flags),
> @@ -775,8 +774,7 @@ static int rds6_conn_info_visitor(struct rds_conn_path *cp, void *buffer)
>   	cinfo6->next_rx_seq = cp->cp_next_rx_seq;
>   	cinfo6->laddr = conn->c_laddr;
>   	cinfo6->faddr = conn->c_faddr;
> -	strncpy(cinfo6->transport, conn->c_trans->t_name,
> -		sizeof(cinfo6->transport));
> +	strscpy_pad(cinfo6->transport, conn->c_trans->t_name);
>   	cinfo6->flags = 0;
>   
>   	rds_conn_info_set(cinfo6->flags, test_bit(RDS_IN_XMIT, &cp->cp_flags),


  reply	other threads:[~2025-05-20 21:14 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-07 18:30 [PATCH] net: rds transform strncpy to strscpy Baris Can Goral
2025-04-08 18:22 ` Simon Horman
2025-04-08 21:21   ` [PATCH net-next v2] Replace strncpy with strscpy Baris Can Goral
2025-05-17 18:12     ` goralbaris
2025-05-18  9:00       ` Simon Horman
2025-05-18 19:53         ` [PATCH v3 net-next: rds] replace strncpy with strscpy_pad goralbaris
2025-05-19  7:01           ` Michal Swiatkowski
2025-05-19 12:51             ` [PATCH v4 " Baris Can Goral
2025-05-19 21:15               ` Allison Henderson
2025-05-20 16:23                 ` [PATCH v5 " Baris Can Goral
2025-05-20 21:13                   ` Zhu Yanjun [this message]
  -- strict thread matches above, loose matches on Subject: below --
2025-05-21 16:10 Baris Can Goral
2025-05-21 17:14 ` Allison Henderson
2025-05-26 20:40 ` patchwork-bot+netdevbpf

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=f0ee3606-1068-4899-8e66-a5e7ec716b0d@linux.dev \
    --to=yanjun.zhu@linux.dev \
    --cc=allison.henderson@oracle.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=goralbaris@gmail.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=michal.swiatkowski@linux.intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shankari.ak0208@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.