diff options
author | Narayan Kamath <narayan@google.com> | 2015-01-19 10:20:54 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-01-19 10:20:54 +0000 |
commit | 2e139d5b4cad5f5a1feead93cdf42a8aaf52902e (patch) | |
tree | 0ec298b6fda641f7eef80bda332be13aa0613fd8 /core/java/com | |
parent | f614a9f7ac0ee35d40bdd9aaec08518efaea7f75 (diff) | |
parent | e05f269bfe17065f5a3d291961700e2d9befc345 (diff) | |
download | frameworks_base-2e139d5b4cad5f5a1feead93cdf42a8aaf52902e.zip frameworks_base-2e139d5b4cad5f5a1feead93cdf42a8aaf52902e.tar.gz frameworks_base-2e139d5b4cad5f5a1feead93cdf42a8aaf52902e.tar.bz2 |
am e05f269b: am 96b87a1d: am 4ac5775d: Merge "Fix handling of wrapped processes [part 2]"
* commit 'e05f269bfe17065f5a3d291961700e2d9befc345':
Fix handling of wrapped processes [part 2]
Diffstat (limited to 'core/java/com')
-rw-r--r-- | core/java/com/android/internal/os/ZygoteInit.java | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java index 0fa9a97..e6f3c0a 100644 --- a/core/java/com/android/internal/os/ZygoteInit.java +++ b/core/java/com/android/internal/os/ZygoteInit.java @@ -17,7 +17,6 @@ package com.android.internal.os; import static android.system.OsConstants.POLLIN; -import static android.system.OsConstants.POLLOUT; import static android.system.OsConstants.S_IRWXG; import static android.system.OsConstants.S_IRWXO; @@ -276,11 +275,22 @@ public class ZygoteInit { long startTime = SystemClock.uptimeMillis(); // Drop root perms while running static initializers. - try { - Os.setregid(ROOT_GID, UNPRIVILEGED_GID); - Os.setreuid(ROOT_UID, UNPRIVILEGED_UID); - } catch (ErrnoException ex) { - throw new RuntimeException("Failed to drop root", ex); + final int reuid = Os.getuid(); + final int regid = Os.getgid(); + + // We need to drop root perms only if we're already root. In the case of "wrapped" + // processes (see WrapperInit), this function is called from an unprivileged uid + // and gid. + boolean droppedPriviliges = false; + if (reuid == ROOT_UID && regid == ROOT_GID) { + try { + Os.setregid(ROOT_GID, UNPRIVILEGED_GID); + Os.setreuid(ROOT_UID, UNPRIVILEGED_UID); + } catch (ErrnoException ex) { + throw new RuntimeException("Failed to drop root", ex); + } + + droppedPriviliges = true; } // Alter the target heap utilization. With explicit GCs this @@ -335,12 +345,14 @@ public class ZygoteInit { // Fill in dex caches with classes, fields, and methods brought in by preloading. runtime.preloadDexCaches(); - // Bring back root. We'll need it later. - try { - Os.setreuid(ROOT_UID, ROOT_UID); - Os.setregid(ROOT_GID, ROOT_GID); - } catch (ErrnoException ex) { - throw new RuntimeException("Failed to restore root", ex); + // Bring back root. We'll need it later if we're in the zygote. + if (droppedPriviliges) { + try { + Os.setreuid(ROOT_UID, ROOT_UID); + Os.setregid(ROOT_GID, ROOT_GID); + } catch (ErrnoException ex) { + throw new RuntimeException("Failed to restore root", ex); + } } } } |