Skip to contentSkip to conversation

staging:gpib: Fix a dereference before null check issue

PATCH Superseded Paolo Perego 4 participants 7 messages Nov 20, 2024 – Nov 21, 2024 Staging

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging:gpib: Fix a dereference before null check issue

This commit fixes a dereference before null check issue discovered by Coverity (CID 1601566).

The check ad line 1450 suggests that a_priv can be NULL, however it has been derefenced before, in the interface_to_usbdev() call.

---
 drivers/staging/gpib/agilent_82357a/agilent_82357a.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/gpib/agilent_82357a/agilent_82357a.c +1 -1
index bf05fb4a736b..604e13c32dfb 100644
@@ -1446,8 +1446,8 @@ static void agilent_82357a_detach(gpib_board_t *board)
 	mutex_lock(&agilent_82357a_hotplug_lock);
 
 	a_priv = board->private_data;
-	usb_dev = interface_to_usbdev(a_priv->bus_interface);
 	if (a_priv) {
+		usb_dev = interface_to_usbdev(a_priv->bus_interface);
 		if (a_priv->bus_interface) {
 			agilent_82357a_go_idle(board);
 			usb_set_intfdata(a_priv->bus_interface, NULL);
Signature · 1 line
2.47.0
#2 lore raw
In reply to Paolo Perego
Quoted 8 lines · Paolo Perego

This commit fixes a dereference before null check issue discovered by Coverity (CID 1601566).

The check ad line 1450 suggests that a_priv can be NULL, however it has been derefenced before, in the interface_to_usbdev() call.

---

You need a Fixes tag. But I'm pretty sure the correct fix is to remove the NULL check.

regards,
dan carpenter

#3 lore raw

Op 20-11-2024 om 18:04 schreef Dan Carpenter:

Quoted 11 lines · Paolo Perego
Quoted 8 lines

This commit fixes a dereference before null check issue discovered by Coverity (CID 1601566).

The check ad line 1450 suggests that a_priv can be NULL, however it has been derefenced before, in the interface_to_usbdev() call.

---

You need a Fixes tag. But I'm pretty sure the correct fix is to remove the NULL check.

In the whole agilent_82357a.c module there is no consistency whether board->private_data needs to be checked for a NULL or not.

If Dan is correct then it is better to drop the NULL check, not only here but in a few more places as well. There are at least 10 functions were there is no NULL check for private_data.

Run this command and you'll see what I mean
git grep -3 -e '->private_data' -- drivers/staging/gpib/agilent_82357a

Quoted 4 lines

regards,
dan carpenter

#4 lore raw
Quoted 15 lines · Kees Bakker

Op 20-11-2024 om 18:04 schreef Dan Carpenter:

Quoted 11 lines · Paolo Perego
Quoted 8 lines

This commit fixes a dereference before null check issue discovered by Coverity (CID 1601566).

The check ad line 1450 suggests that a_priv can be NULL, however it has been derefenced before, in the interface_to_usbdev() call.

---

You need a Fixes tag. But I'm pretty sure the correct fix is to remove the NULL check.

In the whole agilent_82357a.c module there is no consistency whether board->private_data needs to be checked for a NULL or not.

Quoted 7 lines

If Dan is correct then it is better to drop the NULL check, not only here but in a few more places as well. There are at least 10 functions were there is no NULL check for private_data.

Run this command and you'll see what I mean
git grep -3 -e '->private_data' -- drivers/staging/gpib/agilent_82357a

I had looked at similar issue in a different driver:
https://lore.kernel.org/all/[email protected]/

Here the NULL check we are discussing is the same thing. The private data is allocated in attach() and freed in detach(). The detach has no need to check for NULL because we can't detach something which isn't attached.

The other NULL checks are in agilent_82357a_driver_disconnect(), agilent_82357a_driver_suspend() and agilent_82357a_driver_resume(). And there the NULL checks are required because it could happen when the driver isn't attached.

I also did a quick glance through to see if any of the functions which didn't check for NULL should get a NULL check but they all seemed okay because either the board was attached or the caller had a NULL check.

So I think we can just remove this one NULL check and everything else makes sense.

regards,
dan carpenter

#5 lore raw
Quoted 31 lines · Dan Carpenter
Quoted 15 lines · Kees Bakker

Op 20-11-2024 om 18:04 schreef Dan Carpenter:

Quoted 11 lines · Paolo Perego
Quoted 8 lines

This commit fixes a dereference before null check issue discovered by Coverity (CID 1601566).

The check ad line 1450 suggests that a_priv can be NULL, however it has been derefenced before, in the interface_to_usbdev() call.

---

You need a Fixes tag. But I'm pretty sure the correct fix is to remove the NULL check.

In the whole agilent_82357a.c module there is no consistency whether board->private_data needs to be checked for a NULL or not.

Quoted 7 lines

If Dan is correct then it is better to drop the NULL check, not only here but in a few more places as well. There are at least 10 functions were there is no NULL check for private_data.

Run this command and you'll see what I mean
git grep -3 -e '->private_data' -- drivers/staging/gpib/agilent_82357a

I had looked at similar issue in a different driver:
https://lore.kernel.org/all/[email protected]/

Here the NULL check we are discussing is the same thing. The private data is allocated in attach() and freed in detach(). The detach has no need to check for NULL because we can't detach something which isn't attached.

Quoted 9 lines

The other NULL checks are in agilent_82357a_driver_disconnect(), agilent_82357a_driver_suspend() and agilent_82357a_driver_resume(). And there the NULL checks are required because it could happen when the driver isn't attached.

I also did a quick glance through to see if any of the functions which didn't check for NULL should get a NULL check but they all seemed okay because either the board was attached or the caller had a NULL check.

Hi all and thanks for the fruitful discussion.

Quoted 2 lines

So I think we can just remove this one NULL check and everything else makes sense.

Please, apologise if I'm too newbie here to understand next step on my own. Am I asked to do something, to submit a V2 with the correct Tag or the patch is good as is?

( No pressure to be accepted, it's just my willing to understand and go into the process :-) )

Thanks
Paolo

Signature · 3 lines
(*_  Paolo Perego                           @thesp0nge
//\  Software security engineer               suse.com
V_/_ 0A1A 2003 9AE0 B09C 51A4 7ACD FC0D CEA6 0806 294B
#6 lore raw
Quoted 44 lines · Paolo Perego
Quoted 31 lines · Dan Carpenter
Quoted 15 lines · Kees Bakker

Op 20-11-2024 om 18:04 schreef Dan Carpenter:

Quoted 11 lines · Paolo Perego
Quoted 8 lines

This commit fixes a dereference before null check issue discovered by Coverity (CID 1601566).

The check ad line 1450 suggests that a_priv can be NULL, however it has been derefenced before, in the interface_to_usbdev() call.

---

You need a Fixes tag. But I'm pretty sure the correct fix is to remove the NULL check.

In the whole agilent_82357a.c module there is no consistency whether board->private_data needs to be checked for a NULL or not.

Quoted 7 lines

If Dan is correct then it is better to drop the NULL check, not only here but in a few more places as well. There are at least 10 functions were there is no NULL check for private_data.

Run this command and you'll see what I mean
git grep -3 -e '->private_data' -- drivers/staging/gpib/agilent_82357a

I had looked at similar issue in a different driver:
https://lore.kernel.org/all/[email protected]/

Here the NULL check we are discussing is the same thing. The private data is allocated in attach() and freed in detach(). The detach has no need to check for NULL because we can't detach something which isn't attached.

Quoted 9 lines

The other NULL checks are in agilent_82357a_driver_disconnect(), agilent_82357a_driver_suspend() and agilent_82357a_driver_resume(). And there the NULL checks are required because it could happen when the driver isn't attached.

I also did a quick glance through to see if any of the functions which didn't check for NULL should get a NULL check but they all seemed okay because either the board was attached or the caller had a NULL check.

Hi all and thanks for the fruitful discussion.

Quoted 9 lines
Quoted 2 lines

So I think we can just remove this one NULL check and everything else makes sense.

Please, apologise if I'm too newbie here to understand next step on my own. Am I asked to do something, to submit a V2 with the correct Tag or the patch is good as is?

( No pressure to be accepted, it's just my willing to understand and go into the process :-) )

Please send a v2 which deletes the NULL check.

regards,
dan carpenter