* [PATCH 1/2] IB/hfi1: clear VM_MAYWRITE on read-only STATUS mmap
@ 2026-11-18 13:19 Abdifatah Suruur
2026-11-18 13:19 ` [PATCH 2/2] IB/hfi1: reject writable SUBCTXT_EGRBUF mmap Abdifatah Suruur
2026-11-18 13:24 ` [PATCH 1/2] IB/hfi1: clear VM_MAYWRITE on read-only STATUS mmap sashiko-bot
0 siblings, 2 replies; 5+ messages in thread
From: Abdifatah Suruur @ 2026-11-18 13:19 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.
Fixes: 12220267645c ("IB/hfi: Protect against writable mmap")
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] 5+ messages in thread
* [PATCH 2/2] IB/hfi1: reject writable SUBCTXT_EGRBUF mmap
2026-11-18 13:19 [PATCH 1/2] IB/hfi1: clear VM_MAYWRITE on read-only STATUS mmap Abdifatah Suruur
@ 2026-11-18 13:19 ` Abdifatah Suruur
2026-11-18 13:35 ` sashiko-bot
2026-11-18 13:36 ` Abdifatah Suruur
2026-11-18 13:24 ` [PATCH 1/2] IB/hfi1: clear VM_MAYWRITE on read-only STATUS mmap sashiko-bot
1 sibling, 2 replies; 5+ messages in thread
From: Abdifatah Suruur @ 2026-11-18 13:19 UTC (permalink / raw)
To: Dennis Dalessandro
Cc: linux-rdma, Jason Gunthorpe, Leon Romanovsky, Abdifatah Suruur,
stable
hfi1_file_mmap() clears VM_MAYWRITE for the SUBCTXT_EGRBUF mapping, but
never checks whether the caller requested VM_WRITE in the first place.
A caller can pass PROT_WRITE to mmap() and get a writable mapping of
the read-only shared eager receive buffers, unlike RCV_EGRBUF which
rejects the request with -EPERM.
Add the missing VM_WRITE check, matching the other read-only mmap cases
in this function.
Fixes: 12220267645c ("IB/hfi: Protect against writable mmap")
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..6de12a276a605 100644
--- a/drivers/infiniband/hw/hfi1/file_ops.c
+++ b/drivers/infiniband/hw/hfi1/file_ops.c
@@ -525,6 +525,10 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma)
is_vmalloc = 1;
break;
case SUBCTXT_EGRBUF:
+ if (flags & VM_WRITE) {
+ ret = -EPERM;
+ goto done;
+ }
memvirt = uctxt->subctxt_rcvegrbuf;
memlen = uctxt->egrbufs.size * uctxt->subctxt_cnt;
flags &= ~VM_MAYWRITE;
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] IB/hfi1: clear VM_MAYWRITE on read-only STATUS mmap
2026-11-18 13:19 [PATCH 1/2] IB/hfi1: clear VM_MAYWRITE on read-only STATUS mmap Abdifatah Suruur
2026-11-18 13:19 ` [PATCH 2/2] IB/hfi1: reject writable SUBCTXT_EGRBUF mmap Abdifatah Suruur
@ 2026-11-18 13:24 ` sashiko-bot
1 sibling, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-18 13:24 UTC (permalink / raw)
To: Abdifatah Suruur; +Cc: linux-rdma
> 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.
>
> Fixes: 12220267645c ("IB/hfi: Protect against writable mmap")
> Cc: stable@vger.kernel.org
> Signed-off-by: Abdifatah Suruur <suruurism@gmail.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118131948.28748-1-suruurism@gmail.com?part=1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] IB/hfi1: reject writable SUBCTXT_EGRBUF mmap
2026-11-18 13:19 ` [PATCH 2/2] IB/hfi1: reject writable SUBCTXT_EGRBUF mmap Abdifatah Suruur
@ 2026-11-18 13:35 ` sashiko-bot
2026-11-18 13:36 ` Abdifatah Suruur
1 sibling, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-18 13:35 UTC (permalink / raw)
To: Abdifatah Suruur; +Cc: linux-rdma
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] IB/hfi1: rejecting VM_WRITE on SUBCTXT_EGRBUF in
hfi1_file_mmap() breaks subcontexts
- [Low] IB/hfi1: inaccurate Fixes trailer citing 12220267645c for
hfi1_file_mmap()
--
commit 0342c207f57f73ef2cbfe9cff3f4ce685d284272
Author: Abdifatah Suruur <suruurism@gmail.com>
> IB/hfi1: reject writable SUBCTXT_EGRBUF mmap
>
> hfi1_file_mmap() clears VM_MAYWRITE for the SUBCTXT_EGRBUF mapping, but
> never checks whether the caller requested VM_WRITE in the first place.
> A caller can pass PROT_WRITE to mmap() and get a writable mapping of
> the read-only shared eager receive buffers, unlike RCV_EGRBUF which
> rejects the request with -EPERM.
>
> Add the missing VM_WRITE check, matching the other read-only mmap cases
> in this function.
>
> Fixes: 12220267645c ("IB/hfi: Protect against writable mmap")
> Cc: stable@vger.kernel.org
> Signed-off-by: Abdifatah Suruur <suruurism@gmail.com>
[Severity: Low]
12220267645c ("IB/hfi: Protect against writable mmap") only added a
VM_WRITE | VM_EXEC check to the STATUS case in hfi1_file_mmap(). The
SUBCTXT_EGRBUF handling dates back to 7724105686e7 ("IB/hfi1: add driver
files").
> diff --git a/drivers/infiniband/hw/hfi1/file_ops.c b/drivers/infiniband/hw/hfi1/file_ops.c
> index 779dbe32c69da..412c134e5fb2a 100644
> --- a/drivers/infiniband/hw/hfi1/file_ops.c
> +++ b/drivers/infiniband/hw/hfi1/file_ops.c
> @@ -526,6 +526,10 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma)
> is_vmalloc = 1;
> break;
> case SUBCTXT_EGRBUF:
> + if (flags & VM_WRITE) {
> + ret = -EPERM;
> + goto done;
> + }
> memvirt = uctxt->subctxt_rcvegrbuf;
> memlen = uctxt->egrbufs.size * uctxt->subctxt_cnt;
> flags &= ~VM_MAYWRITE;
[Severity: High]
Does rejecting VM_WRITE on SUBCTXT_EGRBUF break userspace context sharing?
Unlike RCV_EGRBUF, which maps DMA buffers written by the HFI1 chip,
uctxt->subctxt_rcvegrbuf is a vmalloc_user() buffer allocated in
setup_subctxt() for userspace subcontexts sharing a hardware context, and
neither hardware nor the kernel ever writes to it. The process polling
the hardware receive queue forwards eager packets to sibling subcontexts
by writing them into this shared mapping (alongside SUBCTXT_RCV_HDRQ and
SUBCTXT_UREGS), so userspace maps SUBCTXT_EGRBUF with PROT_READ |
PROT_WRITE. Rejecting VM_WRITE causes subcontext initialization to fail
with -EPERM and leaves nothing able to populate uctxt->subctxt_rcvegrbuf.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118131948.28748-1-suruurism@gmail.com?part=2
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] IB/hfi1: reject writable SUBCTXT_EGRBUF mmap
2026-11-18 13:19 ` [PATCH 2/2] IB/hfi1: reject writable SUBCTXT_EGRBUF mmap Abdifatah Suruur
2026-11-18 13:35 ` sashiko-bot
@ 2026-11-18 13:36 ` Abdifatah Suruur
1 sibling, 0 replies; 5+ messages in thread
From: Abdifatah Suruur @ 2026-11-18 13:36 UTC (permalink / raw)
To: Dennis Dalessandro; +Cc: linux-rdma, Jason Gunthorpe, Leon Romanovsky
Hello,
Please drop patch 2/2 of this series ("IB/hfi1: reject writable SUBCTXT_EGRBUF mmap").
The automated review pointed out that uctxt->subctxt_rcvegrbuf is a
vmalloc_user() buffer that userspace subcontexts sharing a hardware
context intentionally map PROT_READ|PROT_WRITE: the process polling the
hardware receive queue forwards eager packets into it. Rejecting VM_WRITE
would break subcontext initialization, and the existing VM_MAYWRITE clear
is deliberate policy. My patch was wrong; I am withdrawing it.
Patch 1/2 (STATUS VM_MAYWRITE) is unaffected and stands on its own.
Sorry for the noise,
Abdifatah Suruur
suruurism@gmail.com
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-18 13:36 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 13:19 [PATCH 1/2] IB/hfi1: clear VM_MAYWRITE on read-only STATUS mmap Abdifatah Suruur
2026-11-18 13:19 ` [PATCH 2/2] IB/hfi1: reject writable SUBCTXT_EGRBUF mmap Abdifatah Suruur
2026-11-18 13:35 ` sashiko-bot
2026-11-18 13:36 ` Abdifatah Suruur
2026-11-18 13:24 ` [PATCH 1/2] IB/hfi1: clear VM_MAYWRITE on read-only STATUS mmap sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox