[MERGED] 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
Mon Nov 6 17:43:02 UTC 2017


Pau Espin Pedrol has submitted this change and it was merged.

Change subject: util: Add change_elf_rpath API
......................................................................


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.

Process class from process module is imported inside the method after
module initialization in order to avoid circular dependency of relative
imports, which is only available since python 3.5.

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

Approvals:
  Pau Espin Pedrol: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/osmo_gsm_tester/util.py b/src/osmo_gsm_tester/util.py
index 1ecbf41..8fb6e19 100644
--- a/src/osmo_gsm_tester/util.py
+++ b/src/osmo_gsm_tester/util.py
@@ -38,6 +38,19 @@
         return path
     return path + ':' + lp
 
+def change_elf_rpath(binary, paths, run_dir):
+    '''
+    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.
+    '''
+    from .process import Process
+    proc = Process('patchelf', run_dir, ['patchelf', '--set-rpath', paths, binary])
+    proc.launch()
+    proc.wait()
+    if proc.result != 0:
+        raise RuntimeError('patchelf finished with err code %d' % proc.result)
+
 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: merged
Gerrit-Change-Id: Ibc356957fb3dbcf9947bfe96b671ec8c7ede33ff
Gerrit-PatchSet: 3
Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Pau Espin Pedrol <pespin at sysmocom.de>



More information about the gerrit-log mailing list