Re: [PATCH v6] livepatch: Clear relocation targets on a module removal

From
Miroslav Benes <mbenes@suse.cz>
Date
2022-12-09 12:49:35
Also in
live-patching, lkml
Reply to
Song Liu, 2022-11-29
quoted
quoted
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -316,6 +316,45 @@ int klp_apply_section_relocs(struct module *pmod, Elf_Shdr *sechdrs,
      return apply_relocate_add(sechdrs, strtab, symndx, secndx, pmod);
 }

+static void klp_clear_object_relocations(struct module *pmod,
+                                     struct klp_object *obj)
+{
+     int i, cnt;
+     const char *objname, *secname;
+     char sec_objname[MODULE_NAME_LEN];
+     Elf_Shdr *sec;
+
+     objname = klp_is_module(obj) ? obj->name : "vmlinux";
+
+     /* For each klp relocation section */
+     for (i = 1; i < pmod->klp_info->hdr.e_shnum; i++) {
+             sec = pmod->klp_info->sechdrs + i;
+             secname = pmod->klp_info->secstrings + sec->sh_name;
+             if (!(sec->sh_flags & SHF_RELA_LIVEPATCH))
+                     continue;
+
+             /*
+              * Format: .klp.rela.sec_objname.section_name
+              * See comment in klp_resolve_symbols() for an explanation
+              * of the selected field width value.
+              */
+             secname = pmod->klp_info->secstrings + sec->sh_name;
+             cnt = sscanf(secname, ".klp.rela.%55[^.]", sec_objname);
+             if (cnt != 1) {
+                     pr_err("section %s has an incorrectly formatted name\n",
+                            secname);
+                     continue;
+             }
Actually, I think we don't need the cnt check here. Once it is removed,
there isn't much duplicated logic.
Because it must have passed the check once already during 
klp_apply_section_relocs()? Yes, perhaps.

Miroslav
Thread (27 messages) 27 messages, 5 authors, last reply 2022-12-13
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help