summaryrefslogtreecommitdiff
path: root/libutils/Unicode.cpp
diff options
context:
space:
mode:
authorMihai Serban <mihai.serban@intel.com>2016-04-25 18:22:27 +0300
committerNick Kralevich <nnk@google.com>2016-04-28 06:27:39 -0700
commit721c9ce4a55c13716f263dc7a9cbda92b349b4b7 (patch)
tree16525af4467fea19398ab242cc3a9c594e1acfc9 /libutils/Unicode.cpp
parent0b5651e1588c2fee6a587314993a166a77068974 (diff)
ueventd: relabel block devices nodes when processing subsequent add events
There is a race in ueventd's coldboot procedure that permits creation of device block nodes before platform devices are registered. This happens when the kernel sends events for adding block devices during ueventd's coldboot /sys walk. In this case the device node links used to compute the SELinux context are not known and the node is created under the generic context: u:object_r:block_device:s0. A second add event for block device nodes is triggered after the platform devices are handled by ueventd and the SELinux context is correctly computed but the mknod call fails because the node already exists. This patch handles this error case and updates the node's security context. The race is introduced by the uevent sent from the sdcard device probe function. The issue appears when this uevent is triggered during ueventd's coldboot procedure but before the /sys/devices recursive walk reached the corresponding sdcard platform device path. The backtrace looks something like: 1. ueventd_main() 2. device_init() 3. coldboot("/sys/devices"); 4. do_coldboot() 5. handle_device_fd() 6. handle_device_event() 6.1 handle_block_device_event() 6.2 handle_platform_device_event() Because handle_device_fd() reads all events from the netlink socket it may handle the add events for the sdcard partition nodes send occasionally by the kernel during coldboot /sys walk procedure. If handle_device_event() continues with handle_block_device_event() before handle_platform_device_event() registers the sdcard platform device then handle_block_device_event() will create device nodes without knowing all block device symlinks (get_block_device_symlinks()): 1. handle_device(path=/dev/block/mmcblk0p3, links = NULL) 2. make_device(path=/dev/block/mmcblk0p3, links = NULL) 3. selabel_lookup_best_match(path=/dev/block/mmcblk0p3, links = NULL) returns the default context (u:object_r:block_device:s0) for /dev/block/mmcblk0p3 instead of more specific context like: u:object_r:boot_block_device:s0 4. setfscreatecon(u:object_r:block_device:s0) 5. mknod(/dev/block/mmcblk0p3) So the node is create with the wrong context. Afterwards the coldboot /sys walk continues and make_device() will be called with correct path and links. But even if the secontext is computed correctly this time it will not be applied to the device node because mknod() fails. I see this issue randomly appearing (one time in 10 reboots) on a Minnoboard Turbot with external sdcard as the boot device. BUG=28388946 Signed-off-by: Mihai Serban <mihai.serban@intel.com> (cherry picked from commit 24a3cbfa732dc14c1a559f4ad79e1700fbae888f) Change-Id: I2d217f1c8d48553eb4a37457dbf27fff54051cf9
Diffstat (limited to 'libutils/Unicode.cpp')
0 files changed, 0 insertions, 0 deletions