From: bo cao <treebacker@foxmail.com>
To: linux-fpga@vger.kernel.org
Cc: yilun.xu@intel.com, trix@redhat.com, mdf@kernel.org,
linux-kernel@vger.kernel.org, bo cao <treebacker@foxmail.com>
Subject: [PATCH] fpga: dfl: afu: prevent read-only region mappings from becoming writable
Date: Thu, 29 Oct 2026 11:53:17 +0800 [thread overview]
Message-ID: <tencent_C59525D78A2FBCC2425A3CA9EF4C53D56F08@qq.com> (raw)
afu_mmap() rejects writable mappings of regions without the WRITE
flag, but leaves VM_MAYWRITE set. Userspace can map such a region
read-only and then upgrade the mapping to writable with mprotect().
Clear VM_MAYWRITE for regions without the WRITE flag, as fixed in
vfio/platform (commit 420bed9131db), drm/vc4 (CVE-2026-68445),
drm/panthor (CVE-2024-53071) and ptp/vmclock (commit a5edadbae57e).
Note this is defensive hardening: the in-tree callers of
afu_mmio_region_add() (port_afu_init() and port_stp_init()) all
register their regions with DFL_PORT_REGION_WRITE. The guard costs
nothing and keeps the mmap() interface honest if a read-only region
ever appears.
Fixes: 857a26222ff7 ("fpga: dfl: afu: add afu sub feature support")
Signed-off-by: bo cao <treebacker@foxmail.com>
---
drivers/fpga/dfl-afu-main.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/fpga/dfl-afu-main.c b/drivers/fpga/dfl-afu-main.c
index 097a97eeea66..a802309e0473 100644
--- a/drivers/fpga/dfl-afu-main.c
+++ b/drivers/fpga/dfl-afu-main.c
@@ -833,9 +833,13 @@ static int afu_mmap(struct file *filp, struct vm_area_struct *vma)
if ((vma->vm_flags & VM_READ) && !(region.flags & DFL_PORT_REGION_READ))
return -EPERM;
- if ((vma->vm_flags & VM_WRITE) &&
- !(region.flags & DFL_PORT_REGION_WRITE))
- return -EPERM;
+ /* Prevent read-only region mappings from being upgraded with mprotect() */
+ if (!(region.flags & DFL_PORT_REGION_WRITE)) {
+ if (vma->vm_flags & VM_WRITE)
+ return -EPERM;
+
+ vm_flags_clear(vma, VM_MAYWRITE);
+ }
/* Support debug access to the mapping */
vma->vm_ops = &afu_vma_ops;
--
2.39.5 (Apple Git-154)
next reply other threads:[~2026-10-29 3:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-29 3:53 bo cao [this message]
2026-11-07 11:27 ` Xu Yilun
2026-11-09 2:59 ` bo cao
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=tencent_C59525D78A2FBCC2425A3CA9EF4C53D56F08@qq.com \
--to=treebacker@foxmail.com \
--cc=linux-fpga@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mdf@kernel.org \
--cc=trix@redhat.com \
--cc=yilun.xu@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®