diff --git a/patches.kernel.org/6.2.12-104-riscv-add-icache-flush-for-nommu-sigreturn-tra.patch b/patches.kernel.org/6.2.12-104-riscv-add-icache-flush-for-nommu-sigreturn-tra.patch new file mode 100644 index 0000000..3c7fc8d --- /dev/null +++ b/patches.kernel.org/6.2.12-104-riscv-add-icache-flush-for-nommu-sigreturn-tra.patch @@ -0,0 +1,64 @@ +From: Mathis Salmen +Date: Thu, 6 Apr 2023 12:11:31 +0200 +Subject: [PATCH] riscv: add icache flush for nommu sigreturn trampoline +References: bsc#1012628 +Patch-mainline: 6.2.12 +Git-commit: 8d736482749f6d350892ef83a7a11d43cd49981e + +commit 8d736482749f6d350892ef83a7a11d43cd49981e upstream. + +In a NOMMU kernel, sigreturn trampolines are generated on the user +stack by setup_rt_frame. Currently, these trampolines are not instruction +fenced, thus their visibility to ifetch is not guaranteed. + +This patch adds a flush_icache_range in setup_rt_frame to fix this +problem. + +Signed-off-by: Mathis Salmen +Fixes: 6bd33e1ece52 ("riscv: add nommu support") +Cc: stable@vger.kernel.org +Link: https://lore.kernel.org/r/20230406101130.82304-1-mathis.salmen@matsal.de +Signed-off-by: Palmer Dabbelt +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Jiri Slaby +--- + arch/riscv/kernel/signal.c | 9 ++++++++- + 1 file changed, 8 insertions(+), 1 deletion(-) + +diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c +index bfb2afa4..dee66c92 100644 +--- a/arch/riscv/kernel/signal.c ++++ b/arch/riscv/kernel/signal.c +@@ -19,6 +19,7 @@ + #include + #include + #include ++#include + + extern u32 __user_rt_sigreturn[2]; + +@@ -181,6 +182,7 @@ static int setup_rt_frame(struct ksignal *ksig, sigset_t *set, + { + struct rt_sigframe __user *frame; + long err = 0; ++ unsigned long __maybe_unused addr; + + frame = get_sigframe(ksig, regs, sizeof(*frame)); + if (!access_ok(frame, sizeof(*frame))) +@@ -209,7 +211,12 @@ static int setup_rt_frame(struct ksignal *ksig, sigset_t *set, + if (copy_to_user(&frame->sigreturn_code, __user_rt_sigreturn, + sizeof(frame->sigreturn_code))) + return -EFAULT; +- regs->ra = (unsigned long)&frame->sigreturn_code; ++ ++ addr = (unsigned long)&frame->sigreturn_code; ++ /* Make sure the two instructions are pushed to icache. */ ++ flush_icache_range(addr, addr + sizeof(frame->sigreturn_code)); ++ ++ regs->ra = addr; + #endif /* CONFIG_MMU */ + + /* +-- +2.35.3 + diff --git a/series.conf b/series.conf index 8c6452e..da99376 100644 --- a/series.conf +++ b/series.conf @@ -2331,6 +2331,7 @@ patches.kernel.org/6.2.12-101-tracing-Have-tracing_snapshot_instance_cond-wr.patch patches.kernel.org/6.2.12-102-maple_tree-fix-write-memory-barrier-of-nodes-o.patch patches.kernel.org/6.2.12-103-ksmbd-avoid-out-of-bounds-access-in-decode_pre.patch + patches.kernel.org/6.2.12-104-riscv-add-icache-flush-for-nommu-sigreturn-tra.patch ######################################################## # Build fixes that apply to the vanilla kernel too.