Linux block layer
 help / color / mirror / Atom feed
* [BUG] loop: missing BLK_OPEN_WRITE check on LOOP_SET_STATUS in lo_compat_ioctl()
@ 2026-10-19 10:16 Dominik Maier
  2026-10-19 19:13 ` Jens Axboe
  2026-10-19 19:23 ` Bart Van Assche
  0 siblings, 2 replies; 4+ messages in thread
From: Dominik Maier @ 2026-10-19 10:16 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block, dmnk+artist

In Linux 7.3.0 (commit c03c1a14507d), 32-bit lo_compat_ioctl() in
drivers/block/loop.c (line 1708) dispatches LOOP_SET_STATUS directly to
loop_set_status_compat() without checking whether the caller opened the
loop device for writing or holds CAP_SYS_ADMIN.

In 64-bit lo_ioctl(), commit 604f275f9670 ("loop:Check for read-write
open mode before setting status") added a check requiring
(mode & BLK_OPEN_WRITE) || capable(CAP_SYS_ADMIN) before allowing
LOOP_SET_STATUS or LOOP_SET_STATUS64, but the corresponding check was
omitted from lo_compat_ioctl().

On kernels built with CONFIG_BLK_DEV_LOOP=y/m and CONFIG_COMPAT=y, an
unprivileged local process holding a read-only (O_RDONLY) file
descriptor to an active /dev/loopN device can issue a 32-bit 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.

We reproduced this in QEMU by configuring /dev/loop0 with
lo_sizelimit = 4096, opening /dev/loop0 with O_RDONLY, dropping
privileges to UID 1000, and invoking the 32-bit compat ioctl syscall
(int 0x80) with LOOP_SET_STATUS to shift lo_offset to 4096 and reset
lo_sizelimit to 0. The reproducer is available upon request.

Below is a proposed fix (also tested in QEMU) that enforces the same
(mode & BLK_OPEN_WRITE) || capable(CAP_SYS_ADMIN) check in
lo_compat_ioctl().

Fixes: 604f275f9670 ("loop:Check for read-write open mode before
setting status")
Assisted-by: ARTIST LLM
---
 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 6fb4234ab0e7..43dc7ab3d2aa 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,

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

end of thread, other threads:[~2026-10-19 19:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-19 10:16 [BUG] loop: missing BLK_OPEN_WRITE check on LOOP_SET_STATUS in lo_compat_ioctl() Dominik Maier
2026-10-19 19:13 ` Jens Axboe
2026-10-19 19:23 ` Bart Van Assche
2026-10-19 19:26   ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox