All of lore.kernel.org
 help / color / mirror / Atom feed
From: Abdifatah Suruur <suruurism@gmail.com>
To: Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>
Cc: linux-rdma@vger.kernel.org, Jason Gunthorpe <jgg@nvidia.com>,
	Leon Romanovsky <leonro@nvidia.com>,
	Abdifatah Suruur <suruurism@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH 2/2] IB/hfi1: reject writable SUBCTXT_EGRBUF mmap
Date: Wed, 18 Nov 2026 16:19:47 +0300	[thread overview]
Message-ID: <20261118131948.28748-2-suruurism@gmail.com> (raw)
In-Reply-To: <20261118131948.28748-1-suruurism@gmail.com>

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;

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

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2026-11-18 13:35   ` [PATCH 2/2] IB/hfi1: reject writable SUBCTXT_EGRBUF mmap 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

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=20261118131948.28748-2-suruurism@gmail.com \
    --to=suruurism@gmail.com \
    --cc=dennis.dalessandro@cornelisnetworks.com \
    --cc=jgg@nvidia.com \
    --cc=leonro@nvidia.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /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.