Skip to contentSkip to conversation

mvsas:Fix possible NULL pointer deference in mvs_dev_found_notify

PATCH Dāvis Mosāns 2 participants 2 messages Mar 9, 2016 – Mar 10, 2016 1 message not in the archive SCSI

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive

2016-03-09 15:58 GMT+02:00 Nicholas Krause <[email protected]>:

Quoted 27 lines

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.

---
 drivers/scsi/mvsas/mv_sas.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/scsi/mvsas/mv_sas.c +4 -1
index 83cd3ea..7afb248 100644
@@ -1191,6 +1191,10 @@ int mvs_dev_found_notify(struct domain_device *dev, int lock)
        struct mvs_device *mvi_device;
 
        mvi = mvs_find_dev_mvi(dev);
+       if (!mvi) {
+               res = -1;
+               goto found_out;
+       }
 
        if (lock)
                spin_lock_irqsave(&mvi->lock, flags);
--
Quoted 2 lines

2.5.0

It doesn't look right,
if mvi will be NULL and lock will be set then at

found_out:

    if (lock)
        spin_unlock_irqrestore(&mvi->lock, flags);

there will be mvi dereference, besides spin_lock_irqsave wasn't even called. And without this patch dereference would happen on mvi->lock which is before use in mvs_alloc_dev

About whether mvs_find_dev_mvi can return NULL it looks like it's possible, but I'm not sure if it practically happens. I guess it did hence patch.

#2 lore raw
Quoted 2 lines · DÄ�vis MosÄ�ns

About whether mvs_find_dev_mvi can return NULL it looks like it's possible, but I'm not sure if it practically happens. I guess it did hence patch.

Or the "bug" was found by incorrect code inspection. Nick has a history of submitting patches that are for either non-existent problems or don't deal with with the issue correctly - bad enough that he's not allowed to post to the linux-kernel list.