Skip to content

Commit 74226bd

Browse files
committed
x86/module: prepare module loading for ROX allocations of text
jira LE-4694 Rebuild_History Non-Buildable kernel-6.12.0-55.43.1.el10_0 commit-author Mike Rapoport (Microsoft) <rppt@kernel.org> commit 9bfc482 When module text memory will be allocated with ROX permissions, the memory at the actual address where the module will live will contain invalid instructions and there will be a writable copy that contains the actual module code. Update relocations and alternatives patching to deal with it. [rppt@kernel.org: fix writable address in cfi_rewrite_endbr()] Link: https://lkml.kernel.org/r/ZysRwR29Ji8CcbXc@kernel.org Link: https://lkml.kernel.org/r/20241023162711.2579610-7-rppt@kernel.org Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Tested-by: kdevops <kdevops@lists.linux.dev> Tested-by: Nathan Chancellor <nathan@kernel.org> Cc: Andreas Larsson <andreas@gaisler.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Ard Biesheuvel <ardb@kernel.org> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Borislav Petkov (AMD) <bp@alien8.de> Cc: Brian Cain <bcain@quicinc.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Christophe Leroy <christophe.leroy@csgroup.eu> Cc: Christoph Hellwig <hch@lst.de> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Dinh Nguyen <dinguyen@kernel.org> Cc: Geert Uytterhoeven <geert@linux-m68k.org> Cc: Guo Ren <guoren@kernel.org> Cc: Helge Deller <deller@gmx.de> Cc: Huacai Chen <chenhuacai@kernel.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Johannes Berg <johannes@sipsolutions.net> Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de> Cc: Kent Overstreet <kent.overstreet@linux.dev> Cc: Liam R. Howlett <Liam.Howlett@Oracle.com> Cc: Luis Chamberlain <mcgrof@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Masami Hiramatsu (Google) <mhiramat@kernel.org> Cc: Matt Turner <mattst88@gmail.com> Cc: Max Filippov <jcmvbkbc@gmail.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Michal Simek <monstr@monstr.eu> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Palmer Dabbelt <palmer@dabbelt.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Richard Weinberger <richard@nod.at> Cc: Russell King <linux@armlinux.org.uk> Cc: Song Liu <song@kernel.org> Cc: Stafford Horne <shorne@gmail.com> Cc: Steven Rostedt (Google) <rostedt@goodmis.org> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Uladzislau Rezki (Sony) <urezki@gmail.com> Cc: Vineet Gupta <vgupta@kernel.org> Cc: Will Deacon <will@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> (cherry picked from commit 9bfc482) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent 5a9e6da commit 74226bd

File tree

6 files changed

+167
-117
lines changed

6 files changed

+167
-117
lines changed

arch/um/kernel/um_arch.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -435,24 +435,25 @@ void __init arch_cpu_finalize_init(void)
435435
os_check_bugs();
436436
}
437437

438-
void apply_seal_endbr(s32 *start, s32 *end)
438+
void apply_seal_endbr(s32 *start, s32 *end, struct module *mod)
439439
{
440440
}
441441

442-
void apply_retpolines(s32 *start, s32 *end)
442+
void apply_retpolines(s32 *start, s32 *end, struct module *mod)
443443
{
444444
}
445445

446-
void apply_returns(s32 *start, s32 *end)
446+
void apply_returns(s32 *start, s32 *end, struct module *mod)
447447
{
448448
}
449449

450450
void apply_fineibt(s32 *start_retpoline, s32 *end_retpoline,
451-
s32 *start_cfi, s32 *end_cfi)
451+
s32 *start_cfi, s32 *end_cfi, struct module *mod)
452452
{
453453
}
454454

455-
void apply_alternatives(struct alt_instr *start, struct alt_instr *end)
455+
void apply_alternatives(struct alt_instr *start, struct alt_instr *end,
456+
struct module *mod)
456457
{
457458
}
458459

arch/x86/entry/vdso/vma.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ int __init init_vdso_image(const struct vdso_image *image)
5454

5555
apply_alternatives((struct alt_instr *)(image->data + image->alt),
5656
(struct alt_instr *)(image->data + image->alt +
57-
image->alt_len));
57+
image->alt_len),
58+
NULL);
5859

5960
return 0;
6061
}

arch/x86/include/asm/alternative.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,16 @@ extern struct alt_instr __alt_instructions[], __alt_instructions_end[];
9696
* instructions were patched in already:
9797
*/
9898
extern int alternatives_patched;
99+
struct module;
99100

100101
extern void alternative_instructions(void);
101-
extern void apply_alternatives(struct alt_instr *start, struct alt_instr *end);
102-
extern void apply_retpolines(s32 *start, s32 *end);
103-
extern void apply_returns(s32 *start, s32 *end);
104-
extern void apply_seal_endbr(s32 *start, s32 *end);
102+
extern void apply_alternatives(struct alt_instr *start, struct alt_instr *end,
103+
struct module *mod);
104+
extern void apply_retpolines(s32 *start, s32 *end, struct module *mod);
105+
extern void apply_returns(s32 *start, s32 *end, struct module *mod);
106+
extern void apply_seal_endbr(s32 *start, s32 *end, struct module *mod);
105107
extern void apply_fineibt(s32 *start_retpoline, s32 *end_retpoine,
106-
s32 *start_cfi, s32 *end_cfi);
107-
108-
struct module;
108+
s32 *start_cfi, s32 *end_cfi, struct module *mod);
109109

110110
struct callthunk_sites {
111111
s32 *call_start, *call_end;

0 commit comments

Comments
 (0)