Gentoo Archives: gentoo-portage-dev

From: Michael Orlitzky <mjo@g.o>
To: gentoo-portage-dev@l.g.o
Subject: [gentoo-portage-dev] [PATCH 1/2] bin/install-qa-check.d: add new 90bad-bin-owner QA check.
Date: Sun, 29 Jul 2018 17:38:13
Message-Id: 20180729173757.24273-2-mjo@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH 0/2] Two insecure ownership and group-writability QA checks. by Michael Orlitzky
1 System executables that are not owned by root pose a security
2 risk. The owner of the executable is free to modify it at any time;
3 so, for example, he can change a daemon's behavior to make it
4 malicious before the next time the service is started (usually by
5 root).
6
7 On a "normal" system, there is no good reason why the superuser should
8 not own every system executable. This commit adds a new install-time
9 check that reports any such binaries with a QA warning. To avoid false
10 positives, non-"normal" systems (like prefix) are skipped at the moment.
11
12 Bug: https://bugs.gentoo.org/629398
13 ---
14 bin/install-qa-check.d/90bad-bin-owner | 38 ++++++++++++++++++++++++++++++++++
15 1 file changed, 38 insertions(+)
16 create mode 100644 bin/install-qa-check.d/90bad-bin-owner
17
18 diff --git a/bin/install-qa-check.d/90bad-bin-owner b/bin/install-qa-check.d/90bad-bin-owner
19 new file mode 100644
20 index 000000000..188d67a51
21 --- /dev/null
22 +++ b/bin/install-qa-check.d/90bad-bin-owner
23 @@ -0,0 +1,38 @@
24 +# Copyright 1999-2018 Gentoo Foundation
25 +# Distributed under the terms of the GNU General Public License v2
26 +
27 +bad_bin_owner_check() {
28 + # Warn about globally-installed executables (in /bin, /usr/bin, /sbin,
29 + # or /usr/sbin) that are owned by a nonzero UID.
30 +
31 + # This check doesn't work on non-root prefix installations at
32 + # the moment, because every executable therein is owned by a
33 + # nonzero UID.
34 + [[ "${EUID}" -ne "0" || "${PORTAGE_INST_UID}" -ne "0" ]] && return
35 +
36 + local d f found=()
37 +
38 + for d in "${ED%/}/bin" "${ED%/}/usr/bin" "${ED%/}/sbin" "${ED%/}/usr/sbin"; do
39 + [[ -d "${d}" ]] || continue
40 +
41 + # Read the results of the "find" command into the "found" bash array.
42 + # Use -L to catch symlinks whose targets are owned by a non-root user,
43 + # even though it won't catch ABSOLUTE symlinks until the package
44 + # is RE-installed (the first time around, the target won't exist).
45 + while read -r -d '' f; do
46 + found+=( "${f}" )
47 + done < <(find -L "${d}" -maxdepth 1 -type f ! -uid 0 -print0)
48 +
49 + if [[ ${found[@]} ]]; then
50 + eqawarn "system executables owned by nonzero uid:"
51 + for f in "${found[@]}"; do
52 + # Strip off the leading destdir before outputting the path,
53 + # but leave the prefix if there is one.
54 + eqawarn " ${f#${D%/}/}"
55 + done
56 + fi
57 + done
58 +}
59 +
60 +bad_bin_owner_check
61 +:
62 --
63 2.16.4

Replies