All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] loop: check for read-write open mode on LOOP_SET_STATUS in lo_compat_ioctl()
@ 2026-10-25 20:07 Dominik Maier
  2026-10-26 17:40 ` Bart Van Assche
  2026-10-27  2:35 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Dominik Maier @ 2026-10-25 20:07 UTC (permalink / raw)
  To: Jens Axboe; +Cc: Bart Van Assche, linux-block, dmnk+artist, Dominik Maier

lo_ioctl() checks for (mode & BLK_OPEN_WRITE) || capable(CAP_SYS_ADMIN)
before allowing LOOP_SET_STATUS or LOOP_SET_STATUS64, but not
lo_compat_ioctl(), the handler used by 32-bit user space on 64-bit
kernels.

As a result, on 64-bit kernels with CONFIG_COMPAT=y, a 32-bit
unprivileged user-space process holding a read-only (O_RDONLY) file
descriptor to an active /dev/loopN device can issue a compat
LOOP_SET_STATUS ioctl to modify lo_offset, clear lo_sizelimit to 0
(exposing backing-file data past the configured limit), or alter
lo_flags.

Enforce the same (mode & BLK_OPEN_WRITE) || capable(CAP_SYS_ADMIN) check
on LOOP_SET_STATUS in lo_compat_ioctl().

Assisted-by: ARTIST LLM
Signed-off-by: Dominik Maier <dmnk@google.com>
---
v2:
  - Rephrase commit description of lo_compat_ioctl() and remove
    inaccurate Fixes tag per Bart Van Assche.

 drivers/block/loop.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 758c20678bf6..f15a5cae5c63 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -1708,8 +1708,10 @@ static int lo_compat_ioctl(struct block_device *bdev, blk_mode_t mode,
 
 	switch(cmd) {
 	case LOOP_SET_STATUS:
-		err = loop_set_status_compat(lo,
-			     (const struct compat_loop_info __user *)arg);
+		err = -EPERM;
+		if ((mode & BLK_OPEN_WRITE) || capable(CAP_SYS_ADMIN))
+			err = loop_set_status_compat(lo,
+				(const struct compat_loop_info __user *)arg);
 		break;
 	case LOOP_GET_STATUS:
 		err = loop_get_status_compat(lo,
-- 
2.56.0.257.gf7497c7d27-goog

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

* Re: [PATCH v2] loop: check for read-write open mode on LOOP_SET_STATUS in lo_compat_ioctl()
  2026-10-25 20:07 [PATCH v2] loop: check for read-write open mode on LOOP_SET_STATUS in lo_compat_ioctl() Dominik Maier
@ 2026-10-26 17:40 ` Bart Van Assche
  2026-10-27  2:35 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Bart Van Assche @ 2026-10-26 17:40 UTC (permalink / raw)
  To: Dominik Maier, Jens Axboe; +Cc: linux-block, dmnk+artist

On 10/25/26 1:07 PM, Dominik Maier wrote:
> Assisted-by: ARTIST LLM
> Signed-off-by: Dominik Maier <dmnk@google.com>
Since this is a permission bypass, please add

Cc: stable@vger.kernel.org.

Anyway:

Reviewed-by: Bart Van Assche bvanassche@acm.org

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

* Re: [PATCH v2] loop: check for read-write open mode on LOOP_SET_STATUS in lo_compat_ioctl()
  2026-10-25 20:07 [PATCH v2] loop: check for read-write open mode on LOOP_SET_STATUS in lo_compat_ioctl() Dominik Maier
  2026-10-26 17:40 ` Bart Van Assche
@ 2026-10-27  2:35 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2026-10-27  2:35 UTC (permalink / raw)
  To: Dominik Maier; +Cc: Bart Van Assche, linux-block, dmnk+artist


On Sun, 25 Oct 2026 21:07:40 +0100, Dominik Maier wrote:
> lo_ioctl() checks for (mode & BLK_OPEN_WRITE) || capable(CAP_SYS_ADMIN)
> before allowing LOOP_SET_STATUS or LOOP_SET_STATUS64, but not
> lo_compat_ioctl(), the handler used by 32-bit user space on 64-bit
> kernels.
> 
> As a result, on 64-bit kernels with CONFIG_COMPAT=y, a 32-bit
> unprivileged user-space process holding a read-only (O_RDONLY) file
> descriptor to an active /dev/loopN device can issue a compat
> LOOP_SET_STATUS ioctl to modify lo_offset, clear lo_sizelimit to 0
> (exposing backing-file data past the configured limit), or alter
> lo_flags.
> 
> [...]

Applied, thanks!

[1/1] loop: check for read-write open mode on LOOP_SET_STATUS in lo_compat_ioctl()
      commit: 87409eedc543d288cdd49c2174f7d61eca7b8db5

Best regards,
-- 
Jens Axboe




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

end of thread, other threads:[~2026-10-27  2:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-25 20:07 [PATCH v2] loop: check for read-write open mode on LOOP_SET_STATUS in lo_compat_ioctl() Dominik Maier
2026-10-26 17:40 ` Bart Van Assche
2026-10-27  2:35 ` Jens Axboe

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.