From: Kevin Vigor <kevin@vigor.nu>
To: Martin Schwidefsky <schwidefsky@de.ibm.com>,
Heiko Carstens <heiko.carstens@de.ibm.com>,
Jens Axboe <axboe@kernel.dk>
Cc: linux-kernel@vger.kernel.org, kevin@vigor.nu
Subject: PATCH: dangling pointer when switching to noop elevator in obscure block drivers.
Date: Fri, 20 Aug 2010 15:25:10 -0600 [thread overview]
Message-ID: <20100820212510.GB29022@jimi.int.fusionio.com> (raw)
Linux 2.6.35 introduced a test in the beginning of elevator_init(), like
so:
if (unlikely(q->elevator))
return 0;
So the following code sequence, which appears in two (obscure) block
drivers is now a serious error:
elevator_exit(q);
elevator_init(q, "noop");
The intent is to cleanup the default system elevator and replace it with
the noop elevator. Instead, elevator_exit() frees the existing elevator
object, but leaves q->elevator pointing to it; elevator_init() then
silently fails since q->elevator is non-NULL, and the queue is left with
the elevator pointer invalid, This leads to untold woe and segfaults
later.
The fix is trivial: zero the q->elevator pointer before calling
elevator_init(). Note that drivers/s390/block/dasd.c already follows
this pattern.
I do not have the hardware to actually test either of the two afflicted
drivers, but I believe the fix to be sufficiently obvious. The following
patches are against the current version of Linus' tree.
Signed-off-by: Kevin Vigor <kevin@vigor.nu>
Thanks,
Kevin Vigor
diff --git a/drivers/s390/char/tape_block.c b/drivers/s390/char/tape_block.c
index b7de025..a1028c9 100644
--- a/drivers/s390/char/tape_block.c
+++ b/drivers/s390/char/tape_block.c
@@ -218,6 +218,7 @@ tapeblock_setup_device(struct tape_device * device)
return -ENOMEM;
elevator_exit(blkdat->request_queue->elevator);
+ blkdat->request_queue->elevator = NULL;
rc = elevator_init(blkdat->request_queue, "noop");
if (rc)
goto cleanup_queue;
diff --git a/drivers/block/mg_disk.c b/drivers/block/mg_disk.c
index b82c5ce..c553404 100644
--- a/drivers/block/mg_disk.c
+++ b/drivers/block/mg_disk.c
@@ -975,6 +975,7 @@ static int mg_probe(struct platform_device *plat_dev)
/* mflash is random device, thanx for the noop */
elevator_exit(host->breq->elevator);
+ host->breq->elevator = NULL;
err = elevator_init(host->breq, "noop");
if (err) {
printk(KERN_ERR "%s:%d (elevator_init) fail\n",
next reply other threads:[~2010-08-20 21:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-20 21:25 Kevin Vigor [this message]
2010-08-23 10:11 ` Jens Axboe
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=20100820212510.GB29022@jimi.int.fusionio.com \
--to=kevin@vigor.nu \
--cc=axboe@kernel.dk \
--cc=heiko.carstens@de.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=schwidefsky@de.ibm.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®