Skip to contentSkip to conversation

Do not DMA on the stack

PATCH Superseded Ksenija Stanojevic 3 participants 14 messages Oct 4, 2015 – Oct 5, 2015 Staging

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Do not DMA on the stack

Fix error "doing DMA on the stack" by using kzalloc for buffer allocation in rtl8192u/r8192U_core.c in the following functions:

	write_nic_byte_E()
	write_nic_byte()
	write_nic_word()
	write_nic_dword()

Issue found by smatch.

Ksenija Stanojevic (4):
Staging: rtl8192u: Do not DMA on the stack in write_nic_byte_E()
Staging: rtl8192u: Do not DMA on the stack in write_nic_byte()
Staging: rtl8192u: Do not DMA on the stack in write_nic_word()
Staging: rtl8192u: Do not DMA on the stack in write_nic_dword()

 drivers/staging/rtl8192u/r8192U_core.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/4 Staging: rtl8192u: Do not DMA on the stack in write_nic_byte_E()

Fix error "doing DMA on the stack" by using kzalloc for buffer allocation.
Issue found by smatch.

---
 drivers/staging/rtl8192u/r8192U_core.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/staging/rtl8192u/r8192U_core.c +5 -0
index 28b54ba..287e2ce 100644
@@ -259,10 +259,15 @@ void write_nic_byte_E(struct net_device *dev, int indx, u8 data)
 	int status;
 	struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
 	struct usb_device *udev = priv->udev;
+	u8 *pdata = kzalloc(sizeof(data), GFP_KERNEL);
+
+	if (!pdata)
+		return;
 
 	status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
 				 RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
 				 indx | 0xfe00, 0, &data, 1, HZ / 2);
+	kfree(pdata);
 
 	if (status < 0)
 		netdev_err(dev, "write_nic_byte_E TimeOut! status: %d\n",
Signature · 1 line
1.9.1
maintainer
#2 lore raw

Re: [Outreachy kernel] [PATCH 1/4] Staging: rtl8192u: Do not DMA on the stack in write_nic_byte_E()

Quoted 3 lines · Ksenija Stanojevic

Fix error "doing DMA on the stack" by using kzalloc for buffer allocation.
Issue found by smatch.

What does smatch say after you made your changes and you run it on the code again?

thanks,

greg k-h

#3 lore raw

Re: [Outreachy kernel] [PATCH 1/4] Staging: rtl8192u: Do not DMA on the stack in write_nic_byte_E()

Quoted 7 lines · Greg KH
Quoted 3 lines · Ksenija Stanojevic

Fix error "doing DMA on the stack" by using kzalloc for buffer allocation.
Issue found by smatch.

What does smatch say after you made your changes and you run it on the code again?

I made a mistake i should have replace &data with pdata.

Quoted 10 lines

thanks,

greg k-h

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20151005031746.GD27303%40kroah.com.
For more options, visit https://groups.google.com/d/optout.

#4 lore raw

PATCH 2/4 Staging: rtl8192u: Do not DMA on the stack in write_nic_byte()

In reply to Ksenija Stanojevic

Fix error "doing DMA on the stack" by using kzalloc for buffer allocation.
Issue found by smatch.

---
 drivers/staging/rtl8192u/r8192U_core.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/staging/rtl8192u/r8192U_core.c +5 -0
index 287e2ce..94e3610 100644
@@ -298,11 +298,16 @@ void write_nic_byte(struct net_device *dev, int indx, u8 data)
 
 	struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
 	struct usb_device *udev = priv->udev;
+	u8 *pdata = kzalloc(sizeof(data), GFP_KERNEL);
+
+	if (!pdata)
+		return;
 
 	status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
 				 RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
 				 (indx & 0xff) | 0xff00, (indx >> 8) & 0x0f,
 				 &data, 1, HZ / 2);
+	kfree(pdata);
 
 	if (status < 0)
 		netdev_err(dev, "write_nic_byte TimeOut! status: %d\n", status);
Signature · 1 line
1.9.1
#5 lore raw

PATCH 3/4 Staging: rtl8192u: Do not DMA on the stack in write_nic_word()

In reply to Ksenija Stanojevic

Fix error "doing DMA on the stack" by using kzalloc for buffer allocation.
Issue found by smatch.

---
 drivers/staging/rtl8192u/r8192U_core.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/staging/rtl8192u/r8192U_core.c +5 -0
index 94e3610..6d0127f 100644
@@ -323,11 +323,16 @@ void write_nic_word(struct net_device *dev, int indx, u16 data)
 
 	struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
 	struct usb_device *udev = priv->udev;
+	u16 *pdata = kzalloc(sizeof(data), GFP_KERNEL);
+
+	if (!pdata)
+		return;
 
 	status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
 				 RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
 				 (indx & 0xff) | 0xff00, (indx >> 8) & 0x0f,
 				 &data, 2, HZ / 2);
+	kfree(pdata);
 
 	if (status < 0)
 		netdev_err(dev, "write_nic_word TimeOut! status: %d\n", status);
Signature · 1 line
1.9.1
#6 lore raw

PATCH 4/4 Staging: rtl8192u: Do not DMA on the stack in write_nic_dword()

In reply to Ksenija Stanojevic

Fix error "doing DMA on the stack" by using kzalloc for buffer allocation.
Issue found by smatch.

---
 drivers/staging/rtl8192u/r8192U_core.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/staging/rtl8192u/r8192U_core.c +5 -0
index 6d0127f..a5bf8b4 100644
@@ -347,11 +347,16 @@ void write_nic_dword(struct net_device *dev, int indx, u32 data)
 
 	struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
 	struct usb_device *udev = priv->udev;
+	u32 *pdata = kzalloc(sizeof(data), GFP_KERNEL);
+
+	if (!pdata)
+		return;
 
 	status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
 				 RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
 				 (indx & 0xff) | 0xff00, (indx >> 8) & 0x0f,
 				 &data, 4, HZ / 2);
+	kfree(pdata);
 
 
 	if (status < 0)
Signature · 1 line
1.9.1
#7 lore raw

Re: [PATCH 4/4] Staging: rtl8192u: Do not DMA on the stack in write_nic_dword()

Quoted 16 lines · Ksenija Stanojevic

Fix error "doing DMA on the stack" by using kzalloc for buffer allocation.
Issue found by smatch.

---
 drivers/staging/rtl8192u/r8192U_core.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/staging/rtl8192u/r8192U_core.c +0 -0
index 6d0127f..a5bf8b4 100644
@@ -347,11 +347,16 @@ void write_nic_dword(struct net_device *dev, int indx, u32 data)
 
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);

drivers/staging/rtl8192u/r8192U_core.c void write_nic_dword(struct net_device *dev, int indx, u32 data) · line 358

Quoted 10 lines
drivers/staging/rtl8192u/r8192U_core.c +4 -0
        struct usb_device *udev = priv->udev;
+       u32 *pdata = kzalloc(sizeof(data), GFP_KERNEL);
+
+       if (!pdata)
+               return;
 
        status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
                                 RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
                                 (indx & 0xff) | 0xff00, (indx >> 8) & 0x0f,
                                 &data, 4, HZ / 2);

I made a mistake i should have replace &data with pdata.

Quoted 7 lines
drivers/staging/rtl8192u/r8192U_core.c +1 -1
+       kfree(pdata);
 
 
        if (status < 0)
--

1.9.1

#8 lore raw
In reply to Ksenija Stanojevic
Quoted 8 lines · On Sunday 04 October 2015 22:13:02 Ksenija Stanojevic wrote:

Fix error "doing DMA on the stack" by using kzalloc for buffer allocation in rtl8192u/r8192U_core.c in the following functions:

        write_nic_byte_E()
        write_nic_byte()
        write_nic_word()
        write_nic_dword()

Issue found by smatch.

Quoted 8 lines

Ksenija Stanojevic (4):
Staging: rtl8192u: Do not DMA on the stack in write_nic_byte_E()
Staging: rtl8192u: Do not DMA on the stack in write_nic_byte()
Staging: rtl8192u: Do not DMA on the stack in write_nic_word()
Staging: rtl8192u: Do not DMA on the stack in write_nic_dword()

The changes all look wrong to me, can you guess what the problem is when you read them again?

Also, these are four instances of the same code, in the same file, so it would be reasonable to do a single patch, and then you can do the other five instances in the same file as well.

Arnd

#9 lore raw
Quoted 18 lines · Arnd Bergmann
Quoted 8 lines · On Sunday 04 October 2015 22:13:02 Ksenija Stanojevic wrote:

Fix error "doing DMA on the stack" by using kzalloc for buffer allocation in rtl8192u/r8192U_core.c in the following functions:

        write_nic_byte_E()
        write_nic_byte()
        write_nic_word()
        write_nic_dword()

Issue found by smatch.

Quoted 8 lines

Ksenija Stanojevic (4):
Staging: rtl8192u: Do not DMA on the stack in write_nic_byte_E()
Staging: rtl8192u: Do not DMA on the stack in write_nic_byte()
Staging: rtl8192u: Do not DMA on the stack in write_nic_word()
Staging: rtl8192u: Do not DMA on the stack in write_nic_dword()

Quoted 2 lines

The changes all look wrong to me, can you guess what the problem is when you read them again?

I forgot to replace &data with pdata in usb_control_msg()

Quoted 6 lines

Also, these are four instances of the same code, in the same file, so it would be reasonable to do a single patch, and then you can do the other five instances in the same file as well.

Arnd

#10 lore raw
Quoted 19 lines · Ksenija Stanojević
Quoted 18 lines · Arnd Bergmann
Quoted 16 lines · On Sunday 04 October 2015 22:13:02 Ksenija Stanojevic wrote:

Fix error "doing DMA on the stack" by using kzalloc for buffer allocation in rtl8192u/r8192U_core.c in the following functions:

        write_nic_byte_E()
        write_nic_byte()
        write_nic_word()
        write_nic_dword()

Issue found by smatch.

Ksenija Stanojevic (4):
Staging: rtl8192u: Do not DMA on the stack in write_nic_byte_E()
Staging: rtl8192u: Do not DMA on the stack in write_nic_byte()
Staging: rtl8192u: Do not DMA on the stack in write_nic_word()
Staging: rtl8192u: Do not DMA on the stack in write_nic_dword()

Quoted 4 lines
Quoted 2 lines

The changes all look wrong to me, can you guess what the problem is when you read them again?

I forgot to replace &data with pdata in usb_control_msg()

And also assign pdata to point to data
pdata = &data;

Quoted 6 lines
Quoted 6 lines

Also, these are four instances of the same code, in the same file, so it would be reasonable to do a single patch, and then you can do the other five instances in the same file as well.

Arnd

#11 lore raw
Quoted 21 lines · Ksenija Stanojević
Quoted 19 lines · Ksenija Stanojević
Quoted 18 lines · Arnd Bergmann
Quoted 16 lines · On Sunday 04 October 2015 22:13:02 Ksenija Stanojevic wrote:

Fix error "doing DMA on the stack" by using kzalloc for buffer allocation in rtl8192u/r8192U_core.c in the following functions:

        write_nic_byte_E()
        write_nic_byte()
        write_nic_word()
        write_nic_dword()

Issue found by smatch.

Ksenija Stanojevic (4):
Staging: rtl8192u: Do not DMA on the stack in write_nic_byte_E()
Staging: rtl8192u: Do not DMA on the stack in write_nic_byte()
Staging: rtl8192u: Do not DMA on the stack in write_nic_word()
Staging: rtl8192u: Do not DMA on the stack in write_nic_dword()

Quoted 3 lines
Quoted 3 lines
Quoted 2 lines

The changes all look wrong to me, can you guess what the problem is when you read them again?

Please ignore this.

Quoted 2 lines

And also assign pdata to point to data
pdata = &data;

thanks,
Ksenija

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Also, these are four instances of the same code, in the same file, so it would be reasonable to do a single patch, and then you can do the other five instances in the same file as well.

Arnd

#12 lore raw
Quoted 23 lines · Ksenija Stanojević
Quoted 21 lines · Ksenija Stanojević
Quoted 19 lines · Ksenija Stanojević
Quoted 18 lines · Arnd Bergmann
Quoted 16 lines · On Sunday 04 October 2015 22:13:02 Ksenija Stanojevic wrote:

Fix error "doing DMA on the stack" by using kzalloc for buffer allocation in rtl8192u/r8192U_core.c in the following functions:

        write_nic_byte_E()
        write_nic_byte()
        write_nic_word()
        write_nic_dword()

Issue found by smatch.

Ksenija Stanojevic (4):
Staging: rtl8192u: Do not DMA on the stack in write_nic_byte_E()
Staging: rtl8192u: Do not DMA on the stack in write_nic_byte()
Staging: rtl8192u: Do not DMA on the stack in write_nic_word()
Staging: rtl8192u: Do not DMA on the stack in write_nic_dword()

Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines

The changes all look wrong to me, can you guess what the problem is when you read them again?

Please ignore this.

Quoted 2 lines

And also assign pdata to point to data
pdata = &data;

I meant *pdata = data.

Quoted 8 lines

thanks,
Ksenija

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Also, these are four instances of the same code, in the same file, so it would be reasonable to do a single patch, and then you can do the other five instances in the same file as well.

Arnd

#13 lore raw
Quoted 25 lines · On Monday 05 October 2015 08:50:09 Ksenija Stanojević wrote:
Quoted 23 lines · Ksenija Stanojević
Quoted 21 lines · Ksenija Stanojević
Quoted 19 lines · Ksenija Stanojević
Quoted 18 lines · Arnd Bergmann
Quoted 16 lines · On Sunday 04 October 2015 22:13:02 Ksenija Stanojevic wrote:

Fix error "doing DMA on the stack" by using kzalloc for buffer allocation in rtl8192u/r8192U_core.c in the following functions:

        write_nic_byte_E()
        write_nic_byte()
        write_nic_word()
        write_nic_dword()

Issue found by smatch.

Ksenija Stanojevic (4):
Staging: rtl8192u: Do not DMA on the stack in write_nic_byte_E()
Staging: rtl8192u: Do not DMA on the stack in write_nic_byte()
Staging: rtl8192u: Do not DMA on the stack in write_nic_word()
Staging: rtl8192u: Do not DMA on the stack in write_nic_dword()

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines

The changes all look wrong to me, can you guess what the problem is when you read them again?

Please ignore this.

Quoted 2 lines

And also assign pdata to point to data
pdata = &data;

I meant *pdata = data.

Right. Once you change that, it should be fine.

Arnd