OSDN Git Service

Zygote: set PR_SET_NO_NEW_PRIVS
authorNick Kralevich <nnk@google.com>
Mon, 4 Mar 2013 19:38:30 +0000 (11:38 -0800)
committerNick Kralevich <nnk@google.com>
Mon, 4 Mar 2013 20:07:44 +0000 (12:07 -0800)
call prctl(PR_SET_NO_NEW_PRIVS, 1) to prevent Zygote and zygote
spawned applications from aquiring new privileges.

Change-Id: I69bbf6bb5b01b877de414ecad43d3dffbd5fcea0

vm/Init.cpp

index 35c1085..9169a5d 100644 (file)
@@ -28,6 +28,9 @@
 #include <linux/fs.h>
 #include <cutils/fs.h>
 #include <unistd.h>
+#ifdef HAVE_ANDROID_OS
+#include <sys/prctl.h>
+#endif
 
 #include "Dalvik.h"
 #include "test/Test.h"
@@ -1711,6 +1714,20 @@ static bool initZygote()
         return -1;
     }
 
+#ifdef HAVE_ANDROID_OS
+    if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) < 0) {
+        if (errno == EINVAL) {
+            SLOGW("PR_SET_NO_NEW_PRIVS failed. "
+                  "Is your kernel compiled correctly?: %s", strerror(errno));
+            // Don't return -1 here, since it's expected that not all
+            // kernels will support this option.
+        } else {
+            SLOGW("PR_SET_NO_NEW_PRIVS failed: %s", strerror(errno));
+            return -1;
+        }
+    }
+#endif
+
     return true;
 }