From 2975775768a693eae9c59a2807abe7a963da994c Mon Sep 17 00:00:00 2001 From: Josh Poimboeuf Date: Thu, 15 Aug 2019 08:28:56 -0500 Subject: [PATCH] create-diff-object: allow dynamic debug static keys While static keys (jump labels) are currently broken in livepatch, a broken dynamic debug static key is harmless since it just disables dynamically enabled debug printks in the patched code. Fixes: #1021 Signed-off-by: Josh Poimboeuf --- kpatch-build/create-diff-object.c | 25 ++++++++++++++++++++----- test/unit/objs | 2 +- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c index b1118c9..48ba083 100644 --- a/kpatch-build/create-diff-object.c +++ b/kpatch-build/create-diff-object.c @@ -237,6 +237,15 @@ static void kpatch_detect_child_functions(struct kpatch_elf *kelf) } } +static bool is_dynamic_debug_symbol(struct symbol *sym) +{ + if (sym->type == STT_OBJECT && !strcmp(sym->sec->name, "__verbose")) + return true; + if (sym->type == STT_SECTION && !strcmp(sym->name, "__verbose")) + return true; + return false; +} + /* * This function detects whether the given symbol is a "special" static local * variable (for lack of a better term). @@ -261,8 +270,7 @@ static int is_special_static(struct symbol *sym) return 0; /* pr_debug() uses static local variables in the __verbose section */ - if ((sym->type == STT_OBJECT && !strcmp(sym->sec->name, "__verbose")) || - (sym->type == STT_SECTION && !strcmp(sym->name, "__verbose"))) + if (is_dynamic_debug_symbol(sym)) return 1; if (sym->type == STT_SECTION) { @@ -2104,9 +2112,16 @@ static void kpatch_regenerate_special_section(struct kpatch_elf *kelf, if (i != 3) ERROR("BUG: __jump_table has an unexpected format"); - if (strncmp(key->sym->name, "__tracepoint_", 13)) - ERROR("Found a jump label at %s()+0x%x, using key %s. Jump labels aren't currently supported. Use static_key_enabled() instead.", - code->sym->name, code->addend, key->sym->name); + /* inert tracepoints are harmless */ + if (!strncmp(key->sym->name, "__tracepoint_", 13)) + continue; + + /* inert dynamic debug printks are harmless */ + if (is_dynamic_debug_symbol(key->sym)) + continue; + + ERROR("Found a jump label at %s()+0x%x, using key %s. Jump labels aren't currently supported. Use static_key_enabled() instead.", + code->sym->name, code->addend, key->sym->name); continue; } diff --git a/test/unit/objs b/test/unit/objs index 0b34cbb..510a90c 160000 --- a/test/unit/objs +++ b/test/unit/objs @@ -1 +1 @@ -Subproject commit 0b34cbb7e835706615d2295f8c3129a23e19f6e6 +Subproject commit 510a90ca8d35c09574d449ea0f171a7a9baaf087