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

* Re: [BUG] loop: missing BLK_OPEN_WRITE check on LOOP_SET_STATUS in lo_compat_ioctl()
  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
  1 sibling, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2026-10-19 19:13 UTC (permalink / raw)
  To: Dominik Maier; +Cc: linux-block, dmnk+artist


On Mon, 19 Oct 2026 03:16:31 -0700, Dominik Maier wrote:
> 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().
> 
> [...]

Applied, thanks!

[1/1] loop: missing BLK_OPEN_WRITE check on LOOP_SET_STATUS in lo_compat_ioctl()
      commit: d1be9e57baf20bf25a3fe6acb05fa9e9f85b2f16

Best regards,
-- 
Jens Axboe




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

* Re: [BUG] loop: missing BLK_OPEN_WRITE check on LOOP_SET_STATUS in lo_compat_ioctl()
  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
  1 sibling, 1 reply; 4+ messages in thread
From: Bart Van Assche @ 2026-10-19 19:23 UTC (permalink / raw)
  To: Dominik Maier, Jens Axboe; +Cc: linux-block, dmnk+artist

On 10/19/26 3:16 AM, Dominik Maier wrote:
> Fixes: 604f275f9670 ("loop:Check for read-write open mode before
> setting status")
> Assisted-by: ARTIST LLM

I can't find commit ID 604f275f9670 anywhere. Additionally, I can't find
any commit with the subject "loop:Check for read-write open mode before
setting status". Did I perhaps overlook something?

Linux kernel patches must be signed. I don't see a Signed-off-by tag?

Thanks,

Bart.

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

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

On 10/19/26 1:23 PM, Bart Van Assche wrote:
> On 10/19/26 3:16 AM, Dominik Maier wrote:
>> Fixes: 604f275f9670 ("loop:Check for read-write open mode before
>> setting status")
>> Assisted-by: ARTIST LLM
> 
> I can't find commit ID 604f275f9670 anywhere. Additionally, I can't find
> any commit with the subject "loop:Check for read-write open mode before
> setting status". Did I perhaps overlook something?
> 
> Linux kernel patches must be signed. I don't see a Signed-off-by tag?

Agree, all of these seem broken, sha as well as title, and no SOB.
On top of that, [BUG] is also wrong, and the patch was mangled
and I even had to hand apply it. Fix looks good though - Dominik,
please check how to generate and email patches and resend it, I'll
drop this one.

-- 
Jens Axboe


^ permalink raw reply	[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