Skip to content

Commit ef8b270

Browse files
authored
Merge pull request #1258 from jpoimboe/seg-fault
Fix seg fault caused by missing .LCx symbol
2 parents 8439de4 + c2e73c2 commit ef8b270

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

kpatch-build/create-diff-object.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,18 +1054,9 @@ static void kpatch_correlate_symbols(struct list_head *symlist_orig,
10541054
continue;
10551055

10561056
/*
1057-
* The .LCx symbols point to strings, usually used for
1058-
* the bug table. Don't correlate and compare the
1059-
* symbols themselves, because the suffix number might
1060-
* change.
1061-
*
1062-
* If the symbol is used by the bug table (usual case),
1063-
* it may get pulled in by
1064-
* kpatch_regenerate_special_section().
1065-
*
1066-
* If the symbol is used outside of the bug table (not
1067-
* sure if this actually happens anywhere), any string
1068-
* changes will be detected elsewhere in rela_equal().
1057+
* The .LCx symbols point to string literals in
1058+
* '.rodata.<func>.str1.*' sections. They get included
1059+
* in kpatch_include_standard_elements().
10691060
*/
10701061
if (sym_orig->type == STT_NOTYPE &&
10711062
!strncmp(sym_orig->name, ".LC", 3))
@@ -1781,9 +1772,16 @@ static void kpatch_include_symbol(struct symbol *sym)
17811772
kpatch_include_section(sym->sec);
17821773
}
17831774

1775+
static bool is_string_literal_section(struct section *sec)
1776+
{
1777+
return !strncmp(sec->name, ".rodata.", 8) &&
1778+
strstr(sec->name, ".str1.");
1779+
}
1780+
17841781
static void kpatch_include_standard_elements(struct kpatch_elf *kelf)
17851782
{
17861783
struct section *sec;
1784+
struct symbol *sym;
17871785

17881786
list_for_each_entry(sec, &kelf->sections, list) {
17891787
/*
@@ -1813,12 +1811,15 @@ static void kpatch_include_standard_elements(struct kpatch_elf *kelf)
18131811
!strcmp(sec->name, ".symtab") ||
18141812
!strcmp(sec->name, ".toc") ||
18151813
!strcmp(sec->name, ".rodata") ||
1816-
(!strncmp(sec->name, ".rodata.", 8) &&
1817-
strstr(sec->name, ".str1."))) {
1814+
is_string_literal_section(sec)) {
18181815
kpatch_include_section(sec);
18191816
}
18201817
}
18211818

1819+
list_for_each_entry(sym, &kelf->symbols, list)
1820+
if (sym->sec && is_string_literal_section(sym->sec))
1821+
sym->include = 1;
1822+
18221823
/* include the NULL symbol */
18231824
list_entry(kelf->symbols.next, struct symbol, list)->include = 1;
18241825
}
@@ -3079,6 +3080,9 @@ static bool need_dynrela(struct kpatch_elf *kelf, struct lookup_table *table,
30793080
{
30803081
struct lookup_result symbol;
30813082

3083+
if (is_debug_section(sec))
3084+
return false;
3085+
30823086
/*
30833087
* These references are treated specially by the module loader and
30843088
* should never be converted to dynrelas.

0 commit comments

Comments
 (0)