public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Amit Sunil Dhamne <amitsd@google.com>
Cc: Maxwell Doose <m32285159@gmail.com>,
	badhri@google.com, heikki.krogerus@linux.intel.com,
	gregkh@linuxfoundation.org, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] usb: typec: tcpm: replace strcpy with strscpy
Date: Wed, 29 Apr 2026 09:54:45 +0100	[thread overview]
Message-ID: <20260429095445.11b7302e@pumpkin> (raw)
In-Reply-To: <0643586e-e665-4592-b941-2868fca84322@google.com>

On Thu, 23 Apr 2026 12:23:09 -0700
Amit Sunil Dhamne <amitsd@google.com> wrote:

> Hi Maxwell,
> 
> On 4/19/26 2:36 PM, Maxwell Doose wrote:
> > The function strcpy() is deprecated as it can be used in buffer overflow
> > attacks. This patch replaces strcpy() with strscpy() to improve
> > security and stability.
> >
> > Signed-off-by: Maxwell Doose <m32285159@gmail.com>
> > ---
> >   drivers/usb/typec/tcpm/tcpm.c | 6 +++---
> >   1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> > index 8e0e14a2704e..69574c5e79e1 100644
> > --- a/drivers/usb/typec/tcpm/tcpm.c
> > +++ b/drivers/usb/typec/tcpm/tcpm.c
> > @@ -725,7 +725,7 @@ static void _tcpm_log(struct tcpm_port *port, const char *fmt, va_list args)
> >   
> >   	if (tcpm_log_full(port)) {
> >   		port->logbuffer_head = max(port->logbuffer_head - 1, 0);
> > -		strcpy(tmpbuffer, "overflow");
> > +		strscpy(tmpbuffer, "overflow", sizeof(tmpbuffer))
> >   	}
> >   
> >   	if (port->logbuffer_head < 0 ||
> > @@ -841,10 +841,10 @@ static void tcpm_log_source_caps(struct tcpm_port *port)
> >   					  pdo_spr_avs_apdo_15v_to_20v_max_current_ma(pdo),
> >   					  pdo_spr_avs_apdo_src_peak_current(pdo));
> >   			else
> > -				strcpy(msg, "undefined APDO");
> > +				strscpy(msg, "undefined APDO", sizeof(msg));
> >   			break;
> >   		default:
> > -			strcpy(msg, "undefined");
> > +			strscpy(msg, "undefined", sizeof(msg));
> >   			break;
> >   		}
> >   		tcpm_log(port, " PDO %d: type %d, %s",  
> 
> This has already been fixed as part of [1].

It is also 'not a fix'.
strcpy() is fine for copying literal strings into arrays.
With the kernel headers you get a compile error from strcpy() if the string
is too long.
OTOH strscpy() will truncate overlong strings.

	David

> 
> [1] https://patch.msgid.link/20260310094434.3639602-5-aichao@kylinos.cn
> 
> 
> BR,
> 
> Amit
> 
> 


  parent reply	other threads:[~2026-04-29  8:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-19 21:36 [PATCH] usb: typec: tcpm: replace strcpy with strscpy Maxwell Doose
2026-04-23 19:23 ` Amit Sunil Dhamne
2026-04-23 20:56   ` Maxwell Doose
2026-04-29  8:54   ` David Laight [this message]
2026-04-27 23:01 ` kernel test robot
2026-04-28 23:11 ` kernel test robot

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=20260429095445.11b7302e@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=amitsd@google.com \
    --cc=badhri@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=m32285159@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