From dabc4e9fa87ce2c029e828bd690cd8f689b71635 Mon Sep 17 00:00:00 2001 From: Pawel Wieczorkiewicz Date: Tue, 5 Nov 2019 15:37:45 +0000 Subject: [PATCH] create-diff-object: more precisely identify .rodata sections This is needed for more precise patchability verification. Only non-special .rodata sections should be subject for such a non-referenced check in kpatch_verify_patchability(). Current check (non-standard, non-rela, non-debug) is too weak and allows also non-rodata sections without referenced symbols to slip through. Detect .rodata section by checking section's type (SHT_PROGBITS), flags (no exec, no write) and finally name prefix. Signed-off-by: Pawel Wieczorkiewicz Reviewed-by: Andra-Irina Paraschiv Reviewed-by: Bjoern Doebel Reviewed-by: Norbert Manthey Reviewed-by: Ross Lagerwall Signed-off-by: Ross Lagerwall --- common.c | 7 +++++++ common.h | 1 + create-diff-object.c | 13 ++++++------- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/common.c b/common.c index 0ddc9fa..8f553ea 100644 --- a/common.c +++ b/common.c @@ -249,6 +249,13 @@ int is_text_section(struct section *sec) (sec->sh.sh_flags & SHF_EXECINSTR)); } +int is_rodata_section(struct section *sec) +{ + return sec->sh.sh_type == SHT_PROGBITS && + !(sec->sh.sh_flags & (SHF_EXECINSTR | SHF_WRITE)) && + !strncmp(sec->name, ".rodata", 7); +} + int is_debug_section(struct section *sec) { char *name; diff --git a/common.h b/common.h index 06e19e7..300e508 100644 --- a/common.h +++ b/common.h @@ -148,6 +148,7 @@ struct symbol *find_symbol_by_index(struct list_head *list, size_t index); struct symbol *find_symbol_by_name(struct list_head *list, const char *name); int is_text_section(struct section *sec); +int is_rodata_section(struct section *sec); int is_debug_section(struct section *sec); int is_rela_section(struct section *sec); int is_standard_section(struct section *sec); diff --git a/create-diff-object.c b/create-diff-object.c index 95e1cf4..8d63940 100644 --- a/create-diff-object.c +++ b/create-diff-object.c @@ -1621,13 +1621,12 @@ static void kpatch_verify_patchability(struct kpatch_elf *kelf) } if (sec->include) { - if (!is_standard_section(sec) && !is_rela_section(sec) && - !is_debug_section(sec) && !is_special_section(sec)) { - if (!is_referenced_section(sec, kelf)) { - log_normal("section %s included, but not referenced\n", - sec->name); - errs++; - } + if (is_rodata_section(sec) && + !is_special_section(sec) && + !is_referenced_section(sec, kelf)) { + log_normal(".rodata section %s included, but not referenced\n", + sec->name); + errs++; } /* Check if a RELA section does not contain any entries with -- 2.39.5