History

objtool/klp: Explicitly disallow patching or referencing init code/data

Explicitly disallow the patching and referencing of init code/data. Otherwise it could potentially introduce some odd edge cases depending on whether the target object's init section has been freed yet (note that the init code still exists in the target module when doing late module patching). Such edge cases include sympos calculation and the patching and/or referencing of non-existent (init-freed) code/data. Not to mention the inherent differences in behavior that occur when the init code is only patched *some* of the time depending on module loading order or kernel config.

Josh Poimboeuf committed 3 months ago

Commit 69f361b1 parent 636f2301 file · +10 −0Browse files

Showing the changes to tools/objtool (1 of 1 file). Show all

Unified · Split

tools/objtool/klp-sympos.c+10−0
@@ -367,6 +367,11 @@ static unsigned long find_vmlinux_sympos(struct symbol *sym) · 366 unmodified lines
367367 return sympos;
368368 }
369369
370+static bool is_init_sym(struct symbol *sym)
371+{
372+ return strstarts(sym->sec->name, ".init");
373+}
374+
370375 /*
371376 * "sympos" is used by livepatch to disambiguate duplicate symbol names.
372377 */
@@ -376,6 +381,11 @@ unsigned long klp_find_sympos(struct elf *elf, struct symbol *sym) · 3 unmodified lines
376381 bool has_dup = false;
377382 struct symbol *s;
378383
384+ if (is_init_sym(sym)) {
385+ ERROR("%s: can't patch or reference init code/data", sym->name);
386+ return ULONG_MAX;
387+ }
388+
379389 if (sym->bind != STB_LOCAL)
380390 return 0;
381391