# \[PATCH v5 0/2\] allow blk-zoned ioctls without CAP\_SYS\_ADMIN

- Subsystems: BLOCK LAYER, ZONED BLOCK DEVICE (BLOCK LAYER), THE REST
- Maintainers: Jens Axboe, Damien Le Moal, Linus Torvalds
- Series: 2 patches touching 1 file, +0/-6
- Status: LANDED
- Landed in mainline.
- Revision v5 (5 revisions archived).
- List: linux-block
- 4 messages, 2 authors
- Page: https://ratatoskr.run/linux-block/2021/08/1474776/t

## \[PATCH v5 0/2\] allow blk-zoned ioctls without CAP\_SYS\_ADMIN

- From: Niklas Cassel \<hidden\>
- Date: 2021-08-11 11:05:25 
- Message: https://ratatoskr.run/linux-block/2021/08/1474776.md

```text
From: Niklas Cassel <redacted>

Allow the following blk-zoned ioctls: BLKREPORTZONE, BLKRESETZONE,
BLKOPENZONE, BLKCLOSEZONE, and BLKFINISHZONE to be performed without
CAP_SYS_ADMIN.

Neither read() nor write() requires CAP_SYS_ADMIN, and considering
the close relationship between read()/write() and these ioctls, there
is no reason to require CAP_SYS_ADMIN for these ioctls either.

Changes since v4:
-Picked up additional Reviewed-by tags.
-Corrected Damien's email in patch 2/2.

Changes since v3:
-Picked up additional Reviewed-by tags.

Changes since v2:
-Dropped the FMODE_READ check from patch 2/2.

Changes since v1:
-Picked up tags from Damien.
-Added fixes tags.


Niklas Cassel (2):
  blk-zoned: allow zone management send operations without CAP_SYS_ADMIN
  blk-zoned: allow BLKREPORTZONE without CAP_SYS_ADMIN

 block/blk-zoned.c | 6 ------
 1 file changed, 6 deletions(-)

-- 
2.31.1
```

## \[PATCH v5 1/2\] blk-zoned: allow zone management send operations without CAP\_SYS\_ADMIN

- From: Niklas Cassel \<hidden\>
- Date: 2021-08-11 11:05:30 
- Message: https://ratatoskr.run/linux-block/2021/08/1474777.md

```text
From: Niklas Cassel <redacted>

Zone management send operations (BLKRESETZONE, BLKOPENZONE, BLKCLOSEZONE
and BLKFINISHZONE) should be allowed under the same permissions as write().
(write() does not require CAP_SYS_ADMIN).

Additionally, other ioctls like BLKSECDISCARD and BLKZEROOUT only check if
the fd was successfully opened with FMODE_WRITE.
(They do not require CAP_SYS_ADMIN).

Currently, zone management send operations require both CAP_SYS_ADMIN
and that the fd was successfully opened with FMODE_WRITE.

Remove the CAP_SYS_ADMIN requirement, so that zone management send
operations match the access control requirement of write(), BLKSECDISCARD
and BLKZEROOUT.

Fixes: 3ed05a987e0f ("blk-zoned: implement ioctls")
Signed-off-by: Niklas Cassel <redacted>
Reviewed-by: Damien Le Moal <redacted>
Reviewed-by: Aravind Ramesh <redacted>
Reviewed-by: Adam Manzanares <redacted>
Reviewed-by: Himanshu Madhani <redacted>
Reviewed-by: Johannes Thumshirn <redacted>
Cc: <redacted> # v4.10+
---
Changes since v4:
-Picked up additional Reviewed-by tag.

Note to backporter:
Function was added as blkdev_reset_zones_ioctl() in v4.10.
Function was renamed to blkdev_zone_mgmt_ioctl() in v5.5.
The patch is valid both before and after the function rename.

 block/blk-zoned.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 86fce751bb17..8a60dbeb44be 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -421,9 +421,6 @@ int blkdev_zone_mgmt_ioctl(struct block_device *bdev, fmode_t mode,
 	if (!blk_queue_is_zoned(q))
 		return -ENOTTY;
 
-	if (!capable(CAP_SYS_ADMIN))
-		return -EACCES;
-
 	if (!(mode & FMODE_WRITE))
 		return -EBADF;
 
-- 
2.31.1
```

## \[PATCH v5 2/2\] blk-zoned: allow BLKREPORTZONE without CAP\_SYS\_ADMIN

- From: Niklas Cassel \<hidden\>
- Date: 2021-08-11 11:05:38 
- Message: https://ratatoskr.run/linux-block/2021/08/1474778.md

```text
From: Niklas Cassel <redacted>

A user space process should not need the CAP_SYS_ADMIN capability set
in order to perform a BLKREPORTZONE ioctl.

Getting the zone report is required in order to get the write pointer.
Neither read() nor write() requires CAP_SYS_ADMIN, so it is reasonable
that a user space process that can read/write from/to the device, also
can get the write pointer. (Since e.g. writes have to be at the write
pointer.)

Fixes: 3ed05a987e0f ("blk-zoned: implement ioctls")
Signed-off-by: Niklas Cassel <redacted>
Reviewed-by: Damien Le Moal <redacted>
Reviewed-by: Aravind Ramesh <redacted>
Reviewed-by: Adam Manzanares <redacted>
Reviewed-by: Himanshu Madhani <redacted>
Reviewed-by: Johannes Thumshirn <redacted>
Cc: <redacted> # v4.10+
---
Changes since v4:
-Picked up additional Reviewed-by tag.
-Corrected Damien's email.

 block/blk-zoned.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 8a60dbeb44be..1d0c76c18fc5 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -360,9 +360,6 @@ int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode,
 	if (!blk_queue_is_zoned(q))
 		return -ENOTTY;
 
-	if (!capable(CAP_SYS_ADMIN))
-		return -EACCES;
-
 	if (copy_from_user(&rep, argp, sizeof(struct blk_zone_report)))
 		return -EFAULT;
 
-- 
2.31.1
```

## Re: \[PATCH v5 0/2\] allow blk-zoned ioctls without CAP\_SYS\_ADMIN

- From: Jens Axboe \<axboe@kernel.dk\>
- Date: 2021-08-24 16:13:47 
- Message: https://ratatoskr.run/linux-block/2021/08/1487246.md

```text
On 8/11/21 5:05 AM, Niklas Cassel wrote:
> From: Niklas Cassel <redacted>
> 
> Allow the following blk-zoned ioctls: BLKREPORTZONE, BLKRESETZONE,
> BLKOPENZONE, BLKCLOSEZONE, and BLKFINISHZONE to be performed without
> CAP_SYS_ADMIN.
> 
> Neither read() nor write() requires CAP_SYS_ADMIN, and considering
> the close relationship between read()/write() and these ioctls, there
> is no reason to require CAP_SYS_ADMIN for these ioctls either.

Applied, thanks.

-- 
Jens Axboe

```
