Linux block layer
 help / color / mirror / Atom feed
From: Dominik Maier <dmnk@google.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, dmnk+artist@google.com,
	 Dominik Maier <dmnk@google.com>
Subject: [PATCH] loop: check for read-write open mode on LOOP_SET_STATUS in lo_compat_ioctl()
Date: Fri, 23 Oct 2026 01:21:14 +0200	[thread overview]
Message-ID: <20261022232114.2535802-1-dmnk@google.com> (raw)

In 64-bit lo_ioctl(), commit 7035b5df3c07 ("loop: cleanup set_status
interface") added a check requiring (mode & FMODE_WRITE) ||
capable(CAP_SYS_ADMIN) (now BLK_OPEN_WRITE) before allowing
LOOP_SET_STATUS or LOOP_SET_STATUS64, but the corresponding check was
omitted from 32-bit lo_compat_ioctl().

As a result, on kernels with CONFIG_COMPAT=y, an unprivileged 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.

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

Fixes: 7035b5df3c07 ("loop: cleanup set_status interface")
Assisted-by: ARTIST LLM
Signed-off-by: Dominik Maier <dmnk@google.com>
---
 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.218.g1ec904b173-goog


             reply	other threads:[~2026-10-22 23:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-22 23:21 Dominik Maier [this message]
2026-10-22 23:36 ` [PATCH] loop: check for read-write open mode on LOOP_SET_STATUS in lo_compat_ioctl() Bart Van Assche

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261022232114.2535802-1-dmnk@google.com \
    --to=dmnk@google.com \
    --cc=axboe@kernel.dk \
    --cc=dmnk+artist@google.com \
    --cc=linux-block@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox