Skip to content

Commit

Permalink
blktrace: avoid accessing NULL bdev->bd_disk
Browse files Browse the repository at this point in the history
bdev->bd_disk can be NULL, if the block device is not opened.

Try this against an unmounted partition, and you'll see NULL dereference:

  # echo 1 > /sys/block/sda/sda5/enable

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Acked-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jens Axboe <jens.axboe@oracle.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <49C30098.6080107@cn.fujitsu.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Li Zefan authored and Ingo Molnar committed Mar 21, 2009
1 parent cd649b8 commit b125130
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions kernel/trace/blktrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,14 @@ static int blk_str2act_mask(const char *str)
return mask;
}

static struct request_queue *blk_trace_get_queue(struct block_device *bdev)
{
if (bdev->bd_disk == NULL)
return NULL;

return bdev_get_queue(bdev);
}

static ssize_t sysfs_blk_trace_attr_show(struct device *dev,
struct device_attribute *attr,
char *buf)
Expand All @@ -1376,9 +1384,10 @@ static ssize_t sysfs_blk_trace_attr_show(struct device *dev,
if (bdev == NULL)
goto out_unlock_kernel;

q = bdev_get_queue(bdev);
q = blk_trace_get_queue(bdev);
if (q == NULL)
goto out_bdput;

mutex_lock(&bdev->bd_mutex);

if (attr == &dev_attr_enable) {
Expand Down Expand Up @@ -1435,7 +1444,7 @@ static ssize_t sysfs_blk_trace_attr_store(struct device *dev,
if (bdev == NULL)
goto out_unlock_kernel;

q = bdev_get_queue(bdev);
q = blk_trace_get_queue(bdev);
if (q == NULL)
goto out_bdput;

Expand Down

0 comments on commit b125130

Please sign in to comment.