Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
* [PATCH] IB/hfi1: clear VM_MAYWRITE on read-only STATUS mmap
@ 2026-11-18 12:58 Abdifatah Suruur
  2026-11-18 13:14 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Abdifatah Suruur @ 2026-11-18 12:58 UTC (permalink / raw)
  To: Dennis Dalessandro
  Cc: linux-rdma, Jason Gunthorpe, Leon Romanovsky, Abdifatah Suruur,
	stable

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.

Cc: stable@vger.kernel.org
Signed-off-by: Abdifatah Suruur <suruurism@gmail.com>

---
diff --git a/drivers/infiniband/hw/hfi1/file_ops.c b/drivers/infiniband/hw/hfi1/file_ops.c
index 680364fda856f..779dbe32c69da 100644
--- a/drivers/infiniband/hw/hfi1/file_ops.c
+++ b/drivers/infiniband/hw/hfi1/file_ops.c
@@ -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;

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] IB/hfi1: clear VM_MAYWRITE on read-only STATUS mmap
  2026-11-18 12:58 [PATCH] IB/hfi1: clear VM_MAYWRITE on read-only STATUS mmap Abdifatah Suruur
@ 2026-11-18 13:14 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-18 13:14 UTC (permalink / raw)
  To: Abdifatah Suruur; +Cc: linux-rdma

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 <suruurism@gmail.com>

> 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.
>
> Cc: stable@vger.kernel.org
> Signed-off-by: Abdifatah Suruur <suruurism@gmail.com>

[Severity: Low]
Since this fixes the read-only STATUS mmap check added in commit
12220267645c ("IB/hfi: Protect against writable mmap"), consider adding:

  Fixes: 12220267645c ("IB/hfi: Protect against writable mmap")

> diff --git a/drivers/infiniband/hw/hfi1/file_ops.c b/drivers/infiniband/hw/hfi1/file_ops.c
> index 680364fda856f..779dbe32c69da 100644
> --- a/drivers/infiniband/hw/hfi1/file_ops.c
> +++ b/drivers/infiniband/hw/hfi1/file_ops.c
> @@ -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

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261118125848.26160-1-suruurism@gmail.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-18 13:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 12:58 [PATCH] IB/hfi1: clear VM_MAYWRITE on read-only STATUS mmap Abdifatah Suruur
2026-11-18 13:14 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox