netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: Shankari <shankari.ak0208@gmail.com>
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH v2] net: rds: Replace strncpy with strscpy in connection setup
Date: Wed, 30 Apr 2025 19:16:57 +0100	[thread overview]
Message-ID: <20250430181657.GW3339421@horms.kernel.org> (raw)
In-Reply-To: <CAPRMd3mRUi+ESqDy04c-r38JoSWxo8Ka0Et9gZbe+jRrL6G_nQ@mail.gmail.com>

On Sun, Apr 27, 2025 at 12:56:14AM +0530, Shankari wrote:
> Hi Jacub,
> 
> I have implemented the changes in the v2 patch. Thanks for your review.
> 
> On Sun, Apr 27, 2025 at 12:51 AM Shankari Anand
> <shankari.ak0208@gmail.com> wrote:
> >
> > From: Shankari02 <shankari.ak0208@gmail.com>
> >
> > This patch replaces strncpy() with strscpy(), which is the preferred, safer
> > alternative for bounded string copying in the Linux kernel. strscpy() guarantees
> > null-termination as long as the destination buffer is non-zero in size and provides
> > a return value to detect truncation.
> >
> > Padding of the 'transport' field is not necessary because it is treated purely
> > as a null-terminated string and is not used for binary comparisons or direct
> > memory operations that would rely on padding. Therefore, switching to strscpy()
> > is safe and appropriate here.
> >
> > This change is made in accordance with the Linux kernel documentation, which
> > marks strncpy() as deprecated for bounded string operations:
> > https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy
> >
> > Signed-off-by: Shankari Anand <shankari.ak0208@gmail.com>
> > ---
> >  net/rds/connection.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/net/rds/connection.c b/net/rds/connection.c
> > index c749c5525b40..fb2f14a1279a 100644
> > --- a/net/rds/connection.c
> > +++ b/net/rds/connection.c
> > @@ -749,7 +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,
> > +       strscpy(cinfo->transport, conn->c_trans->t_name,
> >                 sizeof(cinfo->transport));

Because cinfo->transport is an array it's length is sizeof(cinfo->transport),
as used above. But for the same reason the two-argument version of
strscpy() can be used here.

	strscpy(cinfo->transport, conn->c_trans->t_name);

Similarly if, based on my understanding of Jakub's feedback,
strscpy_pad() should be used.

> >         cinfo->flags = 0;
> >
> > @@ -775,7 +775,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,
> > +       strscpy(cinfo6->transport, conn->c_trans->t_name,
> >                 sizeof(cinfo6->transport));

Ditto.

> >         cinfo6->flags = 0;
> >
> > --
> > 2.34.1
> >
> 

  reply	other threads:[~2025-04-30 18:17 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-23 15:37 [PATCH] net: rds: Replace strncpy with strscpy in connection setup Shankari02
2025-04-25  1:36 ` Jakub Kicinski
2025-04-26 19:21   ` [PATCH v2] " Shankari Anand
2025-04-26 19:26     ` Shankari
2025-04-30 18:16       ` Simon Horman [this message]
2025-05-21  5:52         ` [PATCH v3] " Shankari Anand
2025-05-21  5:54         ` Shankari Anand
2025-05-21 12:58           ` [PATCH v4] " Shankari Anand
2025-05-21 17:21             ` Allison Henderson
2025-05-21  6:05         ` [PATCH v3] " Shankari Anand
2025-04-28 23:25     ` [PATCH v2] " Allison Henderson
2025-04-29 18:09     ` 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=20250430181657.GW3339421@horms.kernel.org \
    --to=horms@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=shankari.ak0208@gmail.com \
    /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).