Skip to contentSkip to conversation

libsepol/tests: clear loader environment without env -i

PATCH In review Stephen Smalley 1 participant 2 messages Nov 20 SELinux security module

lore
Share & tools
lore

Stephen Smalley

author maintainer
#0 lore raw

PATCH 1/1 libsepol/tests: clear loader environment without env -i

The test-downgrade mkdir was run under env -i so that a host mkdir linked against libselinux does not abort under Asan when LD_LIBRARY_PATH points at the freshly built, instrumented libselinux. On hosts where coreutils is a single multi-call binary linked against libselinux (e.g. Ubuntu 26.04), env itself now loads the instrumented libselinux and fails the same way before it can clear the environment for mkdir.

Clear LD_LIBRARY_PATH and LD_PRELOAD with shell assignments on the mkdir command instead; the shell links against neither. Drop the now-unused ENV variable.

---
 libsepol/tests/Makefile | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
libsepol/tests/Makefile +8 -4
index a47b452d..45e094ce 100644
@@ -1,4 +1,3 @@
-ENV ?= env
 M4 ?= m4 -E -E
 MKDIR ?= mkdir
 EXE ?= libsepol-tests
@@ -61,14 +60,19 @@ clean:
 	rm -f $(policies)
 	rm -f policies/test-downgrade/policy.hi policies/test-downgrade/policy.lo
 
-# mkdir is run in a clean environment created by env -i to avoid failing under ASan with:
+# mkdir is run with the dynamic loader environment variables cleared to avoid
+# failing under ASan with:
 #
 #   ASan runtime does not come first in initial library list;
 #   you should either link runtime to your application or manually preload it with LD_PRELOAD
 #
-# when the source code is built with ASan
+# when the just-built, instrumented libselinux is in LD_LIBRARY_PATH and the
+# host mkdir links against libselinux. Shell assignments are used instead of
+# env -i because env may itself link against libselinux (e.g. single-binary
+# coreutils implementations) and then fails the same way before it can clear
+# the environment.
 test: $(EXE) $(policies) test-conditional-count
-	$(ENV) -i $(MKDIR) -p policies/test-downgrade
+	LD_LIBRARY_PATH= LD_PRELOAD= $(MKDIR) -p policies/test-downgrade
 	../../checkpolicy/checkpolicy -M policies/test-cond/refpolicy-base.conf -o policies/test-downgrade/policy.hi	
 	./$(EXE)
 
Signature · 1 line
2.56.1
author maintainer
#1 lore raw
Quoted 9 lines · Stephen Smalley

The test-downgrade mkdir was run under env -i so that a host mkdir linked against libselinux does not abort under Asan when LD_LIBRARY_PATH points at the freshly built, instrumented libselinux. On hosts where coreutils is a single multi-call binary linked against libselinux (e.g. Ubuntu 26.04), env itself now loads the instrumented libselinux and fails the same way before it can clear the environment for mkdir.

Quoted 5 lines

Clear LD_LIBRARY_PATH and LD_PRELOAD with shell assignments on the mkdir command instead; the shell links against neither. Drop the now-unused ENV variable.

This change is unnecessary given this change to the build-userspace action:
https://lore.kernel.org/selinux/[email protected]/T/#u
so I won't bother applying this one.
We can drop this hackery from the Makefiles entirely with the build-userspace action change but that can come as a follow up change after 3.12 is released.

Quoted 39 lines
---
 libsepol/tests/Makefile | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
libsepol/tests/Makefile +8 -5
index a47b452d..45e094ce 100644
@@ -1,4 +1,3 @@
-ENV ?= env
 M4 ?= m4 -E -E
 MKDIR ?= mkdir
 EXE ?= libsepol-tests
@@ -61,14 +60,19 @@ clean:
        rm -f $(policies)
        rm -f policies/test-downgrade/policy.hi policies/test-downgrade/policy.lo
 
-# mkdir is run in a clean environment created by env -i to avoid failing under ASan with:
+# mkdir is run with the dynamic loader environment variables cleared to avoid
+# failing under ASan with:
 #
 #   ASan runtime does not come first in initial library list;
 #   you should either link runtime to your application or manually preload it with LD_PRELOAD
 #
-# when the source code is built with ASan
+# when the just-built, instrumented libselinux is in LD_LIBRARY_PATH and the
+# host mkdir links against libselinux. Shell assignments are used instead of
+# env -i because env may itself link against libselinux (e.g. single-binary
+# coreutils implementations) and then fails the same way before it can clear
+# the environment.
 test: $(EXE) $(policies) test-conditional-count
-       $(ENV) -i $(MKDIR) -p policies/test-downgrade
+       LD_LIBRARY_PATH= LD_PRELOAD= $(MKDIR) -p policies/test-downgrade
        ../../checkpolicy/checkpolicy -M policies/test-cond/refpolicy-base.conf -o policies/test-downgrade/policy.hi
        ./$(EXE)
 
--

2.56.1