linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: bugzilla-daemon@bugzilla.kernel.org
To: linux-scsi@vger.kernel.org
Subject: [Bug 101891] mvsas prep failed, NULL pointer dereference in mvs_slot_task_free+0x5/0x1f0 [mvsas]
Date: Tue, 18 Aug 2015 14:54:28 +0000	[thread overview]
Message-ID: <bug-101891-11613-HmXHzyE99A@https.bugzilla.kernel.org/> (raw)
In-Reply-To: <bug-101891-11613@https.bugzilla.kernel.org/>

https://bugzilla.kernel.org/show_bug.cgi?id=101891

--- Comment #4 from Dāvis <davispuh@gmail.com> ---
(In reply to Dāvis from comment #3)
> I narrowed it down to this section of mvs_abort_task function
> (drivers/scsi/mvsas/mv_sas.c)
> 
> 	} else if (task->task_proto & SAS_PROTOCOL_SATA ||
> 		task->task_proto & SAS_PROTOCOL_STP) {
> 		if (SAS_SATA_DEV == dev->dev_type) {
> 			struct mvs_slot_info *slot = task->lldd_task;
> 			u32 slot_idx = (u32)(slot - mvi->slot_info);
> 			mv_dprintk("mvs_abort_task() mvi=%p task=%p "
> 				   "slot=%p slot_idx=x%x\n",
> 				   mvi, task, slot, slot_idx);
> 			task->task_state_flags |= SAS_TASK_STATE_ABORTED;
> 			mvs_slot_task_free(mvi, task, slot, slot_idx);
> 			rc = TMF_RESP_FUNC_COMPLETE;
> 			goto out;
> 		}
> 
> 	}
> 
> 
> Basically this line "u32 slot_idx = (u32)(slot - mvi->slot_info)".
> I think (slot - mvi->slot_info) returns 0x10 and that's why
> (there's no "mvs_abort_task()" in journal so it crashes before that.
> 

Sorry for being idiot, that line doesn't cause any pointer
dereference and neither does previous line. It's just so obvious,
compiler reordered instructions so that mvs_slot_task_free is executed
before mv_dprintk is called and that's why it's not in journal.
Even as title I wrote NULL pointer dereference in mvs_slot_task_free
and that's exactly where had to look.

So anyway when in mvs_task_prep and if pci_pool_alloc fails then
task->lldd_task is NULL as can see

    task->lldd_task = NULL;
    slot->n_elem = n_elem;
    slot->slot_tag = tag;

    slot->buf = pci_pool_alloc(mvi->dma_pool, GFP_ATOMIC, &slot->buf_dma);
    if (!slot->buf)
        goto err_out_tag;

then later it's aborted with mvs_abort_task and there mvs_slot_task_free
is called with (slot = task->lldd_task) which is NULL and in
mvs_slot_task_free
{
    if (!slot->task)
        return;

happens this NULL pointer dereference because slot is NULL.

There's 2 ways to fix this, either check if slot is NULL before calling 
mvs_slot_task_free or just inside it check it.

I went for second option as it seems easier and won't have to always
check before calling.

Here's a patch, haven't tested it yet but I think it will fix this
and it's compiling right now so I'll let know once I'll have tested it.

diff --git a/drivers/scsi/mvsas/mv_sas.c b/drivers/scsi/mvsas/mv_sas.c
index 454536c..9c78074 100644
--- a/drivers/scsi/mvsas/mv_sas.c
+++ b/drivers/scsi/mvsas/mv_sas.c
@@ -887,6 +887,8 @@ static void mvs_slot_free(struct mvs_info *mvi, u32
rx_desc)
 static void mvs_slot_task_free(struct mvs_info *mvi, struct sas_task *task,
                          struct mvs_slot_info *slot, u32 slot_idx)
 {
+       if (!slot)
+               return;
        if (!slot->task)
                return;
        if (!sas_protocol_ata(task->task_proto))

-- 
You are receiving this mail because:
You are watching the assignee of the bug.--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2015-08-18 14:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-23 21:34 [Bug 101891] New: mvsas prep failed, NULL pointer dereference in mvs_slot_task_free+0x5/0x1f0 [mvsas] bugzilla-daemon
2015-07-23 22:01 ` [Bug 101891] " bugzilla-daemon
2015-07-24 11:48 ` bugzilla-daemon
2015-08-16 22:14 ` bugzilla-daemon
2015-08-18 14:54 ` bugzilla-daemon [this message]
2015-08-19 22:09 ` bugzilla-daemon
2015-08-20  7:55 ` bugzilla-daemon
2015-08-20 13:45 ` bugzilla-daemon
2016-02-05 16:45 ` bugzilla-daemon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-101891-11613-HmXHzyE99A@https.bugzilla.kernel.org/ \
    --to=bugzilla-daemon@bugzilla.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).