Commit da5dadb4 authored by Mike Snitzer's avatar Mike Snitzer

dm: fix dropped return code from dm_get_bdev_for_ioctl

dm_get_bdev_for_ioctl()'s return of 0 or 1 must be the result from
prepare_ioctl (1 means the ioctl was issued to a partition, 0 means it
wasn't).  Unfortunately commit 519049af ("dm: use blkdev_get rather
than bdgrab when issuing pass-through ioctl") reused the variable 'r'
to store the return from blkdev_get() that follows prepare_ioctl()
-- whereby dropping prepare_ioctl()'s result on the floor.

This can lead to an ioctl or persistent reservation being issued to a
partition going unnoticed, which implies the extra permission check for
CAP_SYS_RAWIO is skipped.

Fix this by using a different variable to store blkdev_get()'s return.

Fixes: 519049af ("dm: use blkdev_get rather than bdgrab when issuing pass-through ioctl")
Reported-by: default avatarAlasdair G Kergon <agk@redhat.com>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
parent e457edf0
...@@ -466,7 +466,7 @@ static int dm_get_bdev_for_ioctl(struct mapped_device *md, ...@@ -466,7 +466,7 @@ static int dm_get_bdev_for_ioctl(struct mapped_device *md,
{ {
struct dm_target *tgt; struct dm_target *tgt;
struct dm_table *map; struct dm_table *map;
int srcu_idx, r; int srcu_idx, r, r2;
retry: retry:
r = -ENOTTY; r = -ENOTTY;
...@@ -492,9 +492,11 @@ static int dm_get_bdev_for_ioctl(struct mapped_device *md, ...@@ -492,9 +492,11 @@ static int dm_get_bdev_for_ioctl(struct mapped_device *md,
goto out; goto out;
bdgrab(*bdev); bdgrab(*bdev);
r = blkdev_get(*bdev, *mode, _dm_claim_ptr); r2 = blkdev_get(*bdev, *mode, _dm_claim_ptr);
if (r < 0) if (r2 < 0) {
r = r2;
goto out; goto out;
}
dm_put_live_table(md, srcu_idx); dm_put_live_table(md, srcu_idx);
return r; return r;
......
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