Linux kernel staging patches
 help / color / Atom feed
* [PATCH] staging/rtl8192e: Remove all strcpy() uses in favor of strscpy()
@ 2021-07-18  9:06 Len Baker
  2021-07-19  5:43 ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Len Baker @ 2021-07-18  9:06 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Len Baker, Nikolay Kyx, Aditya Srivastava, Jiapeng Chong,
	William Durand, Dan Carpenter, Romain Perier, Allen Pais,
	Phillip Potter, zhaoxiao, 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/rtl8192e/rtl8192e/r8192E_dev.c | 2 +-
 drivers/staging/rtl8192e/rtllib_softmac.c      | 3 ++-
 drivers/staging/rtl8192e/rtllib_softmac_wx.c   | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c b/drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c
index b626ac45db80..358b629d2cc6 100644
--- a/drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c
+++ b/drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c
@@ -2167,7 +2167,7 @@ rtl92e_init_variables(struct net_device  *dev)
 {
 	struct r8192_priv *priv = rtllib_priv(dev);

-	strcpy(priv->nick, "rtl8192E");
+	strscpy(priv->nick, "rtl8192E", sizeof(priv->nick));

 	priv->rtllib->softmac_features  = IEEE_SOFTMAC_SCAN |
 		IEEE_SOFTMAC_ASSOCIATE | IEEE_SOFTMAC_PROBERQ |
diff --git a/drivers/staging/rtl8192e/rtllib_softmac.c b/drivers/staging/rtl8192e/rtllib_softmac.c
index 25b3d3950a3c..d2726d01c757 100644
--- a/drivers/staging/rtl8192e/rtllib_softmac.c
+++ b/drivers/staging/rtl8192e/rtllib_softmac.c
@@ -2582,7 +2582,8 @@ static void rtllib_start_ibss_wq(void *data)
 	mutex_lock(&ieee->wx_mutex);

 	if (ieee->current_network.ssid_len == 0) {
-		strcpy(ieee->current_network.ssid, RTLLIB_DEFAULT_TX_ESSID);
+		strscpy(ieee->current_network.ssid, RTLLIB_DEFAULT_TX_ESSID,
+			sizeof(ieee->current_network.ssid));
 		ieee->current_network.ssid_len = strlen(RTLLIB_DEFAULT_TX_ESSID);
 		ieee->ssid_set = 1;
 	}
diff --git a/drivers/staging/rtl8192e/rtllib_softmac_wx.c b/drivers/staging/rtl8192e/rtllib_softmac_wx.c
index f89799d43b1b..5968407c646d 100644
--- a/drivers/staging/rtl8192e/rtllib_softmac_wx.c
+++ b/drivers/staging/rtl8192e/rtllib_softmac_wx.c
@@ -543,7 +543,7 @@ int rtllib_wx_get_name(struct rtllib_device *ieee,
 			     struct iw_request_info *info,
 			     union iwreq_data *wrqu, char *extra)
 {
-	strcpy(wrqu->name, "802.11");
+	strscpy(wrqu->name, "802.11", sizeof(wrqu->name));

 	if (ieee->modulation & RTLLIB_CCK_MODULATION)
 		strcat(wrqu->name, "b");
--
2.25.1


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

* Re: [PATCH] staging/rtl8192e: Remove all strcpy() uses in favor of strscpy()
  2021-07-18  9:06 [PATCH] staging/rtl8192e: Remove all strcpy() uses in favor of strscpy() Len Baker
@ 2021-07-19  5:43 ` Dan Carpenter
  2021-07-23 16:30   ` Len Baker
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2021-07-19  5:43 UTC (permalink / raw)
  To: Len Baker
  Cc: Greg Kroah-Hartman, Nikolay Kyx, Aditya Srivastava,
	Jiapeng Chong, William Durand, Romain Perier, Allen Pais,
	Phillip Potter, zhaoxiao, linux-staging, linux-kernel

On Sun, Jul 18, 2021 at 11:06:36AM +0200, Len Baker wrote:
> diff --git a/drivers/staging/rtl8192e/rtllib_softmac_wx.c b/drivers/staging/rtl8192e/rtllib_softmac_wx.c
> index f89799d43b1b..5968407c646d 100644
> --- a/drivers/staging/rtl8192e/rtllib_softmac_wx.c
> +++ b/drivers/staging/rtl8192e/rtllib_softmac_wx.c
> @@ -543,7 +543,7 @@ int rtllib_wx_get_name(struct rtllib_device *ieee,
>  			     struct iw_request_info *info,
>  			     union iwreq_data *wrqu, char *extra)
>  {
> -	strcpy(wrqu->name, "802.11");
> +	strscpy(wrqu->name, "802.11", sizeof(wrqu->name));
> 
>  	if (ieee->modulation & RTLLIB_CCK_MODULATION)
>  		strcat(wrqu->name, "b");

This patch is just about silencing inferior static analysis tools,
right?  Most checkers can figure out the size of the array and verify
that it has space for "802.11".  Probably it's only raw grep which
can't.

It doesn't make sense to me that we have strscpy() followed by strcat.
So let's fix both.

regards,
dan carpenter

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

* Re: [PATCH] staging/rtl8192e: Remove all strcpy() uses in favor of strscpy()
  2021-07-19  5:43 ` Dan Carpenter
@ 2021-07-23 16:30   ` Len Baker
  0 siblings, 0 replies; 3+ messages in thread
From: Len Baker @ 2021-07-23 16:30 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Len Baker, Greg Kroah-Hartman, Nikolay Kyx, Aditya Srivastava,
	Jiapeng Chong, William Durand, Romain Perier, Allen Pais,
	Phillip Potter, zhaoxiao, linux-staging, linux-kernel

Hi,

On Mon, Jul 19, 2021 at 08:43:45AM +0300, Dan Carpenter wrote:
> On Sun, Jul 18, 2021 at 11:06:36AM +0200, Len Baker wrote:
> > diff --git a/drivers/staging/rtl8192e/rtllib_softmac_wx.c b/drivers/staging/rtl8192e/rtllib_softmac_wx.c
> > index f89799d43b1b..5968407c646d 100644
> > --- a/drivers/staging/rtl8192e/rtllib_softmac_wx.c
> > +++ b/drivers/staging/rtl8192e/rtllib_softmac_wx.c
> > @@ -543,7 +543,7 @@ int rtllib_wx_get_name(struct rtllib_device *ieee,
> >  			     struct iw_request_info *info,
> >  			     union iwreq_data *wrqu, char *extra)
> >  {
> > -	strcpy(wrqu->name, "802.11");
> > +	strscpy(wrqu->name, "802.11", sizeof(wrqu->name));
> >
> >  	if (ieee->modulation & RTLLIB_CCK_MODULATION)
> >  		strcat(wrqu->name, "b");
>
> This patch is just about silencing inferior static analysis tools,
> right?  Most checkers can figure out the size of the array and verify
> that it has space for "802.11".  Probably it's only raw grep which
> can't.
>
> It doesn't make sense to me that we have strscpy() followed by strcat.
> So let's fix both.

Ok, I will send a v2 for review. Thanks for the feedback.

>
> regards,
> dan carpenter

Regards,
Len

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

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-18  9:06 [PATCH] staging/rtl8192e: Remove all strcpy() uses in favor of strscpy() Len Baker
2021-07-19  5:43 ` Dan Carpenter
2021-07-23 16:30   ` 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