Skip to contentSkip to conversation

mvsas:Fix possible NULL pointer deference in mvs_dev_found_notify

PATCH Luis de Bethencourt 2 participants 3 messages Jul 2, 2016 – Jul 3, 2016 1 message not in the archive SCSI

lore
Share & tools
lore

Luis de Bethencourt

author Reviewed-by
#1 lore raw
In reply to a message not in the archive
Quoted 21 lines · Nicholas Krause

This adds properly checking after the call to mvs_find_dev_mvi
due to this function being able to return a NULL pointer and
if this does arise we will deference it in mvs_alloc_dev due to this function never checking if a NULL pointer is given as it's input argument. Signed-off-by: Nicholas Krause <[email protected]>
---
v3 - Make logic simpler on error path by returning -1 directly if mvs_find_dev_mvi returns NULL.
v2 - Fix NULL pointer deferenece in error path by calling spin_unlock_irqrestore on the now NULL pointer, as returned

 drivers/scsi/mvsas/mv_sas.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/scsi/mvsas/mv_sas.c +0 -0
index 5b9fcff..dffab01 100644

drivers/scsi/mvsas/mv_sas.c int mvs_dev_found_notify(struct domain_device *dev, int lock) · line 1201

Quoted 8 lines
drivers/scsi/mvsas/mv_sas.c +2 -0
@@ -1194,6 +1194,8 @@ int mvs_dev_found_notify(struct domain_device *dev, int lock)
 	struct mvs_device *mvi_device;
 
 	mvi = mvs_find_dev_mvi(dev);
+	if (!mvi)
+		return -1;
 
 	if (lock)
 		spin_lock_irqsave(&mvi->lock, flags);

This looks better :)

Checking the value of mvi makes sense if mvs_find_dev_mvi() can return NULL.

Thanks,
Luis

maintainer
#2 lore raw
Quoted 30 lines · Luis de Bethencourt
Quoted 29 lines · Nicholas Krause

This adds properly checking after the call to mvs_find_dev_mvi
due to this function being able to return a NULL pointer and
if this does arise we will deference it in mvs_alloc_dev due to this function never checking if a NULL pointer is given as it's input argument. Signed-off-by: Nicholas Krause < [email protected]>
---
v3 - Make logic simpler on error path by returning -1 directly if mvs_find_dev_mvi returns NULL.
v2 - Fix NULL pointer deferenece in error path by calling spin_unlock_irqrestore on the now NULL pointer, as returned

 drivers/scsi/mvsas/mv_sas.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/scsi/mvsas/mv_sas.c +2 -0
index 5b9fcff..dffab01 100644
@@ -1194,6 +1194,8 @@ int mvs_dev_found_notify(struct domain_device
 *dev, int lock)
 	struct mvs_device *mvi_device;
 
 	mvi = mvs_find_dev_mvi(dev);
+	if (!mvi)
+		return -1;
 
Quoted 8 lines
Quoted 3 lines
drivers/scsi/mvsas/mv_sas.c +0 -0
 	if (lock)

spin_lock_irqsave(&mvi->lock, flags);

This looks better :)

Checking the value of mvi makes sense if mvs_find_dev_mvi() can return NULL.

Which it can't, if you actually look at the function. For this to happen, we'd have to be receiving a discovery event for a non-existent port on the adapter, meaning the system was so corrupted that operation shouldn't be continuing.

Nick is a known bogus patch submitter. If you want to review them, that's your choice (and perhaps some might be useful), but it's not unreasonable of me to expect the review will be thorough enough to turn up issues like this.

James

Quoted 10 lines

Thanks,
Luis
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
Quoted 45 lines · James Bottomley
Quoted 30 lines · Luis de Bethencourt
Quoted 29 lines · Nicholas Krause

This adds properly checking after the call to mvs_find_dev_mvi
due to this function being able to return a NULL pointer and
if this does arise we will deference it in mvs_alloc_dev due to this function never checking if a NULL pointer is given as it's input argument. Signed-off-by: Nicholas Krause < [email protected]>
---
v3 - Make logic simpler on error path by returning -1 directly if mvs_find_dev_mvi returns NULL.
v2 - Fix NULL pointer deferenece in error path by calling spin_unlock_irqrestore on the now NULL pointer, as returned

 drivers/scsi/mvsas/mv_sas.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/scsi/mvsas/mv_sas.c +2 -0
index 5b9fcff..dffab01 100644
@@ -1194,6 +1194,8 @@ int mvs_dev_found_notify(struct domain_device
 *dev, int lock)
 	struct mvs_device *mvi_device;
 
 	mvi = mvs_find_dev_mvi(dev);
+	if (!mvi)
+		return -1;
 
Quoted 8 lines
Quoted 3 lines
drivers/scsi/mvsas/mv_sas.c +0 -0
 	if (lock)

spin_lock_irqsave(&mvi->lock, flags);

This looks better :)

Checking the value of mvi makes sense if mvs_find_dev_mvi() can return NULL.

Which it can't, if you actually look at the function. For this to happen, we'd have to be receiving a discovery event for a non-existent port on the adapter, meaning the system was so corrupted that operation shouldn't be continuing.

Quoted 6 lines

Nick is a known bogus patch submitter. If you want to review them, that's your choice (and perhaps some might be useful), but it's not unreasonable of me to expect the review will be thorough enough to turn up issues like this.

James

I had my suspicions about mvfs_find_dev_mvi() returning NULL. Which is why I said "if it can return NULL". Unfortunately I assumed the base of the patch was properly considered, because I didn't knew about Nick.

I just searched around and now understand what you mean about his bogus patches.

Sorry I wasn't thorough enough on my review, I know the above isn't an excuse. Lesson learned.

In a related note, why is mvi initialized to NULL in mvfs_find_dev_mvi() if it is going to be overwritten? Curious.

Thanks and apologies,
Luis

Quoted 13 lines
Quoted 12 lines

Thanks,
Luis
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html