From 0506b18a3655562ad32ee279ba394f9869faf995 Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Thu, 23 Feb 2017 13:46:09 -0800 Subject: [PATCH] Check setegid() return values The clang static analyzer is complaining that we are not checking the setegid() return value, so let's add these checks. We should never fail to return to AID_ROOT, so fail hard in this case. Bug: 26962034 Test: Boot bullhead Test: export WITH_STATIC_ANALYZER=1 and run 'mm' in the project directory Change-Id: I62e95b045c5734305c71502871b6cf17f152edbc --- init/devices.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/init/devices.cpp b/init/devices.cpp index 5f54ff8fd..bd11f5fa4 100644 --- a/init/devices.cpp +++ b/init/devices.cpp @@ -251,7 +251,10 @@ static void make_device(const char *path, * some device nodes, so the uid has to be set with chown() and is still * racy. Fixing the gid race at least fixed the issue with system_server * opening dynamic input devices under the AID_INPUT gid. */ - setegid(gid); + if (setegid(gid)) { + PLOG(ERROR) << "setegid(" << gid << ") for " << path << " device failed"; + goto out; + } /* If the node already exists update its SELinux label to handle cases when * it was created with the wrong context during coldboot procedure. */ if (mknod(path, mode, dev) && (errno == EEXIST) && secontext) { @@ -273,7 +276,9 @@ static void make_device(const char *path, out: chown(path, uid, -1); - setegid(AID_ROOT); + if (setegid(AID_ROOT)) { + PLOG(FATAL) << "setegid(AID_ROOT) failed"; + } if (secontext) { freecon(secontext);