Commit b125130b authored by Li Zefan's avatar Li Zefan Committed by Ingo Molnar

blktrace: avoid accessing NULL bdev->bd_disk

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: default avatarLi Zefan <lizf@cn.fujitsu.com>
Acked-by: default avatarFrederic Weisbecker <fweisbec@gmail.com>
Acked-by: default avatarArnaldo 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: default avatarIngo Molnar <mingo@elte.hu>
parent cd649b8b
...@@ -1362,6 +1362,14 @@ static int blk_str2act_mask(const char *str) ...@@ -1362,6 +1362,14 @@ static int blk_str2act_mask(const char *str)
return mask; 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, static ssize_t sysfs_blk_trace_attr_show(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
char *buf) char *buf)
...@@ -1376,9 +1384,10 @@ static ssize_t sysfs_blk_trace_attr_show(struct device *dev, ...@@ -1376,9 +1384,10 @@ static ssize_t sysfs_blk_trace_attr_show(struct device *dev,
if (bdev == NULL) if (bdev == NULL)
goto out_unlock_kernel; goto out_unlock_kernel;
q = bdev_get_queue(bdev); q = blk_trace_get_queue(bdev);
if (q == NULL) if (q == NULL)
goto out_bdput; goto out_bdput;
mutex_lock(&bdev->bd_mutex); mutex_lock(&bdev->bd_mutex);
if (attr == &dev_attr_enable) { if (attr == &dev_attr_enable) {
...@@ -1435,7 +1444,7 @@ static ssize_t sysfs_blk_trace_attr_store(struct device *dev, ...@@ -1435,7 +1444,7 @@ static ssize_t sysfs_blk_trace_attr_store(struct device *dev,
if (bdev == NULL) if (bdev == NULL)
goto out_unlock_kernel; goto out_unlock_kernel;
q = bdev_get_queue(bdev); q = blk_trace_get_queue(bdev);
if (q == NULL) if (q == NULL)
goto out_bdput; goto out_bdput;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment