[Devel] [PATCH RHEL9 COMMIT] blk-cbt: Factor out common capability check
Konstantin Khorenko
khorenko at virtuozzo.com
Wed Feb 22 20:59:46 MSK 2023
The commit is pushed to "branch-rh9-5.14.0-162.6.1.vz9.18.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh9-5.14.0-162.6.1.vz9.18.11
------>
commit f84bebd9f1ff2086e8c2dbe382ac95992c724f9c
Author: Nikolay Borisov <nikolay.borisov at virtuozzo.com>
Date: Fri Jan 27 13:34:39 2023 +0200
blk-cbt: Factor out common capability check
Instead of duplicating CAP_SYS_ADMIN check for every block-cbt ioctl
apart from BLKCBTGET simply factor out the check in the beginning of
blk_cbt_ioctl().
Fixes: ea18c5e9d2ba ("cbt: introduce changed block tracking")
Signed-off-by: Nikolay Borisov <nikolay.borisov at virtuozzo.com>
Reviewed-by: Alexander Atanasov <alexander.atanasov at virtuozzo.com>
---
block/blk-cbt.c | 26 +++++++++-----------------
1 file changed, 9 insertions(+), 17 deletions(-)
diff --git a/block/blk-cbt.c b/block/blk-cbt.c
index 702a44e216e9..a80fdeecd661 100644
--- a/block/blk-cbt.c
+++ b/block/blk-cbt.c
@@ -991,34 +991,26 @@ static int cbt_ioc_misc(struct block_device *bdev, void __user *arg)
int blk_cbt_ioctl(struct block_device *bdev, unsigned cmd, char __user *arg)
{
- struct blk_user_cbt_info __user *ucbt_ioc = (struct blk_user_cbt_info __user *) arg;
+ struct blk_user_cbt_info __user *ucbt_ioc;
+
+ ucbt_ioc = (struct blk_user_cbt_info __user *) arg;
+
+ if (cmd == BLKCBTGET)
+ return cbt_ioc_get(bdev, ucbt_ioc);
+
+ if (!capable(CAP_SYS_ADMIN))
+ return -EACCES;
switch(cmd) {
case BLKCBTSTART:
- if (!capable(CAP_SYS_ADMIN))
- return -EACCES;
return cbt_ioc_init(bdev, ucbt_ioc);
case BLKCBTSTOP:
- if (!capable(CAP_SYS_ADMIN))
- return -EACCES;
-
return cbt_ioc_stop(bdev);
- case BLKCBTGET:
- return cbt_ioc_get(bdev, ucbt_ioc);
case BLKCBTSET:
- if (!capable(CAP_SYS_ADMIN))
- return -EACCES;
-
return cbt_ioc_set(bdev, ucbt_ioc, 1);
case BLKCBTCLR:
- if (!capable(CAP_SYS_ADMIN))
- return -EACCES;
-
return cbt_ioc_set(bdev, ucbt_ioc, 0);
case BLKCBTMISC:
- if (!capable(CAP_SYS_ADMIN))
- return -EACCES;
-
return cbt_ioc_misc(bdev, arg);
default:
BUG();
More information about the Devel
mailing list