Skip to contentSkip to conversation

mk: remove library search path from binary

PATCH Superseded Ferruh Yigit 3 participants 8 messages Nov 12, 2019 – Nov 25, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mk: remove library search path from binary

This patch functionally reverts the patch in fixes line to not have any hardcoded library path in the final binary for the security reasons, in case this binary distributed to production environment.

RPATH only added in RTE_DEVEL_BUILD case and this binary shouldn't distributed, but still removing it to be cautious.

Fixes 8919f73bcbaa ("mk: add build directory to library search path")
---
 devtools/test-null.sh | 1 +
 mk/rte.app.mk         | 4 ----
 2 files changed, 1 insertion(+), 4 deletions(-)
devtools/test-null.sh +1 -0
index 9f9a459f7..0fbb403e2 100755
@@ -19,6 +19,7 @@ if [ ! -f "$testpmd" ] ; then
 fi
 
 if ldd $testpmd | grep -q librte_ ; then
+	export LD_LIBRARY_PATH=$build/lib:$LD_LIBRARY_PATH
 	libs='-d librte_mempool_ring.so -d librte_pmd_null.so'
 else
 	libs=
mk/rte.app.mk +0 -4
index 683e3a4e3..077eaee06 100644
@@ -379,10 +379,6 @@ filter-libs = \
 
 LDLIBS := $(call filter-libs,$(LDLIBS))
 
-ifeq ($(RTE_DEVEL_BUILD)$(CONFIG_RTE_BUILD_SHARED_LIB),yy)
-LDFLAGS += -rpath=$(RTE_SDK_BIN)/lib
-endif
-
 MAPFLAGS = [email protected] --cref
 
 .PHONY: all
Signature · 1 line
2.21.0
#1 lore raw

12/11/2019 14:15, Ferruh Yigit:

Quoted 3 lines

This patch functionally reverts the patch in fixes line to not have any hardcoded library path in the final binary for the security reasons, in case this binary distributed to production environment.

What about meson?
There are these rpaths:

	$ORIGIN/../lib
	$ORIGIN/../drivers
Quoted 2 lines

RPATH only added in RTE_DEVEL_BUILD case and this binary shouldn't distributed, but still removing it to be cautious.

For convenience, we could keep adding rpath for internal apps.

devtools/test-null.sh if [ ! -f "$testpmd" ] ; then · line 23

Quoted 6 lines
devtools/test-null.sh +1 -0
 
 if ldd $testpmd | grep -q librte_ ; then
+	export LD_LIBRARY_PATH=$build/lib:$LD_LIBRARY_PATH
 	libs='-d librte_mempool_ring.so -d librte_pmd_null.so'

There is an issue in this change, because $build may be undefined. It can be fixed with adding this line:

+[ -f "$testpmd" ] && build=$(dirname $(dirname $testpmd))

 [ -f "$testpmd" ] || testpmd=$build/app/dpdk-testpmd
 [ -f "$testpmd" ] || testpmd=$build/app/testpmd
#2 lore raw
Quoted 10 lines · Thomas Monjalon

12/11/2019 14:15, Ferruh Yigit:

Quoted 3 lines

This patch functionally reverts the patch in fixes line to not have any hardcoded library path in the final binary for the security reasons, in case this binary distributed to production environment.

What about meson?
There are these rpaths:

	$ORIGIN/../lib
	$ORIGIN/../drivers

Meson uses relative paths based off the file location "$ORIGIN" as you see above. This avoids having a user's home path in the search directories.

However, meson also adjusts the rpath on install, so if you run test-meson-builds.sh and check the rpath on build-x64-default/app/dpdk-testpmd and compare against build-x86-default/install-root/usr/local/bin/dpdk-testpmd you'll see they are different, with the latter having the final install path encoded in it. If we do want to control these, they can be set for binaries using the "build_rpath" and "install_rpath" parameters, though I think the current values are ok.

/Bruce

#3 lore raw
Quoted 24 lines · Bruce Richardson
Quoted 10 lines · Thomas Monjalon

12/11/2019 14:15, Ferruh Yigit:

Quoted 3 lines

This patch functionally reverts the patch in fixes line to not have any hardcoded library path in the final binary for the security reasons, in case this binary distributed to production environment.

What about meson?
There are these rpaths:

	$ORIGIN/../lib
	$ORIGIN/../drivers

Meson uses relative paths based off the file location "$ORIGIN" as you see above. This avoids having a user's home path in the search directories.

However, meson also adjusts the rpath on install, so if you run test-meson-builds.sh and check the rpath on build-x64-default/app/dpdk-testpmd and compare against build-x86-default/install-root/usr/local/bin/dpdk-testpmd you'll see they are different, with the latter having the final install path encoded in it. If we do want to control these, they can be set for binaries using the "build_rpath" and "install_rpath" parameters, though I think the current values are ok.

Quoted 1 line

/Bruce

Apologies for the self-reply, but forgot to include the reference to the relevant parameters [1], and they should apply for both executables and libraries [2].

[1] https://mesonbuild.com/Reference-manual.html#executable
[2] https://mesonbuild.com/Reference-manual.html#library

#4 lore raw
In reply to Thomas Monjalon
Quoted 7 lines · Thomas Monjalon

12/11/2019 14:15, Ferruh Yigit:

Quoted 3 lines

This patch functionally reverts the patch in fixes line to not have any hardcoded library path in the final binary for the security reasons, in case this binary distributed to production environment.

What about meson?
There are these rpaths:

Quoted 8 lines
	$ORIGIN/../lib
	$ORIGIN/../drivers
Quoted 2 lines

RPATH only added in RTE_DEVEL_BUILD case and this binary shouldn't distributed, but still removing it to be cautious.

For convenience, we could keep adding rpath for internal apps.

This was the main intention, but the concern is someone unaware of this capability and distributes a binary that we think it will be internal.

Quoted 13 lines

devtools/test-null.sh if [ ! -f "$testpmd" ] ; then · line 23

Quoted 8 lines
devtools/test-null.sh +1 -0
 
 if ldd $testpmd | grep -q librte_ ; then
+	export LD_LIBRARY_PATH=$build/lib:$LD_LIBRARY_PATH
 	libs='-d librte_mempool_ring.so -d librte_pmd_null.so'

There is an issue in this change, because $build may be undefined. It can be fixed with adding this line:

Quoted 3 lines

+[ -f "$testpmd" ] && build=$(dirname $(dirname $testpmd))

 [ -f "$testpmd" ] || testpmd=$build/app/dpdk-testpmd
 [ -f "$testpmd" ] || testpmd=$build/app/testpmd

'build' is already defined as following at the beginning of the script build=${1:-build}

And if 'build' is wrong/missing, script can't reach to this line at all, because 'testpmd' path found based on 'build' and if 'testpmd' not found, script will exit.

Can you please give more detail what is problem with 'build'?

#5 lore raw

21/11/2019 18:12, Ferruh Yigit:

Quoted 12 lines · Thomas Monjalon
Quoted 11 lines

12/11/2019 14:15, Ferruh Yigit:

Quoted 3 lines

This patch functionally reverts the patch in fixes line to not have any hardcoded library path in the final binary for the security reasons, in case this binary distributed to production environment.

What about meson?
There are these rpaths:

	$ORIGIN/../lib
	$ORIGIN/../drivers
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

RPATH only added in RTE_DEVEL_BUILD case and this binary shouldn't distributed, but still removing it to be cautious.

For convenience, we could keep adding rpath for internal apps.

This was the main intention, but the concern is someone unaware of this capability and distributes a binary that we think it will be internal.

Internal apps are only for developers.
I don't see how there could be a security issue.

Quoted 11 lines
Quoted 11 lines

devtools/test-null.sh if [ ! -f "$testpmd" ] ; then · line 23

Quoted 6 lines
devtools/test-null.sh +1 -0
 
 if ldd $testpmd | grep -q librte_ ; then
+	export LD_LIBRARY_PATH=$build/lib:$LD_LIBRARY_PATH
 	libs='-d librte_mempool_ring.so -d librte_pmd_null.so'

There is an issue in this change, because $build may be undefined. It can be fixed with adding this line:

Quoted 6 lines
Quoted 3 lines

+[ -f "$testpmd" ] && build=$(dirname $(dirname $testpmd))

 [ -f "$testpmd" ] || testpmd=$build/app/dpdk-testpmd
 [ -f "$testpmd" ] || testpmd=$build/app/testpmd

'build' is already defined as following at the beginning of the script build=${1:-build}

Yes, but $1 can be the testpmd path as well, so $build is meaningless.

Quoted 2 lines

And if 'build' is wrong/missing, script can't reach to this line at all, because 'testpmd' path found based on 'build' and if 'testpmd' not found, script will exit.

No, $testpmd can be defined from $1, not based on $build. You missed this comment:

build=${1:-build} # first argument can be the build directory testpmd=$1 # or first argument can be the testpmd path

Quoted 1 line

Can you please give more detail what is problem with 'build'?

If the testpmd path is directly passed as first parameter, build directory is not known.
That's why I suggest getting it with $(dirname $(dirname $testpmd)).

#6 lore raw

PATCH v2 1/1 mk: remove library search path from binary

In reply to Ferruh Yigit

This patch functionally reverts the patch in fixes line to not have any hardcoded library path in the final binary for the security reasons, in case this binary distributed to production environment.

RPATH only added in RTE_DEVEL_BUILD case and this binary shouldn't distributed, but still removing it to be cautious.

Fixes 8919f73bcbaa ("mk: add build directory to library search path")

---
v2:
* set 'build' if provided argument is testpmd path

---
 devtools/test-null.sh | 2 ++
 mk/rte.app.mk         | 4 ----
 2 files changed, 2 insertions(+), 4 deletions(-)
devtools/test-null.sh +2 -0
index 9f9a459f7..afcd8bb29 100755
@@ -11,6 +11,7 @@ coremask=${2:-3} # default using cores 0 and 1
 eal_options=$3
 testpmd_options=$4
 
+[ -f "$testpmd" ] && build=$(dirname $(dirname $testpmd))
 [ -f "$testpmd" ] || testpmd=$build/app/dpdk-testpmd
 [ -f "$testpmd" ] || testpmd=$build/app/testpmd
 if [ ! -f "$testpmd" ] ; then
@@ -19,6 +20,7 @@ if [ ! -f "$testpmd" ] ; then
 fi
 
 if ldd $testpmd | grep -q librte_ ; then
+	export LD_LIBRARY_PATH=$build/lib:$LD_LIBRARY_PATH
 	libs='-d librte_mempool_ring.so -d librte_pmd_null.so'
 else
 	libs=
mk/rte.app.mk +0 -4
index a278552c6..05ea034b9 100644
@@ -379,10 +379,6 @@ filter-libs = \
 
 LDLIBS := $(call filter-libs,$(LDLIBS))
 
-ifeq ($(RTE_DEVEL_BUILD)$(CONFIG_RTE_BUILD_SHARED_LIB),yy)
-LDFLAGS += -rpath=$(RTE_SDK_BIN)/lib
-endif
-
 MAPFLAGS = [email protected] --cref
 
 .PHONY: all
Signature · 1 line
2.21.0
#7 lore raw

22/11/2019 12:30, Ferruh Yigit:

Quoted 4 lines

This patch functionally reverts the patch in fixes line to not have any hardcoded library path in the final binary for the security reasons, in case this binary distributed to production environment.

Quoted 8 lines

RPATH only added in RTE_DEVEL_BUILD case and this binary shouldn't distributed, but still removing it to be cautious.

Fixes 8919f73bcbaa ("mk: add build directory to library search path")

Applied, thanks