ublk: clear VM_MAYWRITE on read-only ublk char device mmap
Subsystems (3)
A message that is not in the archive (sent off-list or not yet received): 2026083055-isotope-broiler-88e5@gregkh
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.
--- drivers/block/ublk_drv.c | 6 ++++++ 1 file changed, 6 insertions(+)
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 ); + 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
Quoted 32 lines · Kanishka De Silva
ublk_ch_mmap()rejects mmap requests withVM_WRITEset, but never clearsVM_MAYWRITEon the resulting read-only mapping. This allows a userspace daemon to mmap the per-queue command bufferPROT_READ, then upgrade it toPROT_WRITEviamprotect(), sinceVM_MAYWRITEwas never cleared.The command buffer holds struct
ublksrv_io_descentries that are kernel-written ABI; a writable mapping lets an unprivileged daemon process corrupt fields such as addr,op_flags,nr_sectors, andstart_sector.Same bug class as the drm/panthor and drm/vc4
VM_MAYWRITEfixes, and the 2026-08-13 ptp/vmclock fix (a5edadbae57e).Verified via
mprotect()PoC: before the fix, aPROT_READmapping can be upgraded to PROT_READ|PROT_WRITE and a write into the command buffer corruptsio_descfields (confirmed under KASAN). After the fix,mprotect()returns-EACCES.Fixes 3fee8d7599e1 ("ublk_drv: add io_uring based userspace block driver")Signed-off-by Kanishka De Silva <[email protected]>--- drivers/block/ublk_drv.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/block/ublk_drv.c +0
-0
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
Greg KH
maintainerQuoted 19 lines · Kanishka De Silva
ublk_ch_mmap()rejects mmap requests withVM_WRITEset, but never clearsVM_MAYWRITEon the resulting read-only mapping. This allows a userspace daemon to mmap the per-queue command bufferPROT_READ, then upgrade it toPROT_WRITEviamprotect(), sinceVM_MAYWRITEwas never cleared.The command buffer holds struct
ublksrv_io_descentries that are kernel-written ABI; a writable mapping lets an unprivileged daemon process corrupt fields such as addr,op_flags,nr_sectors, andstart_sector.Same bug class as the drm/panthor and drm/vc4
VM_MAYWRITEfixes, and the 2026-08-13 ptp/vmclock fix (a5edadbae57e).Verified via
mprotect()PoC: before the fix, aPROT_READmapping can be upgraded to PROT_READ|PROT_WRITE and a write into the command buffer corruptsio_descfields (confirmed under KASAN). After the fix,mprotect()returns-EACCES.
Quoted 6 lines
Fixes 3fee8d7599e1 ("ublk_drv: add io_uring based userspace block driver")Signed-off-by Kanishka De Silva <[email protected]>--- 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
Quoted 6 lines · Kanishka De Silva
ublk_ch_mmap()rejects mmap requests withVM_WRITEset, but never clearsVM_MAYWRITEon the resulting read-only mapping. This allows a userspace daemon to mmap the per-queue command bufferPROT_READ, then upgrade it toPROT_WRITEviamprotect(), sinceVM_MAYWRITEwas never cleared.
Quoted 6 lines
The command buffer holds struct
ublksrv_io_descentries that are kernel-written ABI; a writable mapping lets an unprivileged daemon process corrupt fields such as addr,op_flags,nr_sectors, andstart_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
PATCH v2 1/1 ublk: clear VM_MAYWRITE on read-only ublk char device mmap
In reply to a message not in the archiveublk_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.
---
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
@@ -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