Skip to contentSkip to conversation

ublk: clear VM_MAYWRITE on read-only ublk char device mmap

PATCH Applied Kanishka De Silva 4 participants 5 messages Aug 30 – Sep 1 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): 2026083055-isotope-broiler-88e5@gregkh

#1 lore raw

PATCH 1/1 ublk: clear VM_MAYWRITE on read-only ublk char device mmap

ublk_ch_mmap() rejects mmap requests with VM_WRITE set, but never clears VM_MAYWRITE on the resulting read-only mapping. This allows a userspace daemon to mmap the per-queue command buffer PROT_READ, then upgrade it to PROT_WRITE via mprotect(), since VM_MAYWRITE was never cleared.

The command buffer holds struct ublksrv_io_desc entries that are kernel-written ABI; a writable mapping lets an unprivileged daemon process corrupt fields such as addr, op_flags, nr_sectors, and start_sector.

Same bug class as the drm/panthor and drm/vc4 VM_MAYWRITE fixes, and the 2026-08-13 ptp/vmclock fix (a5edadbae57e).

Verified via mprotect() PoC: before the fix, a PROT_READ mapping can be upgraded to PROT_READ|PROT_WRITE and a write into the command buffer corrupts io_desc fields (confirmed under KASAN). After the fix, mprotect() returns -EACCES.

Fixes 3fee8d7599e1 ("ublk_drv: add io_uring based userspace block driver")
---
 drivers/block/ublk_drv.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/block/ublk_drv.c +6 -0
index 6c5bec7..e5ba07d 100644
@@ -2653,6 +2653,12 @@ static int ublk_ch_mmap(struct file *filp, struct vm_area_struct *vma)
 	if (vma->vm_flags & VM_WRITE)
 		return -EPERM;
 
+	/*
+	 * The per-queue command buffer is kernel-written ABI; prevent
+	 * the daemon from upgrading to writable via mprotect().
+	 */
+	vm_flags_clear(vma, VM_MAYWRITE);
+
 	end = UBLKSRV_CMD_BUF_OFFSET + ub->dev_info.nr_hw_queues * max_sz;
 	if (phys_off < UBLKSRV_CMD_BUF_OFFSET || phys_off >= end)
 		return -EINVAL;
Signature · 1 line
2.53.0
maintainer Reviewed-by on v1 1/1
#2 lore raw
Quoted 32 lines · Kanishka De Silva

ublk_ch_mmap() rejects mmap requests with VM_WRITE set, but never clears VM_MAYWRITE on the resulting read-only mapping. This allows a userspace daemon to mmap the per-queue command buffer PROT_READ, then upgrade it to PROT_WRITE via mprotect(), since VM_MAYWRITE was never cleared.

The command buffer holds struct ublksrv_io_desc entries that are kernel-written ABI; a writable mapping lets an unprivileged daemon process corrupt fields such as addr, op_flags, nr_sectors, and start_sector.

Same bug class as the drm/panthor and drm/vc4 VM_MAYWRITE fixes, and the 2026-08-13 ptp/vmclock fix (a5edadbae57e).

Verified via mprotect() PoC: before the fix, a PROT_READ mapping can be upgraded to PROT_READ|PROT_WRITE and a write into the command buffer corrupts io_desc fields (confirmed under KASAN). After the fix, mprotect() returns -EACCES.

Fixes 3fee8d7599e1 ("ublk_drv: add io_uring based userspace block driver")
---
 drivers/block/ublk_drv.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/block/ublk_drv.c +0 -0
index 6c5bec7..e5ba07d 100644

drivers/block/ublk_drv.c static int ublk_ch_mmap(struct file *filp, struct vm_area_struct *vma) · line 2661

Quoted 9 lines
drivers/block/ublk_drv.c +6 -0
@@ -2653,6 +2653,12 @@ static int ublk_ch_mmap(struct file *filp, struct vm_area_struct *vma)
        if (vma->vm_flags & VM_WRITE)
                return -EPERM;
 
+       /*
+        * The per-queue command buffer is kernel-written ABI; prevent
+        * the daemon from upgrading to writable via mprotect().
+        */
+       vm_flags_clear(vma, VM_MAYWRITE);
+

Thanks,
Ming Lei

maintainer
#3 lore raw
In reply to Kanishka De Silva
Quoted 19 lines · Kanishka De Silva

ublk_ch_mmap() rejects mmap requests with VM_WRITE set, but never clears VM_MAYWRITE on the resulting read-only mapping. This allows a userspace daemon to mmap the per-queue command buffer PROT_READ, then upgrade it to PROT_WRITE via mprotect(), since VM_MAYWRITE was never cleared.

The command buffer holds struct ublksrv_io_desc entries that are kernel-written ABI; a writable mapping lets an unprivileged daemon process corrupt fields such as addr, op_flags, nr_sectors, and start_sector.

Same bug class as the drm/panthor and drm/vc4 VM_MAYWRITE fixes, and the 2026-08-13 ptp/vmclock fix (a5edadbae57e).

Verified via mprotect() PoC: before the fix, a PROT_READ mapping can be upgraded to PROT_READ|PROT_WRITE and a write into the command buffer corrupts io_desc fields (confirmed under KASAN). After the fix, mprotect() returns -EACCES.

Quoted 6 lines
Fixes 3fee8d7599e1 ("ublk_drv: add io_uring based userspace block driver")
---
 drivers/block/ublk_drv.c | 6 ++++++
 1 file changed, 6 insertions(+)

You only sent this to the stable list in public, and didn't cc: any of the relevant maintainers or the proper mailing list. Please use scripts/get_maintainer.pl on your patch to determine who to send stuff to.

thanks,

greg k-h

maintainer Applied
#4 lore raw
In reply to Kanishka De Silva
Quoted 6 lines · Kanishka De Silva

ublk_ch_mmap() rejects mmap requests with VM_WRITE set, but never clears VM_MAYWRITE on the resulting read-only mapping. This allows a userspace daemon to mmap the per-queue command buffer PROT_READ, then upgrade it to PROT_WRITE via mprotect(), since VM_MAYWRITE was never cleared.

Quoted 6 lines

The command buffer holds struct ublksrv_io_desc entries that are kernel-written ABI; a writable mapping lets an unprivileged daemon process corrupt fields such as addr, op_flags, nr_sectors, and start_sector.

[...]

Applied, thanks!

[1/1] ublk: clear VM_MAYWRITE on read-only ublk char device mmap

      commit: 6e2b571b0a54755b06e092501913e1dfefe75d6c

Best regards,

Signature · 1 line
Jens Axboe
#5 lore raw

PATCH v2 1/1 ublk: clear VM_MAYWRITE on read-only ublk char device mmap

In reply to a message not in the archive

ublk_ch_mmap() rejects mmap requests with VM_WRITE set, but never clears VM_MAYWRITE on the resulting read-only mapping. This allows a userspace daemon to mmap the per-queue command buffer PROT_READ, then upgrade it to PROT_WRITE via mprotect(), since VM_MAYWRITE was never cleared.

The command buffer holds struct ublksrv_io_desc entries that are kernel-written ABI; a writable mapping lets an unprivileged daemon process corrupt fields such as addr, op_flags, nr_sectors, and start_sector.

Same bug class as the drm/panthor and drm/vc4 VM_MAYWRITE fixes, and the 2026-08-13 ptp/vmclock fix (a5edadbae57e).

Verified via mprotect() PoC: before the fix, a PROT_READ mapping can be upgraded to PROT_READ|PROT_WRITE and a write into the command buffer corrupts io_desc fields (confirmed under KASAN). After the fix, mprotect() returns -EACCES.

Fixes 3fee8d7599e1 ("ublk_drv: add io_uring based userspace block driver")

---
v2: Cc [email protected] and Jens Axboe per get_maintainer.pl
(Greg KH). Added Reviewed-by from Ming Lei. No code change.

 drivers/block/ublk_drv.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/block/ublk_drv.c +6 -0
index 6c5bec7..e5ba07d 100644
@@ -2653,6 +2653,12 @@ static int ublk_ch_mmap(struct file *filp, struct vm_area_struct *vma)
 	if (vma->vm_flags & VM_WRITE)
 		return -EPERM;
 
+	/*
+	 * The per-queue command buffer is kernel-written ABI; prevent
+	 * the daemon from upgrading to writable via mprotect().
+	 */
+	vm_flags_clear(vma, VM_MAYWRITE);
+
 	end = UBLKSRV_CMD_BUF_OFFSET + ub->dev_info.nr_hw_queues * max_sz;
 	if (phys_off < UBLKSRV_CMD_BUF_OFFSET || phys_off >= end)
 		return -EINVAL;
Signature · 1 line
2.53.0