Linux kernel staging patches
 help / color / Atom feed
* [PATCH] staging/rtl8712: Remove all strcpy() uses in favor of strscpy()
@ 2021-07-17 15:51 Len Baker
  2021-07-19  5:37 ` Dan Carpenter
  0 siblings, 1 reply; 7+ messages in thread
From: Len Baker @ 2021-07-17 15:51 UTC (permalink / raw)
  To: Larry Finger, Florian Schilhabel, Greg Kroah-Hartman
  Cc: Len Baker, Pavel Skripkin, linux-staging, linux-kernel

strcpy() performs no bounds checking on the destination buffer. This
could result in linear overflows beyond the end of the buffer, leading
to all kinds of misbehaviors. The safe replacement is strscpy().

Signed-off-by: Len Baker <len.baker@gmx.com>
---
 drivers/staging/rtl8712/os_intfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/rtl8712/os_intfs.c b/drivers/staging/rtl8712/os_intfs.c
index 2214aca09730..9502f6aa5306 100644
--- a/drivers/staging/rtl8712/os_intfs.c
+++ b/drivers/staging/rtl8712/os_intfs.c
@@ -203,7 +203,7 @@ struct net_device *r8712_init_netdev(void)
 	if (!pnetdev)
 		return NULL;
 	if (dev_alloc_name(pnetdev, ifname) < 0) {
-		strcpy(ifname, "wlan%d");
+		strscpy(ifname, "wlan%d", sizeof(ifname));
 		dev_alloc_name(pnetdev, ifname);
 	}
 	padapter = netdev_priv(pnetdev);
--
2.25.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] staging/rtl8712: Remove all strcpy() uses in favor of strscpy()
  2021-07-17 15:51 [PATCH] staging/rtl8712: Remove all strcpy() uses in favor of strscpy() Len Baker
@ 2021-07-19  5:37 ` Dan Carpenter
  2021-07-19 15:24   ` David Laight
  0 siblings, 1 reply; 7+ messages in thread
From: Dan Carpenter @ 2021-07-19  5:37 UTC (permalink / raw)
  To: Len Baker
  Cc: Larry Finger, Florian Schilhabel, Greg Kroah-Hartman,
	Pavel Skripkin, linux-staging, linux-kernel

On Sat, Jul 17, 2021 at 05:51:45PM +0200, Len Baker wrote:
> strcpy() performs no bounds checking on the destination buffer. This
> could result in linear overflows beyond the end of the buffer, leading
> to all kinds of misbehaviors. The safe replacement is strscpy().
> 
> Signed-off-by: Len Baker <len.baker@gmx.com>
> ---
>  drivers/staging/rtl8712/os_intfs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/rtl8712/os_intfs.c b/drivers/staging/rtl8712/os_intfs.c
> index 2214aca09730..9502f6aa5306 100644
> --- a/drivers/staging/rtl8712/os_intfs.c
> +++ b/drivers/staging/rtl8712/os_intfs.c
> @@ -203,7 +203,7 @@ struct net_device *r8712_init_netdev(void)
>  	if (!pnetdev)
>  		return NULL;
>  	if (dev_alloc_name(pnetdev, ifname) < 0) {
> -		strcpy(ifname, "wlan%d");
> +		strscpy(ifname, "wlan%d", sizeof(ifname));
>  		dev_alloc_name(pnetdev, ifname);

Not related to your patch but this code is bad.  What it does is the
"ifname" can be set as a module parameter.  So instead of testing if it
has been set, it uses the checking inside dev_alloc_name() to see if we
can allocate what the user requested.  If not then set it to "wlan%d".
If we cannot allocate what the user wants then we should return an
error.

It should do:

	if (ifname[0] == '\0')
		strscpy(ifname, "wlan%d", sizeof(ifname));

	ret = dev_alloc_name(pnetdev, ifname);
	if (ret < 0) {
		dev_err(pnetdev, "allocating device name failed.\n");
		return NULL;
	}

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [PATCH] staging/rtl8712: Remove all strcpy() uses in favor of strscpy()
  2021-07-19  5:37 ` Dan Carpenter
@ 2021-07-19 15:24   ` David Laight
  2021-07-21  8:06     ` Dan Carpenter
  0 siblings, 1 reply; 7+ messages in thread
From: David Laight @ 2021-07-19 15:24 UTC (permalink / raw)
  To: 'Dan Carpenter', Len Baker
  Cc: Larry Finger, Florian Schilhabel, Greg Kroah-Hartman,
	Pavel Skripkin, linux-staging, linux-kernel

From: Dan Carpenter
> Sent: 19 July 2021 06:38
...
> Not related to your patch but this code is bad.  What it does is the
> "ifname" can be set as a module parameter.  So instead of testing if it
> has been set, it uses the checking inside dev_alloc_name() to see if we
> can allocate what the user requested.  If not then set it to "wlan%d".
> If we cannot allocate what the user wants then we should return an
> error.
> 
> It should do:
> 
> 	if (ifname[0] == '\0')
> 		strscpy(ifname, "wlan%d", sizeof(ifname));
> 
> 	ret = dev_alloc_name(pnetdev, ifname);
> 	if (ret < 0) {
> 		dev_err(pnetdev, "allocating device name failed.\n");
> 		return NULL;
> 	}

I know only root can set module parameters, but having one
that contains a string used as a printf format seems
dangerous at best.

Isn't it best to let userspace rename the interfaces later on?

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] staging/rtl8712: Remove all strcpy() uses in favor of strscpy()
  2021-07-19 15:24   ` David Laight
@ 2021-07-21  8:06     ` Dan Carpenter
  2021-07-23 15:15       ` Len Baker
  0 siblings, 1 reply; 7+ messages in thread
From: Dan Carpenter @ 2021-07-21  8:06 UTC (permalink / raw)
  To: David Laight
  Cc: Len Baker, Larry Finger, Florian Schilhabel, Greg Kroah-Hartman,
	Pavel Skripkin, linux-staging, linux-kernel

On Mon, Jul 19, 2021 at 03:24:38PM +0000, David Laight wrote:
> From: Dan Carpenter
> > Sent: 19 July 2021 06:38
> ...
> > Not related to your patch but this code is bad.  What it does is the
> > "ifname" can be set as a module parameter.  So instead of testing if it
> > has been set, it uses the checking inside dev_alloc_name() to see if we
> > can allocate what the user requested.  If not then set it to "wlan%d".
> > If we cannot allocate what the user wants then we should return an
> > error.
> > 
> > It should do:
> > 
> > 	if (ifname[0] == '\0')
> > 		strscpy(ifname, "wlan%d", sizeof(ifname));
> > 
> > 	ret = dev_alloc_name(pnetdev, ifname);
> > 	if (ret < 0) {
> > 		dev_err(pnetdev, "allocating device name failed.\n");
> > 		return NULL;
> > 	}
> 
> I know only root can set module parameters, but having one
> that contains a string used as a printf format seems
> dangerous at best.
> 
> Isn't it best to let userspace rename the interfaces later on?

Yeah.  I think you're right.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] staging/rtl8712: Remove all strcpy() uses in favor of strscpy()
  2021-07-21  8:06     ` Dan Carpenter
@ 2021-07-23 15:15       ` Len Baker
  2021-07-26  8:11         ` Dan Carpenter
  0 siblings, 1 reply; 7+ messages in thread
From: Len Baker @ 2021-07-23 15:15 UTC (permalink / raw)
  To: Dan Carpenter, David Laight
  Cc: Len Baker, Larry Finger, Florian Schilhabel, Greg Kroah-Hartman,
	Pavel Skripkin, linux-staging, linux-kernel

Hi,

On Wed, Jul 21, 2021 at 11:06:24AM +0300, Dan Carpenter wrote:
> On Mon, Jul 19, 2021 at 03:24:38PM +0000, David Laight wrote:
> > From: Dan Carpenter
> > > Sent: 19 July 2021 06:38
> > ...
> > > Not related to your patch but this code is bad.  What it does is the
> > > "ifname" can be set as a module parameter.  So instead of testing if it
> > > has been set, it uses the checking inside dev_alloc_name() to see if we
> > > can allocate what the user requested.  If not then set it to "wlan%d".
> > > If we cannot allocate what the user wants then we should return an
> > > error.
> > >
> > > It should do:
> > >
> > > 	if (ifname[0] == '\0')
> > > 		strscpy(ifname, "wlan%d", sizeof(ifname));
> > >
> > > 	ret = dev_alloc_name(pnetdev, ifname);
> > > 	if (ret < 0) {
> > > 		dev_err(pnetdev, "allocating device name failed.\n");
> > > 		return NULL;
> > > 	}
> >
> > I know only root can set module parameters, but having one
> > that contains a string used as a printf format seems
> > dangerous at best.
> >
> > Isn't it best to let userspace rename the interfaces later on?
>
> Yeah.  I think you're right.

Sorry, but I don't understand if the code needs to be improved or not.
Is the code shown by Dan not correct?

>
> regards,
> dan carpenter
>

Thanks for your time,
Len

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] staging/rtl8712: Remove all strcpy() uses in favor of strscpy()
  2021-07-23 15:15       ` Len Baker
@ 2021-07-26  8:11         ` Dan Carpenter
  2021-07-28 17:45           ` Len Baker
  0 siblings, 1 reply; 7+ messages in thread
From: Dan Carpenter @ 2021-07-26  8:11 UTC (permalink / raw)
  To: Len Baker
  Cc: David Laight, Larry Finger, Florian Schilhabel,
	Greg Kroah-Hartman, Pavel Skripkin, linux-staging, linux-kernel

On Fri, Jul 23, 2021 at 05:15:10PM +0200, Len Baker wrote:
> Hi,
> 
> On Wed, Jul 21, 2021 at 11:06:24AM +0300, Dan Carpenter wrote:
> > On Mon, Jul 19, 2021 at 03:24:38PM +0000, David Laight wrote:
> > > From: Dan Carpenter
> > > > Sent: 19 July 2021 06:38
> > > ...
> > > > Not related to your patch but this code is bad.  What it does is the
> > > > "ifname" can be set as a module parameter.  So instead of testing if it
> > > > has been set, it uses the checking inside dev_alloc_name() to see if we
> > > > can allocate what the user requested.  If not then set it to "wlan%d".
> > > > If we cannot allocate what the user wants then we should return an
> > > > error.
> > > >
> > > > It should do:
> > > >
> > > > 	if (ifname[0] == '\0')
> > > > 		strscpy(ifname, "wlan%d", sizeof(ifname));
> > > >
> > > > 	ret = dev_alloc_name(pnetdev, ifname);
> > > > 	if (ret < 0) {
> > > > 		dev_err(pnetdev, "allocating device name failed.\n");
> > > > 		return NULL;
> > > > 	}
> > >
> > > I know only root can set module parameters, but having one
> > > that contains a string used as a printf format seems
> > > dangerous at best.
> > >
> > > Isn't it best to let userspace rename the interfaces later on?
> >
> > Yeah.  I think you're right.
> 
> Sorry, but I don't understand if the code needs to be improved or not.
> Is the code shown by Dan not correct?

We should remove the ifname[] array and the module option completely.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] staging/rtl8712: Remove all strcpy() uses in favor of strscpy()
  2021-07-26  8:11         ` Dan Carpenter
@ 2021-07-28 17:45           ` Len Baker
  0 siblings, 0 replies; 7+ messages in thread
From: Len Baker @ 2021-07-28 17:45 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Len Baker, David Laight, Larry Finger, Florian Schilhabel,
	Greg Kroah-Hartman, Pavel Skripkin, linux-staging, linux-kernel

On Mon, Jul 26, 2021 at 11:11:48AM +0300, Dan Carpenter wrote:
> On Fri, Jul 23, 2021 at 05:15:10PM +0200, Len Baker wrote:
> > Hi,
> >
> > On Wed, Jul 21, 2021 at 11:06:24AM +0300, Dan Carpenter wrote:
> > > On Mon, Jul 19, 2021 at 03:24:38PM +0000, David Laight wrote:
> > > >
> > > > I know only root can set module parameters, but having one
> > > > that contains a string used as a printf format seems
> > > > dangerous at best.
> > > >
> > > > Isn't it best to let userspace rename the interfaces later on?
> > >
> > > Yeah.  I think you're right.
> >
> > Sorry, but I don't understand if the code needs to be improved or not.
> > Is the code shown by Dan not correct?
>
> We should remove the ifname[] array and the module option completely.

Thanks for the clarification.

Regards,
Len

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, back to index

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-17 15:51 [PATCH] staging/rtl8712: Remove all strcpy() uses in favor of strscpy() Len Baker
2021-07-19  5:37 ` Dan Carpenter
2021-07-19 15:24   ` David Laight
2021-07-21  8:06     ` Dan Carpenter
2021-07-23 15:15       ` Len Baker
2021-07-26  8:11         ` Dan Carpenter
2021-07-28 17:45           ` Len Baker

Linux kernel staging patches

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-staging/0 linux-staging/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-staging linux-staging/ https://lore.kernel.org/linux-staging \
		linux-staging@lists.linux.dev
	public-inbox-index linux-staging

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/dev.linux.lists.linux-staging


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git