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

Add support for unexported variables access in live patches #19

Merged
merged 1 commit into from
Aug 15, 2021

Conversation

inconstante
Copy link
Contributor

Read the commit message for more information...

Apart from that, the patch adds new information to the live patch metadata, more specifically, the addresses (offsets from the load address) of data objects, and that means that there is no need to open in-disk files (DSOs) during live patch application to fix references to LOCAL objects.

We should probably copy this mechanism to the other parts of the live patch metadata, so that, in the future, nothing else depends on the target library file being both in-disk and in the exact same version that the target process used (which doesn´t work after package updates).

@inconstante
Copy link
Contributor Author

Commit b45f0f3 disabled optimization in the live patch, otherwise the reference variable disappears.

@inconstante inconstante force-pushed the active/static-data branch 4 times, most recently from 3270175 to d40122a Compare August 6, 2021 15:04
@inconstante
Copy link
Contributor Author

Commit d40122a changes the following:

  • undo the pragma optimize trick, which only worked with GCC;
  • make sure that the reference var is not optimized away or placed into read-only sections by writing to it;
  • fix coding-style issues pointed-out by the CI;
  • fix make distcheck errors;
  • describe the changes to the metadata description file in the manpages and in the README file.

Sorry for flooding the pull request with commits. :B

So far, none of the live patch examples in the test suite needs access
to data objects in the target library, instead, all of them replace
functions that only deal with local variables or function arguments
(either on the stack or in registers). However, direct access to data
objects in the target library is desirable and even required by some
live patches.

If a live patch needs to access a data object that has been exported by
the target library, i.e. a GLOBAL object, the compiler toolchain is able
to generate the relocations that the loader needs. However, when the
data object has not been exported, i.e. a LOCAL object, the toolchain is
unable to generate a reference and fails with an 'undefined reference'
error message.

To bridge this gap, this patch extends the live patch metadata with
information about LOCAL data objects. The information is comprised of
the name of the variable in the target library, the name of a reference
variable in the live patch, as well as the offsets that these two data
objects have within their DSOs. The following example (taken from the
new test case added by this patch) of a live patch description file
provides a clarification:

  1. /run/user/1001/libpulp/tests/.libs/libaccess_livepatch1.so
  2. @/run/user/1001/libpulp/tests/.libs/libaccess.so.0
  3. banner_set:new_banner_set
  4. #banner:ulpr_banner:0000000000004020:0000000000004038

Lines 1 and 2 are not new and inform Libpulp about the in-disk paths to
the live patch DSO and to the target library, respectively. Line 3 is
also not new, and provides a pair of replaced and replacement functions.
Line 4 is new. It is preceded by the '#' character and divided into 4
parts, in a predefined order: 1. the name of the data object in the
target library, 'banner'; 2. the name of another data object,
'ulpr_banner', which sits within the live patch object and is used as a
reference to 'banner'; 3. the offset of 'banner' from the loading
address of the target library; 4. the offset of 'ulpr_banner' from the
loading address of the live patch object.

Then, when a live patch gets applied, Libpulp uses the aforementioned
offsets and makes 'ulpr_banner' point to the loaded address of 'banner',
which makes it possible for the live patch to access the data object in
the target library.

PS: The names of the objects (in the target library and in the live
patch) are not really necessary and, in fact, not used by libpulp.so.
On the other hand, the test infrastructure (tests/offsets.py) uses these
names to automatically create a live patch description file.
@inconstante
Copy link
Contributor Author

Updated branch against current master.

@inconstante inconstante merged commit 2b9327b into SUSE:master Aug 15, 2021
@inconstante inconstante deleted the active/static-data branch August 15, 2021 18:22
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.

1 participant