Skip to contentSkip to conversation

loop: check for read-write open mode on LOOP_SET_STATUS in lo_compat_ioctl()

PATCH Applied Dominik Maier 3 participants 3 messages Oct 25 – Oct 27 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 loop: check for read-write open mode on LOOP_SET_STATUS in lo_compat_ioctl()

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

---
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(-)
drivers/block/loop.c +4 -2
index 758c20678bf6..f15a5cae5c63 100644
@@ -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,
Signature · 1 line
2.56.0.257.gf7497c7d27-goog
maintainer Applied
#2 lore raw
In reply to Dominik Maier
Quoted 5 lines · 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.

Quoted 8 lines

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,

Signature · 1 line
Jens Axboe