summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Roland Levillain <rpl@google.com> 2019-01-29 18:07:59 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2019-01-29 18:07:59 +0000
commitd1569ad0045cc1b61ab6cc708d838de5386fbbc5 (patch)
tree43f67e3427a489f482701bc2aa33b1bd7cacfc7c
parent058cb9364418131f32297320d9013c225f46d508 (diff)
parent8d276818c6d672139dad5426de6f22b58f80a5b2 (diff)
Merge "Restore security context of `/postinstall/apex` earlier in otapreopt_chroot."
-rw-r--r--cmds/installd/otapreopt_chroot.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/cmds/installd/otapreopt_chroot.cpp b/cmds/installd/otapreopt_chroot.cpp
index 9965d588f8..c0f8e91acb 100644
--- a/cmds/installd/otapreopt_chroot.cpp
+++ b/cmds/installd/otapreopt_chroot.cpp
@@ -151,11 +151,26 @@ static int otapreopt_chroot(const int argc, char **arg) {
// chown root root /apex
// restorecon /apex
//
+ // except we perform the `restorecon` step just after mounting the tmpfs
+ // filesystem in /postinstall/apex, so that this directory is correctly
+ // labeled (with type `postinstall_apex_mnt_dir`) and may be manipulated in
+ // following operations (`chmod`, `chown`, etc.) following policies
+ // restricted to `postinstall_apex_mnt_dir`:
+ //
+ // mount tmpfs tmpfs /postinstall/apex nodev noexec nosuid
+ // restorecon /postinstall/apex
+ // chmod 0755 /postinstall/apex
+ // chown root root /postinstall/apex
+ //
if (mount("tmpfs", kPostinstallApexDir, "tmpfs", MS_NODEV | MS_NOEXEC | MS_NOSUID, nullptr)
!= 0) {
PLOG(ERROR) << "Failed to mount tmpfs in " << kPostinstallApexDir;
exit(209);
}
+ if (selinux_android_restorecon(kPostinstallApexDir, 0) < 0) {
+ PLOG(ERROR) << "Failed to restorecon " << kPostinstallApexDir;
+ exit(214);
+ }
if (chmod(kPostinstallApexDir, 0755) != 0) {
PLOG(ERROR) << "Failed to chmod " << kPostinstallApexDir << " to 0755";
exit(210);
@@ -164,10 +179,6 @@ static int otapreopt_chroot(const int argc, char **arg) {
PLOG(ERROR) << "Failed to chown " << kPostinstallApexDir << " to root:root";
exit(211);
}
- if (selinux_android_restorecon(kPostinstallApexDir, 0) < 0) {
- PLOG(ERROR) << "Failed to restorecon " << kPostinstallApexDir;
- exit(212);
- }
// Chdir into /postinstall.
if (chdir("/postinstall") != 0) {