linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* /proc/kallsyms shows undefined symbols for livepatch modules
@ 2018-06-02 17:32 Josh Poimboeuf
  2018-06-04  8:05 ` Jessica Yu
  0 siblings, 1 reply; 12+ messages in thread
From: Josh Poimboeuf @ 2018-06-02 17:32 UTC (permalink / raw)
  To: Jessica Yu; +Cc: linux-kernel, live-patching

Hi Jessica,

I found a bug:

  [root@f25 ~]# modprobe livepatch-sample
  [root@f25 ~]# grep ' u ' /proc/kallsyms
  ffffffff81161080 u klp_enable_patch	[livepatch_sample]
  ffffffff81a01800 u __fentry__	[livepatch_sample]
  ffffffff81161250 u klp_unregister_patch	[livepatch_sample]
  ffffffff81161870 u klp_register_patch	[livepatch_sample]
  ffffffff8131f0b0 u seq_printf	[livepatch_sample]

Notice that livepatch modules' undefined symbols are showing up in
/proc/kallsyms.  This can confuse klp_find_object_symbol() which can
cause subtle bugs in livepatch.

I stared at the module kallsyms code for a bit, but I don't see the bug.
Maybe it has something to do with how we save the symbol table in
copy_module_elf().  Any ideas?

-- 
Josh

^ permalink raw reply	[flat|nested] 12+ messages in thread
* [PATCH] module: exclude SHN_UNDEF symbols from kallsyms api
@ 2018-06-05  8:42 Jessica Yu
  2018-06-05 13:57 ` Josh Poimboeuf
  0 siblings, 1 reply; 12+ messages in thread
From: Jessica Yu @ 2018-06-05  8:42 UTC (permalink / raw)
  To: linux-kernel; +Cc: Josh Poimboeuf, live-patching, Jessica Yu

Livepatch modules are special in that we preserve their entire symbol
tables in order to be able to apply relocations after module load. The
unwanted side effect of this is that undefined (SHN_UNDEF) symbols of
livepatch modules are accessible via the kallsyms api and this can
confuse symbol resolution in livepatch (klp_find_object_symbol()) and
cause subtle bugs in livepatch.

Have the module kallsyms api skip over SHN_UNDEF symbols. These symbols
are usually not available for normal modules anyway as we cut down their
symbol tables to just the core (non-undefined) symbols, so this should
really just affect livepatch modules. Note that this patch doesn't
affect the display of undefined symbols in /proc/kallsyms.

Reported-by: Josh Poimboeuf <jpoimboe@redhat.com>
Tested-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Jessica Yu <jeyu@kernel.org>
---
 kernel/module.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/kernel/module.c b/kernel/module.c
index c9bea7f2b43e..dfa61490b37d 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -4070,7 +4070,7 @@ static unsigned long mod_find_symname(struct module *mod, const char *name)
 
 	for (i = 0; i < kallsyms->num_symtab; i++)
 		if (strcmp(name, symname(kallsyms, i)) == 0 &&
-		    kallsyms->symtab[i].st_info != 'U')
+		    kallsyms->symtab[i].st_shndx != SHN_UNDEF)
 			return kallsyms->symtab[i].st_value;
 	return 0;
 }
@@ -4116,6 +4116,10 @@ int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
 		if (mod->state == MODULE_STATE_UNFORMED)
 			continue;
 		for (i = 0; i < kallsyms->num_symtab; i++) {
+
+			if (kallsyms->symtab[i].st_shndx == SHN_UNDEF)
+				continue;
+
 			ret = fn(data, symname(kallsyms, i),
 				 mod, kallsyms->symtab[i].st_value);
 			if (ret != 0)
-- 
2.16.3

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2018-06-05 13:57 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-02 17:32 /proc/kallsyms shows undefined symbols for livepatch modules Josh Poimboeuf
2018-06-04  8:05 ` Jessica Yu
2018-06-04  9:54   ` Jessica Yu
2018-06-04 13:01     ` [PATCH] module: exclude SHN_UNDEF symbols from kallsyms api Jessica Yu
2018-06-04 13:16       ` Josh Poimboeuf
2018-06-04 14:05         ` Jessica Yu
2018-06-04 14:54           ` Josh Poimboeuf
2018-06-04 22:56             ` Josh Poimboeuf
2018-06-04 23:02               ` Josh Poimboeuf
2018-06-05  7:39                 ` Jessica Yu
2018-06-05  8:42 Jessica Yu
2018-06-05 13:57 ` Josh Poimboeuf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).