IB/hfi1: clear VM_MAYWRITE on read-only STATUS mmap
Subsystems (3)
PATCH 1/1 IB/hfi1: clear VM_MAYWRITE on read-only STATUS mmap
hfi1_file_mmap() rejects a writable mapping of the device status page, but leaves VM_MAYWRITE set in the VMA flags. Userspace can map the page read-only and then upgrade it to writable with mprotect(), bypassing the check and writing to a device-owned status page.
Clear VM_MAYWRITE on this path, as the RTAIL and SUBCTXT_EGRBUF cases in the same function already do.
---
drivers/infiniband/hw/hfi1/file_ops.c +1 -0
@@ -492,6 +492,7 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma) ret = -EPERM ; goto done; } + flags &= ~VM_MAYWRITE ; memaddr =kvirt_to_phys ((void *)dd->status); memlen =PAGE_SIZE ;break ;
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] IB/hfi1: missing Fixes trailer for STATUS mmap VM_MAYWRITE fix It also noticed 1 related pre-existing…
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] IB/hfi1: missing Fixes trailer for STATUS mmap VM_MAYWRITE fix It also noticed 1 related pre-existing issue this patch does not introduce:
- [Critical] IB/hfi1: missing VM_WRITE check in hfi1_file_mmap() [1] --
commit acb6e09931f843c6bef13cb9b188808881bec93a
Author: Abdifatah Suruur <[email protected]>
Quoted 7 lines
IB/hfi1: clear
VM_MAYWRITEon read-only STATUS mmap
hfi1_file_mmap()rejects a writable mapping of the device status page, but leavesVM_MAYWRITEset in the VMA flags. Userspace can map the page read-only and then upgrade it to writable withmprotect(), bypassing the check and writing to a device-owned status page.
Quoted 5 lines
Clear
VM_MAYWRITEon this path, as the RTAIL andSUBCTXT_EGRBUFcases in the same function already do.Signed-off-by Abdifatah Suruur <[email protected]>
[Severity: Low]
Since this fixes the read-only STATUS mmap check added in commit 12220267645c ("IB/hfi: Protect against writable mmap"), consider adding:
drivers/infiniband/hw/hfi1/file_ops.c static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma) · line 498
Quoted 12 lines
drivers/infiniband/hw/hfi1/file_ops.c +1
-0@@ -492,6 +492,7 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma) ret = -EPERM ; goto done; } + flags &= ~VM_MAYWRITE ; memaddr =kvirt_to_phys ((void *)dd->status); memlen =PAGE_SIZE ;break ;
[Severity: Critical]
This problem wasn't introduced by this patch, but can userspace map the SUBCTXT_EGRBUF region as writable [1] by passing PROT_WRITE to mmap()?
drivers/infiniband/hw/hfi1/file_ops.c:hfi1_file_mmap() {
...
case SUBCTXT_EGRBUF:
memvirt = uctxt->subctxt_rcvegrbuf;
memlen = uctxt->egrbufs.size * uctxt->subctxt_cnt;
flags &= ~VM_MAYWRITE;
is_vmalloc = 1;
break;
...
}The SUBCTXT_EGRBUF case clears VM_MAYWRITE from flags, but unlike RCV_EGRBUF, STATUS, and RTAIL, it never checks if VM_WRITE is set in flags and does not reject the mapping with -EPERM. When userspace maps SUBCTXT_EGRBUF with PROT_WRITE, vm_flags_reset() leaves VM_WRITE set on the VMA and remap_vmalloc_range() maps uctxt->subctxt_rcvegrbuf with write permissions, allowing userspace to modify the read-only eager receive buffers.
[1] https://sashiko.dev/#/bug/linux-011f18cc-47f7-48a3-9cad-8eb2f835cdbe
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1