Skip to content

Commit 1262962

Browse files
lostjeffleaxboe
authored andcommitted
block: disallow Persistent Reservation on partitions
Refuse Persistent Reservation operations on partitions as reservation on partitions doesn't make sense. Besides, introduce blkdev_pr_allowed() helper, where more policies could be placed here later. Signed-off-by: Jingbo Xu <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent c576c4b commit 1262962

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

block/ioctl.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,25 @@ int blkdev_compat_ptr_ioctl(struct block_device *bdev, blk_mode_t mode,
254254
EXPORT_SYMBOL(blkdev_compat_ptr_ioctl);
255255
#endif
256256

257+
static bool blkdev_pr_allowed(struct block_device *bdev)
258+
{
259+
/* no sense to make reservations for partitions */
260+
if (bdev_is_partition(bdev))
261+
return false;
262+
263+
if (capable(CAP_SYS_ADMIN))
264+
return true;
265+
266+
return false;
267+
}
268+
257269
static int blkdev_pr_register(struct block_device *bdev,
258270
struct pr_registration __user *arg)
259271
{
260272
const struct pr_ops *ops = bdev->bd_disk->fops->pr_ops;
261273
struct pr_registration reg;
262274

263-
if (!capable(CAP_SYS_ADMIN))
275+
if (!blkdev_pr_allowed(bdev))
264276
return -EPERM;
265277
if (!ops || !ops->pr_register)
266278
return -EOPNOTSUPP;
@@ -278,7 +290,7 @@ static int blkdev_pr_reserve(struct block_device *bdev,
278290
const struct pr_ops *ops = bdev->bd_disk->fops->pr_ops;
279291
struct pr_reservation rsv;
280292

281-
if (!capable(CAP_SYS_ADMIN))
293+
if (!blkdev_pr_allowed(bdev))
282294
return -EPERM;
283295
if (!ops || !ops->pr_reserve)
284296
return -EOPNOTSUPP;
@@ -296,7 +308,7 @@ static int blkdev_pr_release(struct block_device *bdev,
296308
const struct pr_ops *ops = bdev->bd_disk->fops->pr_ops;
297309
struct pr_reservation rsv;
298310

299-
if (!capable(CAP_SYS_ADMIN))
311+
if (!blkdev_pr_allowed(bdev))
300312
return -EPERM;
301313
if (!ops || !ops->pr_release)
302314
return -EOPNOTSUPP;
@@ -314,7 +326,7 @@ static int blkdev_pr_preempt(struct block_device *bdev,
314326
const struct pr_ops *ops = bdev->bd_disk->fops->pr_ops;
315327
struct pr_preempt p;
316328

317-
if (!capable(CAP_SYS_ADMIN))
329+
if (!blkdev_pr_allowed(bdev))
318330
return -EPERM;
319331
if (!ops || !ops->pr_preempt)
320332
return -EOPNOTSUPP;
@@ -332,7 +344,7 @@ static int blkdev_pr_clear(struct block_device *bdev,
332344
const struct pr_ops *ops = bdev->bd_disk->fops->pr_ops;
333345
struct pr_clear c;
334346

335-
if (!capable(CAP_SYS_ADMIN))
347+
if (!blkdev_pr_allowed(bdev))
336348
return -EPERM;
337349
if (!ops || !ops->pr_clear)
338350
return -EOPNOTSUPP;

0 commit comments

Comments
 (0)