Skip to content

Commit ba8a4f2

Browse files
committed
Add test that LD_LIBRARY_PATH doesn't have any effect
1 parent ae0a01d commit ba8a4f2

File tree

4 files changed

+49
-6
lines changed

4 files changed

+49
-6
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242

4343
- name: Run all E2E tests
4444
working-directory: test-framework
45-
run: cargo test -p e2e-tests
45+
run: cargo test -p e2e-tests --features apparmor
4646

4747
- name: prevent the cache from growing too large
4848
run: |

test-framework/e2e-tests/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ version = "0.0.0"
66

77
[dependencies]
88
sudo-test.path = "../sudo-test"
9+
10+
[features]
11+
apparmor = ["sudo-test/apparmor"]

test-framework/e2e-tests/src/lib.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,48 @@ fn sanity_check() {
1313
"you must set `SUDO_UNDER_TEST=ours` when running this test suite"
1414
);
1515
}
16+
17+
#[test]
18+
#[cfg(feature = "apparmor")]
19+
fn dlopen_apparmor_ignores_ld_library_path() -> Result<(), Box<dyn std::error::Error>> {
20+
use sudo_test::{Command, Env};
21+
22+
let env = Env("foo ALL=(ALL:ALL) APPARMOR_PROFILE=docker-default NOPASSWD: ALL")
23+
.file(
24+
"/tmp/crash_me.c",
25+
"#include <stdlib.h>
26+
27+
void __attribute__((constructor)) do_not_load() {
28+
abort();
29+
}
30+
",
31+
)
32+
.user("foo")
33+
.apparmor("unconfined")
34+
.build();
35+
36+
Command::new("gcc")
37+
.args(["/tmp/crash_me.c", "-shared", "-o", "/tmp/libapparmor.so.1"])
38+
.output(&env)
39+
.assert_success();
40+
41+
let output = Command::new("sh")
42+
.args([
43+
"-c",
44+
"LD_LIBRARY_PATH=/tmp sudo -s cat /proc/\\$\\$/attr/current",
45+
])
46+
.as_user("foo")
47+
.output(&env);
48+
49+
output.assert_success();
50+
assert_eq!(output.stdout(), "docker-default (enforce)");
51+
52+
let output = Command::new("sh")
53+
.args(["-c", "LD_PRELOAD=/tmp/libapparmor.so.1 ls"])
54+
.output(&env);
55+
56+
output.assert_exit_code(134); // SIGABRT
57+
assert_eq!(output.stderr(), "Aborted (core dumped)");
58+
59+
Ok(())
60+
}

test-framework/sudo-compliance-tests/src/sudo/apparmor.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ fn can_switch_the_apparmor_profile() -> Result<()> {
1111
let output = Command::new("sudo")
1212
.args(["-s", "cat", "/proc/$$/attr/current"])
1313
.output(&env);
14-
dbg!(&output);
1514

1615
output.assert_success();
1716
assert_eq!(output.stdout(), "docker-default (enforce)");
@@ -25,8 +24,6 @@ fn cannot_switch_to_nonexisting_profile() -> Result<()> {
2524

2625
let output = Command::new("sudo").arg("true").output(&env);
2726

28-
dbg!(&output);
29-
3027
output.assert_exit_code(1);
3128
assert_contains!(output.stderr(), "unable to change AppArmor profile");
3229

@@ -44,7 +41,6 @@ Defaults apparmor_profile=docker-default
4441
let output = Command::new("sudo")
4542
.args(["-s", "cat", "/proc/$$/attr/current"])
4643
.output(&env);
47-
dbg!(&output);
4844

4945
output.assert_success();
5046
assert_eq!(output.stdout(), "docker-default (enforce)");
@@ -63,7 +59,6 @@ Defaults apparmor_profile=docker-default
6359
let output = Command::new("sudo")
6460
.args(["-s", "cat", "/proc/$$/attr/current"])
6561
.output(&env);
66-
dbg!(&output);
6762

6863
output.assert_success();
6964
assert_eq!(output.stdout(), "unconfined");

0 commit comments

Comments
 (0)