ueventd: relabel block devices nodes when processing subsequent add events

am: 721c9ce

* commit '721c9ce4a55c13716f263dc7a9cbda92b349b4b7':
  ueventd: relabel block devices nodes when processing subsequent add events

Change-Id: I148427f531764e1baa4b19faa14274c0bd03851e
This commit is contained in:
Mihai Serban 2016-04-28 16:36:39 +00:00 committed by android-build-merger
commit f375bf38aa

View file

@ -242,7 +242,11 @@ static void make_device(const char *path,
mode = get_device_perm(path, links, &uid, &gid) | (block ? S_IFBLK : S_IFCHR);
selabel_lookup_best_match(sehandle, &secontext, path, links, mode);
if (selabel_lookup_best_match(sehandle, &secontext, path, links, mode)) {
ERROR("Device '%s' not created; cannot find SELinux label (%s)\n",
path, strerror(errno));
return;
}
setfscreatecon(secontext);
dev = makedev(major, minor);
@ -252,14 +256,19 @@ static void make_device(const char *path,
* racy. Fixing the gid race at least fixed the issue with system_server
* opening dynamic input devices under the AID_INPUT gid. */
setegid(gid);
mknod(path, mode, dev);
/* 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)) {
if (lsetfilecon(path, secontext)) {
ERROR("Cannot set '%s' SELinux label on '%s' device (%s)\n",
secontext, path, strerror(errno));
}
}
chown(path, uid, -1);
setegid(AID_ROOT);
if (secontext) {
freecon(secontext);
setfscreatecon(NULL);
}
freecon(secontext);
setfscreatecon(NULL);
}
static void add_platform_device(const char *path)