mirror of
https://github.com/dynup/kpatch
synced 2025-02-19 19:26:53 +00:00
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:
parent
c21cc1292f
commit
0537ff6a6f
@ -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) {
|
||||
|
20
test/integration/gcc-static-local-var-3.patch
Normal file
20
test/integration/gcc-static-local-var-3.patch
Normal 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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user