OSDN Git Service

fail explicitly if setuid() fails
authorKeun Soo Yim <yim@google.com>
Thu, 14 Apr 2016 00:17:52 +0000 (17:17 -0700)
committerKeun Soo Yim <yim@google.com>
Thu, 14 Apr 2016 01:43:26 +0000 (01:43 +0000)
otherwise, the following code can be executed
with unintended privileges.

bug:28178548
Change-Id: I265f8c0e1693344a675cc2623968db816309b1f4

rild/rild.c

index b10329b..c5d2315 100644 (file)
@@ -105,7 +105,10 @@ void switchUser() {
     char debuggable[PROP_VALUE_MAX];
 
     prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);
-    setuid(AID_RADIO);
+    if (setresuid(AID_RADIO, AID_RADIO, AID_RADIO) == -1) {
+        RLOGE("setresuid failed: %s", strerror(errno));
+        exit(EXIT_FAILURE);
+    }
 
     struct __user_cap_header_struct header;
     memset(&header, 0, sizeof(header));