Skip to content

Commit be84d8e

Browse files
jpidancetsuryasaimadhu
authored andcommitted
x86/alternative: Consistently patch SMP locks in vmlinux and modules
alternatives_smp_module_add() restricts patching of SMP lock prefixes to the text address range passed as an argument. For vmlinux, patching all the instructions located between the _text and _etext symbols is allowed. That includes the .text section but also other sections such as .text.hot and .text.unlikely. As per the comment inside the 'struct smp_alt_module' definition, the original purpose of this restriction is to avoid patching the init code because in the case when one boots with a single CPU, the LOCK prefixes to the locking primitives are removed. Later on, when other CPUs are onlined, those LOCK prefixes get added back in but by that time the .init code is very likely removed so patching that would be a bad idea. For modules, the current code only allows patching instructions located inside the .text segment, excluding other sections such as .text.hot or .text.unlikely, which may need patching. Make patching of the kernel core and modules more consistent by allowing all text sections of modules except .init.text to be patched in module_finalize(). For that, use mod->core_layout.base/mod->core_layout.text_size as the address range allowed to be patched, which include all the code sections except the init code. [ bp: Massage and expand commit message. ] Signed-off-by: Julian Pidancet <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent eb70814 commit be84d8e

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

arch/x86/kernel/module.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,12 @@ int module_finalize(const Elf_Ehdr *hdr,
251251
const Elf_Shdr *sechdrs,
252252
struct module *me)
253253
{
254-
const Elf_Shdr *s, *text = NULL, *alt = NULL, *locks = NULL,
254+
const Elf_Shdr *s, *alt = NULL, *locks = NULL,
255255
*para = NULL, *orc = NULL, *orc_ip = NULL,
256256
*retpolines = NULL, *returns = NULL, *ibt_endbr = NULL;
257257
char *secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
258258

259259
for (s = sechdrs; s < sechdrs + hdr->e_shnum; s++) {
260-
if (!strcmp(".text", secstrings + s->sh_name))
261-
text = s;
262260
if (!strcmp(".altinstructions", secstrings + s->sh_name))
263261
alt = s;
264262
if (!strcmp(".smp_locks", secstrings + s->sh_name))
@@ -302,12 +300,13 @@ int module_finalize(const Elf_Ehdr *hdr,
302300
void *iseg = (void *)ibt_endbr->sh_addr;
303301
apply_ibt_endbr(iseg, iseg + ibt_endbr->sh_size);
304302
}
305-
if (locks && text) {
303+
if (locks) {
306304
void *lseg = (void *)locks->sh_addr;
307-
void *tseg = (void *)text->sh_addr;
305+
void *text = me->core_layout.base;
306+
void *text_end = text + me->core_layout.text_size;
308307
alternatives_smp_module_add(me, me->name,
309308
lseg, lseg + locks->sh_size,
310-
tseg, tseg + text->sh_size);
309+
text, text_end);
311310
}
312311

313312
if (orc && orc_ip)

0 commit comments

Comments
 (0)