Linux kernel staging patches
 help / color / Atom feed
* [PATCH] staging/ks7010: Remove all strcpy() uses in favor of strscpy()
@ 2021-07-17 15:37 Len Baker
  2021-07-19  5:26 ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Len Baker @ 2021-07-17 15:37 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Len Baker, Gustavo A. R. Silva, Dan Carpenter, 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/ks7010/ks_wlan_net.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/ks7010/ks_wlan_net.c b/drivers/staging/ks7010/ks_wlan_net.c
index 09e7b4cd0138..7a38b1ceeb5c 100644
--- a/drivers/staging/ks7010/ks_wlan_net.c
+++ b/drivers/staging/ks7010/ks_wlan_net.c
@@ -158,13 +158,13 @@ static int ks_wlan_get_name(struct net_device *dev,

 	/* for SLEEP MODE */
 	if (priv->dev_state < DEVICE_STATE_READY)
-		strcpy(cwrq->name, "NOT READY!");
+		strscpy(cwrq->name, "NOT READY!", sizeof(cwrq->name));
 	else if (priv->reg.phy_type == D_11B_ONLY_MODE)
-		strcpy(cwrq->name, "IEEE 802.11b");
+		strscpy(cwrq->name, "IEEE 802.11b", sizeof(cwrq->name));
 	else if (priv->reg.phy_type == D_11G_ONLY_MODE)
-		strcpy(cwrq->name, "IEEE 802.11g");
+		strscpy(cwrq->name, "IEEE 802.11g", sizeof(cwrq->name));
 	else
-		strcpy(cwrq->name, "IEEE 802.11b/g");
+		strscpy(cwrq->name, "IEEE 802.11b/g", sizeof(cwrq->name));

 	return 0;
 }
@@ -1808,7 +1808,7 @@ static int ks_wlan_get_firmware_version(struct net_device *dev,
 {
 	struct ks_wlan_private *priv = netdev_priv(dev);

-	strcpy(extra, priv->firmware_version);
+	strscpy(extra, priv->firmware_version, sizeof(extra));
 	dwrq->length = priv->version_size + 1;
 	return 0;
 }
--
2.25.1


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

* Re: [PATCH] staging/ks7010: Remove all strcpy() uses in favor of strscpy()
  2021-07-17 15:37 [PATCH] staging/ks7010: Remove all strcpy() uses in favor of strscpy() Len Baker
@ 2021-07-19  5:26 ` Dan Carpenter
  2021-07-23 14:30   ` Len Baker
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2021-07-19  5:26 UTC (permalink / raw)
  To: Len Baker
  Cc: Greg Kroah-Hartman, Gustavo A. R. Silva, linux-staging, linux-kernel

On Sat, Jul 17, 2021 at 05:37:59PM +0200, Len Baker wrote:
> @@ -1808,7 +1808,7 @@ static int ks_wlan_get_firmware_version(struct net_device *dev,
>  {
>  	struct ks_wlan_private *priv = netdev_priv(dev);
> 
> -	strcpy(extra, priv->firmware_version);
> +	strscpy(extra, priv->firmware_version, sizeof(extra));

Extra is a pointer and not an array so this doesn't work.

regards,
dan carpenter


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

* Re: [PATCH] staging/ks7010: Remove all strcpy() uses in favor of strscpy()
  2021-07-19  5:26 ` Dan Carpenter
@ 2021-07-23 14:30   ` Len Baker
  0 siblings, 0 replies; 3+ messages in thread
From: Len Baker @ 2021-07-23 14:30 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Len Baker, Greg Kroah-Hartman, Gustavo A. R. Silva,
	linux-staging, linux-kernel

Hi,

On Mon, Jul 19, 2021 at 08:26:23AM +0300, Dan Carpenter wrote:
> On Sat, Jul 17, 2021 at 05:37:59PM +0200, Len Baker wrote:
> > @@ -1808,7 +1808,7 @@ static int ks_wlan_get_firmware_version(struct net_device *dev,
> >  {
> >  	struct ks_wlan_private *priv = netdev_priv(dev);
> >
> > -	strcpy(extra, priv->firmware_version);
> > +	strscpy(extra, priv->firmware_version, sizeof(extra));
>
> Extra is a pointer and not an array so this doesn't work.

Apologies. I will send a v2 for review.

Thanks for your time.
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-17 15:37 [PATCH] staging/ks7010: Remove all strcpy() uses in favor of strscpy() Len Baker
2021-07-19  5:26 ` Dan Carpenter
2021-07-23 14: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