Skip to content

Commit

Permalink
[PATCH] possible use-after-free of bio
Browse files Browse the repository at this point in the history
There is a possibility that a bio will be accessed after it has been freed
on SCSI.  It happens if you submit a bio with BIO_SYNC marked and the
auto-unplugging kicks the request_fn, SCSI re-enables interrupts in-between
so if the request completes between the add_request() in __make_request()
and the bio_sync() call, we could be looking at a dead bio.  It's a slim
race, but it has been triggered in the Real World.

So assign bio_sync() to a local variable instead.

Signed-off-by: Jens Axboe <axboe@suse.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  • Loading branch information
Jens Axboe authored and Linus Torvalds committed Apr 16, 2005
1 parent 9c340d8 commit 4a534f9
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions drivers/block/ll_rw_blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -2559,14 +2559,15 @@ EXPORT_SYMBOL(__blk_attempt_remerge);
static int __make_request(request_queue_t *q, struct bio *bio)
{
struct request *req, *freereq = NULL;
int el_ret, rw, nr_sectors, cur_nr_sectors, barrier, err;
int el_ret, rw, nr_sectors, cur_nr_sectors, barrier, err, sync;
sector_t sector;

sector = bio->bi_sector;
nr_sectors = bio_sectors(bio);
cur_nr_sectors = bio_cur_sectors(bio);

rw = bio_data_dir(bio);
sync = bio_sync(bio);

/*
* low level driver can indicate that it wants pages above a
Expand Down Expand Up @@ -2698,7 +2699,7 @@ static int __make_request(request_queue_t *q, struct bio *bio)
out:
if (freereq)
__blk_put_request(q, freereq);
if (bio_sync(bio))
if (sync)
__generic_unplug_device(q);

spin_unlock_irq(q->queue_lock);
Expand Down

0 comments on commit 4a534f9

Please sign in to comment.