From: Zixuan Fu <r33s3n6@gmail.com>
To: kashyap.desai@broadcom.com, sumit.saxena@broadcom.com,
shivasharan.srikanteshwara@broadcom.com, jejb@linux.ibm.com,
martin.petersen@oracle.com
Cc: megaraidlinux.pdl@broadcom.com, linux-scsi@vger.kernel.org,
linux-kernel@vger.kernel.org, baijiaju1990@gmail.com,
TOTE Robot <oslab@tsinghua.edu.cn>
Subject: [BUG] scsi: megaraid_sas: possible use-after-free caused by bad error handling in megasas_probe_one()
Date: Tue, 6 Sep 2022 14:33:18 +0800 [thread overview]
Message-ID: <20220906063318.2745858-1-r33s3n6@gmail.com> (raw)
Hello,
Our fault injection tool finds a possible use-after-free in the
megaraid_sas driver in Linux 5.10.0:
In the file drivers/scsi/megaraid/megaraid_sas_base.c:
In megasas_io_attach(), the call to scsi_add_host() may fail:
6814: if (scsi_add_host(host, &instance->pdev->dev)) {
...
6818: return -ENODEV;
6819: }
This error is then propagated to its caller megasas_probe_one().
7414: if (megasas_io_attach(instance))
7415: goto fail_io_attach;
In error handling code of megasas_probe_one(), it calls scsi_host_put():
7457: scsi_host_put(host);
The function scsi_host_put() calls scsi_host_dev_release() to free `host`,
which contains a variable `instance`.
But megasas_probe_one() calls megasas_init_fw() before:
7372: if (megasas_init_fw(instance))
In megasas_init_fw(), it starts a timer:
6369: megasas_start_timer(instance);
And megasas_probe_one() does nothing about it in error handling code. When
the timer expires, it accesses `instance`, causing a use-after-free bug.
I am not quite sure how to fix this possible bug. Any feedback would be
appreciated, thanks!
Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
Best wishes,
Zixuan Fu
reply other threads:[~2022-09-06 6:33 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20220906063318.2745858-1-r33s3n6@gmail.com \
--to=r33s3n6@gmail.com \
--cc=baijiaju1990@gmail.com \
--cc=jejb@linux.ibm.com \
--cc=kashyap.desai@broadcom.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=megaraidlinux.pdl@broadcom.com \
--cc=oslab@tsinghua.edu.cn \
--cc=shivasharan.srikanteshwara@broadcom.com \
--cc=sumit.saxena@broadcom.com \
/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
all inboxes | Powered by JetHome®