All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Abdifatah Suruur" <suruurism@gmail.com>
Cc: linux-rdma@vger.kernel.org
Subject: Re: [PATCH] IB/hfi1: clear VM_MAYWRITE on read-only STATUS mmap
Date: Wed, 18 Nov 2026 13:14:18 +0000	[thread overview]
Message-ID: <sashiko-outbox-220989@kernel.org> (raw)
In-Reply-To: <20261118125848.26160-1-suruurism@gmail.com>

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

      reply	other threads:[~2026-11-18 13:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-220989@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=suruurism@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.