-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change .so load policy and fix symbol visibility problems
Previously, libpulp used RTLD_LAZY in dlopen, which resulted in livepatch that should have failed to apply being applied. In SLE-15-SP4, those patches seems to work regardless of that, but in SP5 it result in problems. Hence, change this policy to RTLD_NOW to force all symbols to be loaded by the linker at patch load time. Also, this commit now encode the symbol references on packer even if not specified in .dsc by capturing it from the .json dumps, which should improve the support for strong externalizations. Signed-off-by: Giuliano Belinassi <[email protected]>
- Loading branch information
1 parent
3b9b86f
commit b11427c
Showing
12 changed files
with
254 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,6 @@ Makefile.in | |
configure | ||
aclocal.m4 | ||
autom4te.cache | ||
*~ | ||
*.swp | ||
dev/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* libpulp - User-space Livepatching Library | ||
* | ||
* Copyright (C) 2024 SUSE Software Solutions GmbH | ||
* | ||
* This file is part of libpulp. | ||
* | ||
* libpulp is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* libpulp is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with libpulp. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/* This function has hidden visibility. We should not be able to do an weak | ||
externalization here. */ | ||
|
||
static char string[] = "This is a hidden string"; | ||
|
||
__attribute__((visibility("hidden"))) | ||
void *get_hidden_address(void) | ||
{ | ||
return string; | ||
} | ||
|
||
void *get_address(void) | ||
{ | ||
return get_hidden_address(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* libpulp - User-space Livepatching Library | ||
* | ||
* Copyright (C) 2024 SUSE Software Solutions GmbH | ||
* | ||
* This file is part of libpulp. | ||
* | ||
* libpulp is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* libpulp is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with libpulp. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <string.h> | ||
|
||
static char string[128]; | ||
|
||
void *get_hidden_address(void); | ||
|
||
void *get_address_lp(void) | ||
{ | ||
strcpy(string, "String from lp "); | ||
strcat(string, get_hidden_address()); | ||
return string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
__ABS_BUILDDIR__/.libs/libvisibility_livepatch1.so | ||
@__ABS_BUILDDIR__/.libs/libvisibility.so.0.json | ||
get_hidden_address:get_address_lp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* libpulp - User-space Livepatching Library | ||
* | ||
* Copyright (C) 2024 SUSE Software Solutions GmbH | ||
* | ||
* This file is part of libpulp. | ||
* | ||
* libpulp is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* libpulp is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with libpulp. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <string.h> | ||
|
||
static char string[128]; | ||
|
||
// Strong externalization of get_hidden_address | ||
static __attribute__((used)) void *(*klpe_get_hidden_address)(void); | ||
|
||
void *get_address_lp(void) | ||
{ | ||
strcpy(string, "String from lp "); | ||
strcat(string, (*klpe_get_hidden_address)()); | ||
return string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
__ABS_BUILDDIR__/.libs/libvisibility_livepatch2.so | ||
@__ABS_BUILDDIR__/.libs/libvisibility.so.0.json | ||
get_address:get_address_lp | ||
#get_hidden_address:klpe_get_hidden_address |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* libpulp - User-space Livepatching Library | ||
* | ||
* Copyright (C) 2024 SUSE Software Solutions GmbH | ||
* | ||
* This file is part of libpulp. | ||
* | ||
* libpulp is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* libpulp is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with libpulp. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <unistd.h> | ||
|
||
void *get_address(void); | ||
|
||
int main(void) | ||
{ | ||
while (1) { | ||
puts("Press ENTER to continue"); | ||
getchar(); | ||
const char *string = get_address(); | ||
puts(string); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# libpulp - User-space Livepatching Library | ||
# | ||
# Copyright (C) 2020-2024 SUSE Software Solutions GmbH | ||
# | ||
# This file is part of libpulp. | ||
# | ||
# libpulp is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU Lesser General Public | ||
# License as published by the Free Software Foundation; either | ||
# version 2.1 of the License, or (at your option) any later version. | ||
# | ||
# libpulp is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with libpulp. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import testsuite | ||
|
||
child = testsuite.spawn('visibility', script=False) | ||
|
||
child.expect('Press ENTER to continue') | ||
child.sendline('') | ||
child.expect('This is a hidden string') | ||
child.expect('Press ENTER to continue') | ||
out = child.livepatch('.libs/libvisibility_livepatch1.so', | ||
sanity=False, capture_tool_output=True) | ||
|
||
child.sendline('') | ||
child.expect('This is a hidden string') | ||
|
||
# Check if we can't apply the above patch. | ||
if out.find('Failure in dlopen') < 0: | ||
child.close(force=True) | ||
exit(1) | ||
|
||
# Now try to apply the patch with strong externalization | ||
child.expect('Press ENTER to continue') | ||
child.livepatch('.libs/libvisibility_livepatch2.so') | ||
|
||
child.sendline('') | ||
child.expect('String from lp This is a hidden string') | ||
|
||
child.close(force=True) | ||
exit(0) |
Oops, something went wrong.