From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
To: Albert Ou <aou@eecs.berkeley.edu>,
Palmer Dabbelt <palmer@dabbelt.com>,
Paul Walmsley <pjw@kernel.org>
Cc: Alexandre Ghiti <alex@ghiti.fr>, Mike Rapoport <rppt@kernel.org>,
linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org
Subject: [PATCH 1/2] riscv: do not make the linear map alias executable in set_memory_*()
Date: Thu, 12 Nov 2026 15:42:18 +0200 [thread overview]
Message-ID: <20261112-fixes-riscv-v1-1-1caac19897b5@kernel.org> (raw)
In-Reply-To: <20261112-fixes-riscv-v1-0-1caac19897b5@kernel.org>
set_memory_*() applies the requested change to the linear map alias of the
range. For set_memory_x() that makes the linear map alias of module text
and of BPF programs executable, although nothing should ever execute that
code through the linear map.
Keep _PAGE_EXEC out of the bits set_memory_*() sets on the linear map
alias.
Fixes: 311cd2f6e253 ("riscv: Fix set_memory_XX() and set_direct_map_XX() by splitting huge linear mappings")
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
arch/riscv/mm/pageattr.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/arch/riscv/mm/pageattr.c b/arch/riscv/mm/pageattr.c
index 5b3cf326455db..b138113755359 100644
--- a/arch/riscv/mm/pageattr.c
+++ b/arch/riscv/mm/pageattr.c
@@ -271,6 +271,10 @@ static int __set_memory(unsigned long addr, int numpages, pgprot_t set_mask,
.set_mask = set_mask,
.clear_mask = clear_mask
};
+ struct pageattr_masks __maybe_unused lm_masks = {
+ .set_mask = __pgprot(pgprot_val(set_mask) & ~_PAGE_EXEC),
+ .clear_mask = clear_mask
+ };
if (!numpages)
return 0;
@@ -300,7 +304,8 @@ static int __set_memory(unsigned long addr, int numpages, pgprot_t set_mask,
goto unlock;
ret = walk_kernel_page_table_range(lm_start, lm_end,
- &pageattr_ops, NULL, &masks);
+ &pageattr_ops, NULL,
+ &lm_masks);
if (ret)
goto unlock;
}
@@ -318,7 +323,7 @@ static int __set_memory(unsigned long addr, int numpages, pgprot_t set_mask,
goto unlock;
ret = walk_kernel_page_table_range(lm_start, lm_end,
- &pageattr_ops, NULL, &masks);
+ &pageattr_ops, NULL, &lm_masks);
if (ret)
goto unlock;
}
--
2.53.0
next prev parent reply other threads:[~2026-11-12 13:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 13:42 [PATCH 0/2] riscv: mm: fix set_memory_x() and kernel_page_present() Mike Rapoport (Microsoft)
2026-11-12 13:42 ` Mike Rapoport (Microsoft) [this message]
2026-11-12 13:42 ` [PATCH 2/2] riscv: mm: check the valid bit in kernel_page_present() Mike Rapoport (Microsoft)
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=20261112-fixes-riscv-v1-1-1caac19897b5@kernel.org \
--to=rppt@kernel.org \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=pjw@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 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®