Skip to content

Commit 077d41a

Browse files
committed
fix(remove-system.map): continue past undeletable files
The deletion loop called `exit 0` on the first System.map that `[ -w ]` rejected, so copies in later locations were never shredded. Where `[ -w ]` passed but shred failed anyway, shred ran as a bare command and tripped the ERR trap that pre.bsh installs, aborting with a "## Please report this bug!" banner and exit 1. Branch on shred's exit status instead of `[ -w ]`, which does not predict removability. Unlinking depends on write permission on the parent directory rather than on the file itself, and an append-only file passes the test yet cannot be unlinked at all. For a full-capability root process the check is also true on a mode 444 file, so it only ever failed on read-only file systems and on files carrying the immutable attribute. Clear the immutable and append-only attributes before each attempt. Per review, a System.map should never be immutable and `chattr +i` would possibly complicate kernel package removal; append-only is cleared on the same grounds, since it blocks removal without affecting `[ -w ]`. Report the files that remain once at the end, under a single wiki link rather than repeating it on every line, and withhold "Done. Success." when anything failed. A file reachable under two names, such as /lib/modules/<version>/build and the source symlink beside it, is listed under each, since both matched and both failed. Iterate an array rather than word-splitting a string with IFS, which a /etc/remove-system.map_pre.d drop-in can set; under `IFS=:` the globs matched nothing, so the script deleted nothing and still exited 0. The removal loop no longer exits early on failure and the script ends in an explicit `exit 0`; a non-zero status would fail the kernel package's postinst hook and the oneshot unit on every boot.
1 parent 7f55b21 commit 077d41a

1 file changed

Lines changed: 31 additions & 18 deletions

File tree

usr/libexec/security-misc/remove-system.map#security-misc-shared

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,44 @@ fi
1212

1313
shopt -s nullglob
1414

15-
system_map_location="/boot/System.map* /usr/src/*/System.map* /lib/modules/*/*/System.map* /System.map*"
15+
system_map_list=( /boot/System.map* /usr/src/*/System.map* /lib/modules/*/*/System.map* /System.map* )
1616

17-
counter=0
18-
for filename in ${system_map_location} ; do
19-
counter=$(( counter + 1 ))
20-
done
21-
22-
if [ "$counter" -ge "1" ]; then
17+
if (( ${#system_map_list[@]} > 0 )); then
2318
echo "INFO: Deleting system.map files..."
2419
fi
2520

21+
failed_list=()
22+
2623
## Removes the System.map files as they are only used for debugging or malware.
27-
for filename in ${system_map_location} ; do
28-
if [ -f "${filename}" ]; then
29-
if [ -w "${filename}" ]; then
30-
## 'shred' with '--verbose' is too chatty. (7 lines)
31-
shred --force --zero -u "${filename}"
32-
echo "INFO: removed '${filename}'"
33-
else
34-
echo "NOTE: Cannot delete '${filename}' - read-only. For details, see: https://www.kicksecure.com/wiki/security-misc#system_map"
35-
exit 0
36-
fi
24+
for filename in "${system_map_list[@]}"; do
25+
if [[ ! -f "${filename}" ]]; then
26+
continue
3727
fi
28+
## The immutable and append-only file attributes ('chattr +i', 'chattr +a')
29+
## prevent deletion. Clear them. A System.map file has no legitimate
30+
## reason to carry either and they would possibly complicate kernel
31+
## package removal.
32+
chattr -ia -- "${filename}" &>/dev/null || true
33+
34+
## 'shred' with '--verbose' is too chatty. (7 lines)
35+
## 'shred' stderr is suppressed because failure is expected on read-only
36+
## file systems. Failures are reported below instead.
37+
if shred --force --zero -u -- "${filename}" 2>/dev/null; then
38+
echo "INFO: removed '${filename}'"
39+
continue
40+
fi
41+
failed_list+=( "${filename}" )
3842
done
3943

40-
if [ "$counter" -ge "1" ]; then
44+
if (( ${#failed_list[@]} > 0 )); then
45+
for filename in "${failed_list[@]}"; do
46+
echo "NOTE: Could not remove '${filename}'."
47+
done
48+
echo "NOTE: For details, see: https://www.kicksecure.com/wiki/security-misc#system_map"
49+
elif (( ${#system_map_list[@]} > 0 )); then
4150
echo "INFO: Done. Success."
4251
fi
52+
53+
## Deliberately exits 0 even on partial failure. A non-zero exit code would fail
54+
## the kernel package's postinst hook and the oneshot unit on every boot.
55+
exit 0

0 commit comments

Comments
 (0)