Skip to content

Commit 2565678

Browse files
authored
Merge pull request #1265 from rfrohl/fix_1263
Change test_sysctl_probe_all to succeed for non-root users
2 parents 439c095 + 1e475b3 commit 2565678

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

tests/probes/sysctl/test_sysctl_probe_all.sh

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,30 @@
44

55
set -e -o pipefail
66

7+
# on some systems sysctl might live in sbin, which can cause problems for
8+
# non root users
9+
PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
10+
11+
# non root users are not able to access some kernel params, so they get blacklisted
12+
SYSCTL_BLACKLIST='
13+
fs.protected_hardlinks
14+
fs.protected_symlinks
15+
kernel.cad_pid
16+
kernel.unprivileged_userns_apparmor_policy
17+
kernel.usermodehelper.bset
18+
kernel.usermodehelper.inheritable
19+
net.core.bpf_jit_harden
20+
net.core.bpf_jit_kallsyms
21+
net.ipv4.tcp_fastopen_key
22+
stable_secret
23+
vm.mmap_rnd_bits
24+
vm.mmap_rnd_compat_bits
25+
vm.stat_refresh'
26+
27+
SYSCTL_BLACKLIST_REGEX="$(printf '\|%s' $SYSCTL_BLACKLIST)"
28+
# strip leading '\|'
29+
SYSCTL_BLACKLIST_REGEX=${SYSCTL_BLACKLIST_REGEX:2}
30+
731
function perform_test {
832
probecheck "sysctl" || return 255
933

@@ -24,9 +48,9 @@ $OSCAP oval eval --results $result $srcdir/test_sysctl_probe_all.oval.xml > /dev
2448
# sysctl has duplicities in output
2549
# hide permission errors like: "sysctl: permission denied on key 'fs.protected_hardlinks'"
2650
# kernel parameters might use "/" and "." separators interchangeably - normalizing
27-
sysctl -aN --deprecated 2> /dev/null | tr "/" "." | sort -u > "$sysctlNames"
51+
sysctl -aN --deprecated 2> /dev/null | grep -v $SYSCTL_BLACKLIST_REGEX | tr "/" "." | sort -u > "$sysctlNames"
2852

29-
grep unix-sys:name "$result" | sed -E 's;.*>(.*)<.*;\1;g' | sort > "$ourNames"
53+
grep unix-sys:name "$result" | grep -v $SYSCTL_BLACKLIST_REGEX | sed -E 's;.*>(.*)<.*;\1;g' | sort > "$ourNames"
3054

3155
# If procps_ver > 3.3.12 we need to filter *stable_secret and vm.stat_refresh
3256
# options from the sysctl output, for more details see

0 commit comments

Comments
 (0)