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.
Showing the changes to tools/objtool (1 of 1 file). Show all
Unified · Split
| @@ -367,6 +367,11 @@ static unsigned long find_vmlinux_sympos(struct symbol *sym) · 366 unmodified lines | |||
| 367 | return sympos; | 367 | return sympos; |
| 368 | } | 368 | } |
| 369 | 369 | ||
| 370 | static bool is_init_sym(struct symbol *sym) | ||
| 371 | { | ||
| 372 | return strstarts(sym->sec->name, ".init"); | ||
| 373 | } | ||
| 374 | |||
| 370 | /* | 375 | /* |
| 371 | * "sympos" is used by livepatch to disambiguate duplicate symbol names. | 376 | * "sympos" is used by livepatch to disambiguate duplicate symbol names. |
| 372 | */ | 377 | */ |
| @@ -376,6 +381,11 @@ unsigned long klp_find_sympos(struct elf *elf, struct symbol *sym) · 3 unmodified lines | |||
| 376 | bool has_dup = false; | 381 | bool has_dup = false; |
| 377 | struct symbol *s; | 382 | struct symbol *s; |
| 378 | 383 | ||
| 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 | |||
| 379 | if (sym->bind != STB_LOCAL) | 389 | if (sym->bind != STB_LOCAL) |
| 380 | return 0; | 390 | return 0; |
| 381 | 391 | ||