No description
Find a file
Mihai Serban 721c9ce4a5 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 24a3cbfa73)

Change-Id: I2d217f1c8d48553eb4a37457dbf27fff54051cf9
2016-04-28 06:27:39 -07:00
adb adb: fix adb usb operations on device. 2016-04-26 17:43:14 -07:00
adf Adf: Remove unused variable 2015-07-27 22:08:16 -07:00
base Merge "base: Avoid compilation error when compiled with -Wdangling-else." into nyc-dev 2016-03-30 19:29:11 +00:00
bootstat bootstat: Differentiate system update boot times. 2016-04-11 10:17:46 -07:00
cpio fs_config: replace getenv('OUT') by new fs_config parameter 2015-07-09 21:47:07 -07:00
crash_reporter crash_reporter_tests: Compile only on 'eng' builds. 2016-02-04 13:56:25 -08:00
debuggerd Connect to activity manager as root. 2016-04-20 11:30:33 -07:00
fastboot Also archive adb.exe/fastboot.exe when building win_sdk. 2016-03-03 15:46:50 -08:00
fingerprintd Fingerprint: Plumb enumerate support. 2015-12-04 10:07:55 -08:00
fs_mgr resolve merge conflicts of 2857bd1 to nyc-dev 2016-04-12 14:28:09 -07:00
gatekeeperd Move gatekeeperd to system-background cpuset. 2016-04-15 14:29:40 +02:00
healthd healthd: Add charge counter for BatteryProperties. 2016-04-07 23:10:14 +00:00
include Merge "Move canned_fs_config into libcutils" into nyc-dev 2016-04-08 17:39:05 +00:00
init ueventd: relabel block devices nodes when processing subsequent add events 2016-04-28 06:27:39 -07:00
libbacktrace libbacktrace: only build libbacktrace_offline static library. 2016-04-14 14:37:37 -07:00
libbinderwrapper libbinderwrapper: Add BinderWrapper::GetOrCreateInstance() 2016-01-04 12:56:27 -08:00
libcutils Merge "Update get_sched_policy to return TOP_APP correctly." into nyc-dev 2016-04-11 10:31:26 +00:00
libdiskconfig am eb075e28: am c8179498: am 2f62edf7: Merge "libdiskconfig: Turn on -Werror" 2014-05-21 21:19:27 +00:00
libion am 8d2cd035: am 2ddb9cb1: am ed43be39: Merge "Remove LOCAL_ADDITIONAL_DEPENDENCIES in cases where it\'s not needed." 2015-04-02 22:07:16 +00:00
liblog liblog: android_log_isloggable failing apct 2016-04-19 07:23:17 -07:00
libmemtrack Remove a hack for getting libpagerank's headers. 2015-09-22 22:35:30 -07:00
libmemunreachable Fix mac build 2016-03-07 17:19:28 -08:00
libmincrypt Enable clang compilation. 2015-05-15 16:13:19 -07:00
libnativebridge Revert "nativebrige: log code_cache access errors to stderr as well" 2016-01-27 17:53:20 +00:00
libnativeloader native_loader: Use ANDROID_ROOT environment variable 2016-04-27 13:43:33 -07:00
libnetutils Set IFA_BROADCAST during IPv4 RTM_NEWADDRs 2016-03-31 16:00:40 +09:00
libpackagelistparser packagelistparser: rename to libpackagelistparser 2015-11-05 12:12:38 -08:00
libpixelflinger Use dlmalloc from external/dlmalloc instead of bionic/. 2016-01-22 11:04:35 -08:00
libprocessgroup Don't use mem cgroups for pid accounting. 2016-03-18 15:35:48 +01:00
libsparse Fix static analyzer issues caught by clang 2016-02-01 11:19:26 -08:00
libsuspend Adds a parameter to the wakeup_callback to report sucessful wakeup or suspend aborts. 2015-06-25 13:15:22 -07:00
libsync Fix isValid() condition for libsync tests 2015-11-05 10:07:53 -08:00
libsysutils Tolerate RTM_DELADDR messages from deleted interfaces. 2016-02-16 23:12:26 +09:00
libusbhost libusbhost: add usb_device_reset 2016-01-13 16:01:42 -08:00
libutils system/core: Make Thread::run threadName argument required 2016-03-12 21:32:52 -08:00
libziparchive libziparchive: ensure ReadAtOffset is atomic 2016-03-09 17:17:19 -08:00
lmkd lmkd: subscribe to low mempressure events. 2016-02-09 11:25:18 +01:00
logcat logcat: apct test failures 2016-04-15 16:38:42 +00:00
logd logd: check return values 2016-03-02 11:37:21 -08:00
logwrapper am eaf04aa0: am 3b94cef1: Merge "Add FORK_EXECVP_OPTION_CAPTURE_OUTPUT to logwrap.h" 2015-08-22 02:40:51 +00:00
metricsd Merge "metricsd: Create a brillo::MessageLoop." 2016-02-04 23:38:54 +00:00
mkbootimg mkbootimg: use int for os_version and os_patch_level 2016-03-29 18:27:13 -07:00
reboot reboot: Turn on -Werror 2014-05-21 12:58:38 -07:00
rootdir Merge "Don't start defaultcrypto twice" into nyc-dev 2016-04-19 14:44:26 +00:00
run-as run-as should accept /data/user/0 symlink 2016-03-21 07:56:46 -06:00
sdcard Add support for FUSE_CANONICAL_PATH 2016-04-25 20:42:57 -07:00
toolbox Allow building with Python 3.x 2016-03-08 08:18:34 -08:00
trusty [core][trusty] add gatekeeper module 2015-11-12 12:19:48 -08:00
tzdatacheck Track rename of base/ to android-base/. 2015-12-04 22:00:26 -08:00
.gitignore Ignore adb/*.pyc files 2015-08-11 12:59:58 -07:00
Android.mk Remove the simulator target from all makefiles. 2011-07-11 22:12:32 -07:00
CleanSpec.mk Add a CleanSpec for grep/toolbox. 2015-03-22 18:04:54 -07:00
MODULE_LICENSE_APACHE2 auto import from //depot/cupcake/@135843 2013-07-30 13:56:49 -07:00
NOTICE Fix omission in NOTICE file. 2013-07-30 13:56:55 -07:00