Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o
Cc: Zac Medico <zmedico@g.o>
Subject: [gentoo-portage-dev] [PATCH] ebuild.sh: sandbox write to ${PORTAGE_TMPDIR}/portage (bug 673738)
Date: Wed, 02 Jan 2019 23:56:40
Message-Id: 20190102235342.31717-1-zmedico@gentoo.org
1 In ebuild.sh, grant sandbox write access directly to
2 ${PORTAGE_TMPDIR}/portage, since write access to ${PORTAGE_TMPDIR}
3 itself is not needed. Also, remove the _check_temp_dir symlink
4 check from bug 378403, since a symlink is permissible if write
5 access is granted directly to ${PORTAGE_TMPDIR}/portage.
6
7 Bug: https://bugs.gentoo.org/673738
8 Bug: https://bugs.gentoo.org/378403
9 Signed-off-by: Zac Medico <zmedico@g.o>
10 ---
11 bin/ebuild.sh | 4 ++--
12 lib/portage/package/ebuild/doebuild.py | 27 ++------------------------
13 2 files changed, 4 insertions(+), 27 deletions(-)
14
15 diff --git a/bin/ebuild.sh b/bin/ebuild.sh
16 index 00524d019..978643af7 100755
17 --- a/bin/ebuild.sh
18 +++ b/bin/ebuild.sh
19 @@ -161,8 +161,8 @@ addwrite() { __sb_append_var WRITE "$@" ; }
20 adddeny() { __sb_append_var DENY "$@" ; }
21 addpredict() { __sb_append_var PREDICT "$@" ; }
22
23 -addwrite "${PORTAGE_TMPDIR}"
24 -addread "/:${PORTAGE_TMPDIR}"
25 +addwrite "${PORTAGE_TMPDIR}/portage"
26 +addread "/:${PORTAGE_TMPDIR}/portage"
27 [[ -n ${PORTAGE_GPG_DIR} ]] && addpredict "${PORTAGE_GPG_DIR}"
28
29 # Avoid sandbox violations in temporary directories.
30 diff --git a/lib/portage/package/ebuild/doebuild.py b/lib/portage/package/ebuild/doebuild.py
31 index 2dd458835..baebb9a27 100644
32 --- a/lib/portage/package/ebuild/doebuild.py
33 +++ b/lib/portage/package/ebuild/doebuild.py
34 @@ -82,6 +82,7 @@ from portage.util import ( apply_recursive_permissions,
35 from portage.util.cpuinfo import get_cpu_count
36 from portage.util.lafilefixer import rewrite_lafile
37 from portage.util.compression_probe import _compressors
38 +from portage.util.path import first_existing
39 from portage.util.socks5 import get_socks5_proxy
40 from portage.versions import _pkgsplit
41 from _emerge.BinpkgEnvExtractor import BinpkgEnvExtractor
42 @@ -1296,31 +1297,7 @@ def _check_temp_dir(settings):
43 # as some people use a separate PORTAGE_TMPDIR mount
44 # we prefer that as the checks below would otherwise be pointless
45 # for those people.
46 - tmpdir = os.path.realpath(settings["PORTAGE_TMPDIR"])
47 - if os.path.exists(os.path.join(tmpdir, "portage")):
48 - checkdir = os.path.realpath(os.path.join(tmpdir, "portage"))
49 - if ("sandbox" in settings.features or
50 - "usersandox" in settings.features) and \
51 - not checkdir.startswith(tmpdir + os.sep):
52 - msg = _("The 'portage' subdirectory of the directory "
53 - "referenced by the PORTAGE_TMPDIR variable appears to be "
54 - "a symlink. In order to avoid sandbox violations (see bug "
55 - "#378403), you must adjust PORTAGE_TMPDIR instead of using "
56 - "the symlink located at '%s'. A suitable PORTAGE_TMPDIR "
57 - "setting would be '%s'.") % \
58 - (os.path.join(tmpdir, "portage"), checkdir)
59 - lines = []
60 - lines.append("")
61 - lines.append("")
62 - lines.extend(wrap(msg, 72))
63 - lines.append("")
64 - for line in lines:
65 - if line:
66 - line = "!!! %s" % (line,)
67 - writemsg("%s\n" % (line,), noiselevel=-1)
68 - return 1
69 - else:
70 - checkdir = tmpdir
71 + checkdir = first_existing(os.path.join(settings["PORTAGE_TMPDIR"], "portage"))
72
73 if not os.access(checkdir, os.W_OK):
74 writemsg(_("%s is not writable.\n"
75 --
76 2.18.1