skip data sections when looking for users of static locals

It's possible for a static local variable's data section to have
a relocation which refers to the variable symbol itself.  Fix the logic
which searches for the user of a static local variable by only looking
in text sections (i.e. functions).

Fixes #411.
This commit is contained in:
Josh Poimboeuf 2014-09-09 14:28:38 -05:00
parent c21cc1292f
commit 0537ff6a6f
2 changed files with 27 additions and 0 deletions

View File

@ -182,6 +182,12 @@ int is_rela_section(struct section *sec)
return (sec->sh.sh_type == SHT_RELA);
}
int is_text_section(struct section *sec)
{
return (sec->sh.sh_type == SHT_PROGBITS &&
(sec->sh.sh_flags & SHF_EXECINSTR));
}
int is_debug_section(struct section *sec)
{
char *name;
@ -904,6 +910,7 @@ void kpatch_correlate_static_local_variables(struct kpatch_elf *base,
sec = NULL;
list_for_each_entry(tmpsec, &patched->sections, list) {
if (!is_rela_section(tmpsec) ||
!is_text_section(tmpsec->base) ||
is_debug_section(tmpsec))
continue;
list_for_each_entry(rela, &tmpsec->relas, list) {

View File

@ -0,0 +1,20 @@
Index: src/kernel/reboot.c
===================================================================
--- src.orig/kernel/reboot.c
+++ src/kernel/reboot.c
@@ -285,8 +285,15 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
return ret;
}
+void kpatch_foo(void)
+{
+ if (!jiffies)
+ printk("kpatch_foo\n");
+}
+
static void deferred_cad(struct work_struct *dummy)
{
+ kpatch_foo();
kernel_restart(NULL);
}