netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Allison Henderson <allison.henderson@oracle.com>
To: "linux-rdma@vger.kernel.org" <linux-rdma@vger.kernel.org>,
	"shannon.nelson@amd.com" <shannon.nelson@amd.com>,
	"davem@davemloft.net" <davem@davemloft.net>,
	"dsahern@kernel.org" <dsahern@kernel.org>,
	"linux-kernel-mentees@lists.linux.dev"
	<linux-kernel-mentees@lists.linux.dev>,
	"pranav.tyagi03@gmail.com" <pranav.tyagi03@gmail.com>,
	"rds-devel@oss.oracle.com" <rds-devel@oss.oracle.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"pabeni@redhat.com" <pabeni@redhat.com>,
	"horms@kernel.org" <horms@kernel.org>,
	"edumazet@google.com" <edumazet@google.com>,
	"kuba@kernel.org" <kuba@kernel.org>,
	"skhan@linuxfoundation.org" <skhan@linuxfoundation.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: [PATCH] net: rds: replace strncpy with memcpy
Date: Tue, 8 Apr 2025 22:45:24 +0000	[thread overview]
Message-ID: <32b8d4635b8f15cce3ae898cc480616428bc93ba.camel@oracle.com> (raw)
In-Reply-To: <c7dbeaf7-ab93-4b4f-904c-99d42a83a83d@amd.com>

On Tue, 2025-04-08 at 14:18 -0700, Nelson, Shannon wrote:
> On 4/8/2025 12:41 PM, Pranav Tyagi wrote:
> > 
> > Replace deprecated strncpy() function with memcpy()
> 
> I suspect that strtomem() is a better answer here than a raw memcpy() - 
> it already has all the strnlen() and min() stuff baked into it, along 
> with some other compile-time checking.
> 
> > as the destination buffer is length bounded
> > and not required to be NUL-terminated
> 
> Are you sure that null-termination is not required?  I'm not familiar 
> with this bit of code, but the definitions of both of the .transport[] 
> fields do say /* null term ascii */
> 
> sln
> 

Hi all,

It appears that the transport names are null-terminated. Looking at rds_ib_transport, rds_tcp_transport, and
rds_loop_transport, the t_name member is initialized to "infiniband", "tcp", or "loop", respectively— which include the
null terminator. Given that, I think strscpy seems to be the appropriate function to use here.

However, it looks like Baris has already submitted a similar patch yesterday, and unfortunately, we can't accept both.
That said, thank you very much for your contribution—we really appreciate it! 😊

Allison

> > 
> > Signed-off-by: Pranav Tyagi <pranav.tyagi03@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..3718c3edb32e 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));
> > +       memcpy(cinfo->transport, conn->c_trans->t_name, min(sizeof(cinfo->transport), strnlen(conn->c_trans->t_name, sizeof(cinfo->transport))));
> >          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));
> > +       memcpy(cinfo6->transport, conn->c_trans->t_name, min(sizeof(cinfo6->transport), strnlen(conn->c_trans->t_name, sizeof(cinfo6->transport))));
> >          cinfo6->flags = 0;
> > 
> >          rds_conn_info_set(cinfo6->flags, test_bit(RDS_IN_XMIT, &cp->cp_flags),
> > --
> > 2.49.0
> > 
> > 
> 
> 


      reply	other threads:[~2025-04-08 22:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-08 19:41 [PATCH] net: rds: replace strncpy with memcpy Pranav Tyagi
2025-04-08 21:18 ` Nelson, Shannon
2025-04-08 22:45   ` Allison Henderson [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=32b8d4635b8f15cce3ae898cc480616428bc93ba.camel@oracle.com \
    --to=allison.henderson@oracle.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel-mentees@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pranav.tyagi03@gmail.com \
    --cc=rds-devel@oss.oracle.com \
    --cc=shannon.nelson@amd.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).