Skip to content

Commit

Permalink
um: Mark all kernel symbols as local
Browse files Browse the repository at this point in the history
[ Upstream commit d5027ca ]

Ritesh reported a bug [1] against UML, noting that it crashed on
startup. The backtrace shows the following (heavily redacted):

(gdb) bt
...
 MiCode#26 0x0000000060015b5d in sem_init () at ipc/sem.c:268
 MiCode#27 0x00007f89906d92f7 in ?? () from /lib/x86_64-linux-gnu/libcom_err.so.2
 MiCode#28 0x00007f8990ab8fb2 in call_init (...) at dl-init.c:72
...
 MiCode#40 0x00007f89909bf3a6 in nss_load_library (...) at nsswitch.c:359
...
 MiCode#44 0x00007f8990895e35 in _nss_compat_getgrnam_r (...) at nss_compat/compat-grp.c:486
 MiCode#45 0x00007f8990968b85 in __getgrnam_r [...]
 MiCode#46 0x00007f89909d6b77 in grantpt [...]
 MiCode#47 0x00007f8990a9394e in __GI_openpty [...]
 MiCode#48 0x00000000604a1f65 in openpty_cb (...) at arch/um/os-Linux/sigio.c:407
 MiCode#49 0x00000000604a58d0 in start_idle_thread (...) at arch/um/os-Linux/skas/process.c:598
 MiCode#50 0x0000000060004a3d in start_uml () at arch/um/kernel/skas/process.c:45
 MiCode#51 0x00000000600047b2 in linux_main (...) at arch/um/kernel/um_arch.c:334
 MiCode#52 0x000000006000574f in main (...) at arch/um/os-Linux/main.c:144

indicating that the UML function openpty_cb() calls openpty(),
which internally calls __getgrnam_r(), which causes the nsswitch
machinery to get started.

This loads, through lots of indirection that I snipped, the
libcom_err.so.2 library, which (in an unknown function, "??")
calls sem_init().

Now, of course it wants to get libpthread's sem_init(), since
it's linked against libpthread. However, the dynamic linker
looks up that symbol against the binary first, and gets the
kernel's sem_init().

Hajime Tazaki noted that "objcopy -L" can localize a symbol,
so the dynamic linker wouldn't do the lookup this way. I tried,
but for some reason that didn't seem to work.

Doing the same thing in the linker script instead does seem to
work, though I cannot entirely explain - it *also* works if I
just add "VERSION { { global: *; }; }" instead, indicating that
something else is happening that I don't really understand. It
may be that explicitly doing that marks them with some kind of
empty version, and that's different from the default.

Explicitly marking them with a version breaks kallsyms, so that
doesn't seem to be possible.

Marking all the symbols as local seems correct, and does seem
to address the issue, so do that. Also do it for static link,
nsswitch libraries could still be loaded there.

[1] https://bugs.debian.org/983379

Reported-by: Ritesh Raj Sarraf <rrs@debian.org>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Acked-By: Anton Ivanov <anton.ivanov@cambridgegreys.com>
Tested-By: Ritesh Raj Sarraf <rrs@debian.org>
Signed-off-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
jmberg-intel authored and gregkh committed May 22, 2021
1 parent d81519a commit fffa02e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions arch/um/kernel/dyn.lds.S
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ OUTPUT_ARCH(ELF_ARCH)
ENTRY(_start)
jiffies = jiffies_64;

VERSION {
{
local: *;
};
}

SECTIONS
{
PROVIDE (__executable_start = START);
Expand Down
6 changes: 6 additions & 0 deletions arch/um/kernel/uml.lds.S
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ OUTPUT_ARCH(ELF_ARCH)
ENTRY(_start)
jiffies = jiffies_64;

VERSION {
{
local: *;
};
}

SECTIONS
{
/* This must contain the right address - not quite the default ELF one.*/
Expand Down

0 comments on commit fffa02e

Please sign in to comment.