Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix externalization on Userpsace Livepatching #124

Merged
merged 3 commits into from
Aug 23, 2024

Conversation

giulianobelinassi
Copy link
Collaborator

This PR contains multiple fixes with regard to symbol externalization for what concerns Userspace Livepathing. As follows:

  • Every strong externalized function/variable now contains the attribute used to avoid gcc to remove the variable read on assembly (i.e. inlining the pointer to always be NULL). This most likely also affects kernel livepatching and possibly it went unnoticed so far because of the gcc version they are currently using. Here is an example of this happening for function f, while g is correct.
  • Fix symbol visibility if it is only available on .symtab section. dlsym won't be able to find such symbols, hence they should be strongly externalized rather than weakly.
  • Allow clang-extract to be feed with two DEBUGINFO files: one is the real *.debug file which is found in -debug packages in SUSE Linux, the other is the *.so file. This should not affect kernel livepatching, as they use another mechanism to decide symbol visibility.

The value of the externalized vars are filled by the livepatch system,
not the compiler.  Hence if there are no writes into the variable
the compiler won't generate the instructions to read it.  As an
example:

```
static int aa;
int f(void) { return aa; }
```
generates:
```
  xor eax, eax
  ret
```
Notice how there is no memory read.  Adding the `__attribute__((used))`
to it changes the asm code to:
```
  movl	aa(%rip), %eax
  ret
```
Fixing the issue.

Signed-off-by: Giuliano Belinassi <[email protected]>
In the case the symbol is only available on SYMTAB we can't weakly
externalize it, as the linker will resolve it as not found.

Signed-off-by: Giuliano Belinassi <[email protected]>
SUSE packages contain the stripped .so file with .dynsym and the
debuginfo (.debug) provided in -debuginfo packages.  We need both
of them in Userspace Livepatching since 15.5 for proper analysis.
This commit patches the ElfCache and InlineAnalysis so it can use
both of them.

For kernel we expect it to only use one ELF file for now (the
first one).

Signed-off-by: Giuliano Belinassi <[email protected]>
Copy link
Collaborator

@marcosps marcosps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this problem seen only with LTO? If yes, it should be mentioned here.

Other that than, LGTM

@marcosps
Copy link
Collaborator

(I mean to comment on the first commit only...)

Copy link
Collaborator

@marcosps marcosps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH I don't like much the word "debuginfo" when we just pass plain ELF files, having it debug symbols or not (talking about kernel ELF files). Maybe we could use "elf files" or another name in the future? For now I don't dislike it that much, but using "debuginfo"
everywhere is misleading.

@marcosps
Copy link
Collaborator

I tested here, and it does generate code as before, just adding the new attributes when IBT is not set.

LGTM:

Reviewed-by: Marcos Paulo de Souza [email protected]

@giulianobelinassi
Copy link
Collaborator Author

Is this problem seen only with LTO? If yes, it should be mentioned here.

Other that than, LGTM

No, it happens on default as well.

@giulianobelinassi
Copy link
Collaborator Author

TBH I don't like much the word "debuginfo" when we just pass plain ELF files, having it debug symbols or not (talking about kernel ELF files). Maybe we could use "elf files" or another name in the future? For now I don't dislike it that much, but using "debuginfo" everywhere is misleading.

I kept it as compatibility measure, so we can keep passing -DCE_DEBUGINGO_PATH

@giulianobelinassi giulianobelinassi merged commit 4c858e7 into SUSE:main Aug 23, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants