Skip to contentSkip to conversation

USB Pegasus driver - avoid a potential NULL pointer dereference.

PATCH In review Jesper Juhl 5 participants 7 messages Jul 28, 2007 – Jul 30, 2007

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 USB Pegasus driver - avoid a potential NULL pointer dereference.

Hello,

This patch makes sure we don't dereference a NULL pointer in drivers/net/usb/pegasus.c::write_bulk_callback() in the initial struct net_device *net = pegasus->net; assignment.
The existing code checks if 'pegasus' is NULL and bails out if it is, so we better not touch that pointer until after that check.

Please consider merging.

---

 drivers/net/usb/pegasus.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/net/usb/pegasus.c +3 -1
index a05fd97..04cba6b 100644
@@ -768,11 +768,13 @@ done:
 static void write_bulk_callback(struct urb *urb)
 {
 	pegasus_t *pegasus = urb->context;
-	struct net_device *net = pegasus->net;
+	struct net_device *net;
 
 	if (!pegasus)
 		return;
 
+	net = pegasus->net;
+
 	if (!netif_device_present(net) || !netif_running(net))
 		return;
 

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

#1 lore raw

Hi,

Quoted 16 lines · Jesper Juhl

Hello,

This patch makes sure we don't dereference a NULL pointer in drivers/net/usb/pegasus.c::write_bulk_callback() in the initial struct net_device *net = pegasus->net; assignment.
The existing code checks if 'pegasus' is NULL and bails out if it is, so we better not touch that pointer until after that check. [...]

drivers/net/usb/pegasus.c +0 -0
index a05fd97..04cba6b 100644
@@ -768,11 +768,13 @@ done:
 static void write_bulk_callback(struct urb *urb)
 {
        pegasus_t *pegasus = urb->context;

drivers/net/usb/pegasus.c done: · line 779

Quoted 10 lines
drivers/net/usb/pegasus.c +3 -1
-       struct net_device *net = pegasus->net;
+       struct net_device *net;
 
        if (!pegasus)
                return;
 
+       net = pegasus->net;
+
        if (!netif_device_present(net) || !netif_running(net))
                return;

Is it really possible that we're called into this function with urb->context == NULL? If not, I'd suggest let's just get rid of the check itself, instead.

Satyam

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

#2 lore raw
Quoted 25 lines · Satyam Sharma

Hi,

Quoted 22 lines · Jesper Juhl

Hello,

This patch makes sure we don't dereference a NULL pointer in drivers/net/usb/pegasus.c::write_bulk_callback() in the initial struct net_device *net = pegasus->net; assignment.
The existing code checks if 'pegasus' is NULL and bails out if it is, so we better not touch that pointer until after that check. [...]

drivers/net/usb/pegasus.c +1 -1
index a05fd97..04cba6b 100644
@@ -768,11 +768,13 @@ done:
 static void write_bulk_callback(struct urb *urb)
 {
        pegasus_t *pegasus = urb->context;
-       struct net_device *net = pegasus->net;
+       struct net_device *net;
 
        if (!pegasus)
                return;
 
Quoted 9 lines

drivers/net/usb/pegasus.c done: · line 779

Quoted 4 lines
drivers/net/usb/pegasus.c +2 -0
+       net = pegasus->net;
+
        if (!netif_device_present(net) || !netif_running(net))
                return;

Is it really possible that we're called into this function with urb->context == NULL? If not, I'd suggest let's just get rid of the check itself, instead.

I'm not sure. I am not very familiar with this code. I just figured that moving the assignment is potentially a little safer and it is certainly no worse than the current code, so that's a safe and potentially benneficial change. Removing the check may be safe but I'm not certain enough to make that call...

Signature · 13 lines
Jesper Juhl <[email protected]>
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel
#3 lore raw

Am Sonntag 29 Juli 2007 schrieb Jesper Juhl:

Quoted 35 lines · Satyam Sharma
Quoted 25 lines

Hi,

Quoted 22 lines · Jesper Juhl

Hello,

This patch makes sure we don't dereference a NULL pointer in drivers/net/usb/pegasus.c::write_bulk_callback() in the initial struct net_device *net = pegasus->net; assignment.
The existing code checks if 'pegasus' is NULL and bails out if it is, so we better not touch that pointer until after that check. [...]

drivers/net/usb/pegasus.c +1 -1
index a05fd97..04cba6b 100644
@@ -768,11 +768,13 @@ done:
 static void write_bulk_callback(struct urb *urb)
 {
        pegasus_t *pegasus = urb->context;
-       struct net_device *net = pegasus->net;
+       struct net_device *net;
 
        if (!pegasus)
                return;
 
Quoted 9 lines

drivers/net/usb/pegasus.c done: · line 779

Quoted 4 lines
drivers/net/usb/pegasus.c +2 -0
+       net = pegasus->net;
+
        if (!netif_device_present(net) || !netif_running(net))
                return;

Is it really possible that we're called into this function with urb->context == NULL? If not, I'd suggest let's just get rid of the check itself, instead.

Quoted 5 lines

I'm not sure. I am not very familiar with this code. I just figured that moving the assignment is potentially a little safer and it is certainly no worse than the current code, so that's a safe and potentially benneficial change. Removing the check may be safe but I'm not certain enough to make that call...

pegasus == NULL there would be a kernel bug. Silently ignoring it, like the code now wants to do is bad. As the oops has never been reported, I figure turning it into an explicit debugging test is overkill, so removal seems to be the best option.

Regards
Oliver

#4 lore raw
Quoted 24 lines · Oliver Neukum

Am Sonntag 29 Juli 2007 schrieb Jesper Juhl:

Quoted 17 lines · Satyam Sharma
Quoted 12 lines

Hi,

Quoted 8 lines · Jesper Juhl

Hello,

This patch makes sure we don't dereference a NULL pointer in drivers/net/usb/pegasus.c::write_bulk_callback() in the initial struct net_device *net = pegasus->net; assignment.
The existing code checks if 'pegasus' is NULL and bails out if it is, so we better not touch that pointer until after that check. [...]

Quoted 4 lines

Is it really possible that we're called into this function with urb->context == NULL? If not, I'd suggest let's just get rid of the check itself, instead.

Quoted 5 lines

I'm not sure. I am not very familiar with this code. I just figured that moving the assignment is potentially a little safer and it is certainly no worse than the current code, so that's a safe and potentially benneficial change. Removing the check may be safe but I'm not certain enough to make that call...

Quoted 4 lines

pegasus == NULL there would be a kernel bug. Silently ignoring it, like the code now wants to do is bad. As the oops has never been reported, I figure turning it into an explicit debugging test is overkill, so removal seems to be the best option.

Ok, thanks. Updated patch below.

[PATCH] pegasus: Remove bogus checks in urb->complete() callbacks

urb->complete() callbacks registered in drivers/net/usb/pegasus.c needlessly check for urb->context != NULL, but that is not possible (the only way that can be possible would be a kernel bug elsewhere, and these checks would simply end up hiding that). So let's remove the bogus checks.

---

 drivers/net/usb/pegasus.c |    9 +--------
 1 files changed, 1 insertions(+), 8 deletions(-)
drivers/net/usb/pegasus.c +1 -8
index a05fd97..439ef9f 100644
@@ -770,9 +770,6 @@ static void write_bulk_callback(struct urb *urb)
 	pegasus_t *pegasus = urb->context;
 	struct net_device *net = pegasus->net;
 
-	if (!pegasus)
-		return;
-
 	if (!netif_device_present(net) || !netif_running(net))
 		return;
 
@@ -805,13 +802,9 @@ static void write_bulk_callback(struct urb *urb)
 static void intr_callback(struct urb *urb)
 {
 	pegasus_t *pegasus = urb->context;
-	struct net_device *net;
+	struct net_device *net = pegasus->net;
 	int status;
 
-	if (!pegasus)
-		return;
-	net = pegasus->net;
-
 	switch (urb->status) {
 	case 0:
 		break;
maintainer
#5 lore raw
In reply to Oliver Neukum
Quoted 42 lines · Oliver Neukum

Am Sonntag 29 Juli 2007 schrieb Jesper Juhl:

Quoted 35 lines · Satyam Sharma
Quoted 25 lines

Hi,

Quoted 22 lines · Jesper Juhl

Hello,

This patch makes sure we don't dereference a NULL pointer in drivers/net/usb/pegasus.c::write_bulk_callback() in the initial struct net_device *net = pegasus->net; assignment.
The existing code checks if 'pegasus' is NULL and bails out if it is, so we better not touch that pointer until after that check. [...]

drivers/net/usb/pegasus.c +1 -1
index a05fd97..04cba6b 100644
@@ -768,11 +768,13 @@ done:
 static void write_bulk_callback(struct urb *urb)
 {
        pegasus_t *pegasus = urb->context;
-       struct net_device *net = pegasus->net;
+       struct net_device *net;
 
        if (!pegasus)
                return;
 
Quoted 9 lines

drivers/net/usb/pegasus.c done: · line 779

Quoted 4 lines
drivers/net/usb/pegasus.c +2 -0
+       net = pegasus->net;
+
        if (!netif_device_present(net) || !netif_running(net))
                return;

Is it really possible that we're called into this function with urb->context == NULL? If not, I'd suggest let's just get rid of the check itself, instead.

Quoted 5 lines

I'm not sure. I am not very familiar with this code. I just figured that moving the assignment is potentially a little safer and it is certainly no worse than the current code, so that's a safe and potentially benneficial change. Removing the check may be safe but I'm not certain enough to make that call...

Quoted 4 lines

pegasus == NULL there would be a kernel bug. Silently ignoring it, like the code now wants to do is bad. As the oops has never been reported, I figure turning it into an explicit debugging test is overkill, so removal seems to be the best option.

In the past urb->context was not guaranteed to be non-null for any asynchronous calls. If this is not the case anymore then it should be removed from at least two more locations in the driver.

Attached you'll find the resulting patch.

Petko

net/usb/pegasus.c renamed from net/usb/pegasus.c.old +2 -16
@@ -100,9 +100,6 @@ static void ctrl_callback(struct urb *ur
 {
 	pegasus_t *pegasus = urb->context;
 
-	if (!pegasus)
-		return;
-
 	switch (urb->status) {
 	case 0:
 		if (pegasus->flags & ETH_REGS_CHANGE) {
@@ -609,15 +606,11 @@ static inline struct sk_buff *pull_skb(p
 static void read_bulk_callback(struct urb *urb)
 {
 	pegasus_t *pegasus = urb->context;
-	struct net_device *net;
+	struct net_device *net = pegasus->net;
 	int rx_status, count = urb->actual_length;
 	u8 *buf = urb->transfer_buffer;
 	__u16 pkt_len;
 
-	if (!pegasus)
-		return;
-
-	net = pegasus->net;
 	if (!netif_device_present(net) || !netif_running(net))
 		return;
 
@@ -770,9 +763,6 @@ static void write_bulk_callback(struct u
 	pegasus_t *pegasus = urb->context;
 	struct net_device *net = pegasus->net;
 
-	if (!pegasus)
-		return;
-
 	if (!netif_device_present(net) || !netif_running(net))
 		return;
 
@@ -805,13 +795,9 @@ static void write_bulk_callback(struct u
 static void intr_callback(struct urb *urb)
 {
 	pegasus_t *pegasus = urb->context;
-	struct net_device *net;
+	struct net_device *net = pegasus->net;
 	int status;
 
-	if (!pegasus)
-		return;
-	net = pegasus->net;
-
 	switch (urb->status) {
 	case 0:
 		break;

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

#6 lore raw
Quoted 8 lines · Petko Manolov
Quoted 5 lines · Oliver Neukum

[...]
pegasus == NULL there would be a kernel bug. Silently ignoring it, like the code now wants to do is bad. As the oops has never been reported, I figure turning it into an explicit debugging test is overkill, so removal seems to be the best option.

Quoted 5 lines

In the past urb->context was not guaranteed to be non-null for any asynchronous calls. If this is not the case anymore then it should be removed from at least two more locations in the driver.

Attached you'll find the resulting patch.

Given Oliver's earlier comment, it looks okay to me. Thanks.