All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] allow blk-zoned ioctls without CAP_SYS_ADMIN
@ 2021-06-01  8:39 Niklas Cassel
  2021-06-01  8:39 ` [PATCH v2 2/2] blk-zoned: allow BLKREPORTZONE " Niklas Cassel
  2021-06-01  8:39 ` [PATCH v2 1/2] blk-zoned: allow zone management send operations " Niklas Cassel
  0 siblings, 2 replies; 3+ messages in thread
From: Niklas Cassel @ 2021-06-01  8:39 UTC (permalink / raw)
  To: Jens Axboe, Shaun Tancheff, Hannes Reinecke, Damien Le Moal,
	Martin K. Petersen
  Cc: Damien Le Moal, Niklas Cassel, Jens Axboe, linux-block, linux-kernel

From: Niklas Cassel <niklas.cassel@wdc.com>

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

These ioctls instead only requires that the corresponding R/W access
control flag to be successfully set on the opened file descriptor.

(open()/openat() will fail with -EPERM if you try to open a file with
flags that you lack permission for.)

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 | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

-- 
2.31.1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2 1/2] blk-zoned: allow zone management send operations without CAP_SYS_ADMIN
  2021-06-01  8:39 [PATCH v2 0/2] allow blk-zoned ioctls without CAP_SYS_ADMIN Niklas Cassel
  2021-06-01  8:39 ` [PATCH v2 2/2] blk-zoned: allow BLKREPORTZONE " Niklas Cassel
@ 2021-06-01  8:39 ` Niklas Cassel
  1 sibling, 0 replies; 3+ messages in thread
From: Niklas Cassel @ 2021-06-01  8:39 UTC (permalink / raw)
  To: Jens Axboe, Martin K. Petersen, Damien Le Moal, Hannes Reinecke,
	Shaun Tancheff
  Cc: Damien Le Moal, Niklas Cassel, stable, Jens Axboe, linux-block,
	linux-kernel

From: Niklas Cassel <niklas.cassel@wdc.com>

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 <niklas.cassel@wdc.com>
Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com>
Cc: stable@vger.kernel.org # v4.10+
---
Changes since v1:
- Pick up tag from Damien.
- Add fixes tag and CC stable.

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 250cb76ee615..0789e6e9f7db 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -349,9 +349,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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v2 2/2] blk-zoned: allow BLKREPORTZONE without CAP_SYS_ADMIN
  2021-06-01  8:39 [PATCH v2 0/2] allow blk-zoned ioctls without CAP_SYS_ADMIN Niklas Cassel
@ 2021-06-01  8:39 ` Niklas Cassel
  2021-06-01  8:39 ` [PATCH v2 1/2] blk-zoned: allow zone management send operations " Niklas Cassel
  1 sibling, 0 replies; 3+ messages in thread
From: Niklas Cassel @ 2021-06-01  8:39 UTC (permalink / raw)
  To: Jens Axboe, Damien Le Moal, Shaun Tancheff, Martin K. Petersen,
	Hannes Reinecke
  Cc: Damien Le Moal, Niklas Cassel, stable, Jens Axboe, linux-block,
	linux-kernel

From: Niklas Cassel <niklas.cassel@wdc.com>

Performing a BLKREPORTZONE operation should be allowed under the same
permissions as read(). (read() does not require CAP_SYS_ADMIN).

Remove the CAP_SYS_ADMIN requirement, and instead check that the fd was
successfully opened with FMODE_READ. This way BLKREPORTZONE will match
the access control requirement of read().

Fixes: 3ed05a987e0f ("blk-zoned: implement ioctls")
Signed-off-by: Niklas Cassel <niklas.cassel@wdc.com>
Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com>
Cc: stable@vger.kernel.org # v4.10+
---
Changes since v1:
- Pick up tag from Damien.
- Add fixes tag and CC stable.

 block/blk-zoned.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 0789e6e9f7db..e05fe8dbb06d 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -288,8 +288,8 @@ 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 (!(mode & FMODE_READ))
+		return -EBADF;
 
 	if (copy_from_user(&rep, argp, sizeof(struct blk_zone_report)))
 		return -EFAULT;
-- 
2.31.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-06-01  8:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-01  8:39 [PATCH v2 0/2] allow blk-zoned ioctls without CAP_SYS_ADMIN Niklas Cassel
2021-06-01  8:39 ` [PATCH v2 2/2] blk-zoned: allow BLKREPORTZONE " Niklas Cassel
2021-06-01  8:39 ` [PATCH v2 1/2] blk-zoned: allow zone management send operations " Niklas Cassel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.