RDMA/cxgb4: Do not allow userspace to write the status page
Subsystems (2)
PATCH 1/1 RDMA/cxgb4: Do not allow userspace to write the status page
The device status page is shared by all userspace contexts and contains db_off, which the driver updates to control doorbell flow. The rdma-core provider maps it with PROT_READ, but c4iw_mmap() passes the requested page protection through when handling CXGB4_MMAP_CONTIG.
A process can therefore request PROT_WRITE directly or later upgrade a read-only mapping with mprotect() because VM_MAYWRITE remains set. This lets userspace alter device-wide flow-control state seen by the kernel and other contexts.
Reject initially writable mappings and clear VM_MAYWRITE before mapping the page. This preserves the existing read-only userspace ABI.
--- drivers/infiniband/hw/cxgb4/provider.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/infiniband/hw/cxgb4/provider.c +5 -0
@@ -171,6 +171,11 @@ static int c4iw_mmap(struct ib_ucontext *context, struct vm_area_struct *vma) len, t4_pgprot_wc(vma->vm_page_prot));break ;case CXGB4_MMAP_CONTIG : +if (vma->vm_flags &VM_WRITE ) { + ret = -EPERM ; +break ; + } +vm_flags_clear (vma,VM_MAYWRITE ); ret =io_remap_pfn_range (vma, vma->vm_start, addr >>PAGE_SHIFT , len, vma->vm_page_prot);
Signature · 1 line
2.34.1
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 10 lines
The device status page is shared by all userspace contexts and contains
db_off, which the driver updates to control doorbell flow. The rdma-core provider maps it withPROT_READ, butc4iw_mmap()passes the requested page protection through when handlingCXGB4_MMAP_CONTIG.A process can therefore request
PROT_WRITEdirectly or later upgrade a read-only mapping withmprotect()becauseVM_MAYWRITEremains set. This lets userspace alter device-wide flow-control state seen by the kernel and other contexts.
Quoted 5 lines
Reject initially writable mappings and clear
VM_MAYWRITEbefore mapping the page. This preserves the existing read-only userspace ABI.Fixes 05eb23893c2c ("cxgb4/iw_cxgb4: Doorbell Drop Avoidance Bug Fixes")Signed-off-by Jiale Yao <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Leon Romanovsky
AppliedQuoted 11 lines · Jiale Yao
The device status page is shared by all userspace contexts and contains
db_off, which the driver updates to control doorbell flow. The rdma-core provider maps it withPROT_READ, butc4iw_mmap()passes the requested page protection through when handlingCXGB4_MMAP_CONTIG.A process can therefore request
PROT_WRITEdirectly or later upgrade a read-only mapping withmprotect()becauseVM_MAYWRITEremains set. This lets userspace alter device-wide flow-control state seen by the kernel and other contexts.[...]
Applied, thanks!
[1/1] RDMA/cxgb4: Do not allow userspace to write the status page
https://git.kernel.org/rdma/rdma/c/1c5335a6902639
Best regards,
Signature · 1 line
Leon Romanovsky <[email protected]>