[PATCH] osmo-gsm-tester[master]: util: Add change_elf_rpath API

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Pau Espin Pedrol gerrit-no-reply at lists.osmocom.org
Thu Oct 26 09:53:09 UTC 2017


Review at  https://gerrit.osmocom.org/4424

util: Add change_elf_rpath API

Linux dynamic loader avoids loading shared libraries from env vars such
as LD_LIBRALY_PATH for ELF binaries which have capabilitiy flags enabled
for security reasons. For these binaries, we modify the RPATH of the ELF
header to tell the loader where to find the libraries.

Change-Id: Ibc356957fb3dbcf9947bfe96b671ec8c7ede33ff
---
M src/osmo_gsm_tester/util.py
1 file changed, 11 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-gsm-tester refs/changes/24/4424/1

diff --git a/src/osmo_gsm_tester/util.py b/src/osmo_gsm_tester/util.py
index e0de997..d192719 100644
--- a/src/osmo_gsm_tester/util.py
+++ b/src/osmo_gsm_tester/util.py
@@ -38,6 +38,17 @@
         return path
     return path + ':' + lp
 
+def change_elf_rpath(binary, paths):
+    '''Change RPATH field in ELF executable binary.
+    This feature can be used to tell the loaded to load the trial libraries, as
+    LD_LIBRARY_PATH is disabled for paths with modified capabilities.'''
+    proc = subprocess.Popen(['patchelf', '--set-rpath', paths, binary], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
+    (stdoutdata, stderrdata) = proc.communicate()
+    if proc.returncode != 0:
+        print('stdout: %s' % stdoutdata)
+        print('stderr: %s' % stderrdata)
+        raise RuntimeError('change_elf_rpath finished with err code %d' % proc.returncode)
+
 def ip_to_iface(ip):
     try:
         for iface in os.listdir('/sys/class/net'):

-- 
To view, visit https://gerrit.osmocom.org/4424
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibc356957fb3dbcf9947bfe96b671ec8c7ede33ff
Gerrit-PatchSet: 1
Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de>



More information about the gerrit-log mailing list