No description
Find a file
Akilesh Kailash fd5562b0a5 init: Wait for snapuserd before starting second stage
This is a race between init process and bionic libc initialization of
snapuserd.

init->fork() ----------------> SecondStageMain() -> PropertyInit()
       |
       |
       v
      execveat ---> __libc_init_common() -> __system_properties_init()
     (snapuserd)

When init process calls PropertyInit(), /dev/__properties__ directory
is created. When bionic libc of snapuserd daemon invokes __system_properties_init
_after_ init process PropertyInit() function is invoked, libc will
try to initialize the property by reading
/system/etc/selinux/plat_property_contexts. Since any reads on /system
has to be served by snapuserd, this specific read from libc cannot be
serviced leading to deadlock.

Reproduce the race by inducing a sleep of 1500ms just before execveat()
so that init process calls PropertyInit() before bionic libc
initialization. This leads to deadlock
immediately and with additional kernel instrumentation with debug
logs confirms the failure:

======================================================
init: Relaunched snapuserd with pid: 428
ext4_file_open: SNAPUSERD: path /system/etc/selinux/plat_property_contexts - Pid: 428 comm 8
ext4_file_read_iter: SNAPUSERD for path: /system/etc/selinux/plat_property_contexts pid: 428 comm 8

[   25.418043][  T428]  ext4_file_read_iter+0x3dc/0x3e0
[   25.423000][  T428]  vfs_read+0x2e0/0x354
[   25.426986][  T428]  ksys_read+0x7c/0xec
[   25.430894][  T428]  __arm64_sys_read+0x20/0x30
[   25.435419][  T428]  el0_svc_common.llvm.17612735770287389485+0xd0/0x1e0
[   25.442095][  T428]  do_el0_svc+0x28/0xa0
[   25.446100][  T428]  el0_svc+0x14/0x24
[   25.449825][  T428]  el0_sync_handler+0x88/0xec
[   25.454343][  T428]  el0_sync+0x1c0/0x200

=====================================================

Fix:

Before starting init second stage, we will wait
for snapuserd daemon to be up and running. We do a simple probe by
reading system partition. This read will eventually be serviced by
daemon confirming that daemon is up and running. Furthermore,
we are still in the kernel domain and sepolicy has not been enforced yet.
Thus, access to these device mapper block devices are ok even though
we may see audit logs.

Note that daemon will re-initialize the __system_property_init()
as part of WaitForSocket() call. This is subtle but important; since
bionic libc initialized had failed silently, it is important
that this re-initialization is done.

Bug: 207298357
Test: Induce the failure by explicitly delaying the call of execveat().
      With fix, no issues observed.
      Tested incremental OTA on pixel ~15 times.
Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: I86c2de977de052bfe9dcdc002dcbd9026601d0f3
2022-01-25 08:30:08 +00:00
bootstat bootstat: add more bootreasons 2021-09-19 19:11:06 +00:00
cli-test [LSC] Add LOCAL_LICENSE_KINDS to system/core 2021-02-19 12:59:05 -08:00
code_coverage [LSC] Add LOCAL_LICENSE_KINDS to system/core 2021-02-19 12:59:05 -08:00
debuggerd Merge "debuggerd: add the PAC keys to the tombstones." 2022-01-14 18:52:01 +00:00
diagnose_usb Support building diagnose_usb against musl 2021-12-16 14:04:06 -08:00
fastboot Merge "fuzzy_fastboot: Add malformed download command test" 2022-01-19 19:31:49 +00:00
fs_mgr init: Wait for snapuserd before starting second stage 2022-01-25 08:30:08 +00:00
gatekeeperd Depend on KeyMint HAL via default 2021-12-02 08:16:25 +00:00
healthd BatteryMonitor: support Dock charging 2022-01-13 20:30:32 +08:00
include Remove include/backtrace symlink. 2020-10-20 12:46:14 -07:00
init init: Wait for snapuserd before starting second stage 2022-01-25 08:30:08 +00:00
janitors Add the two best build system janitors. 2019-03-25 10:25:13 -07:00
libappfuse [LSC] Add LOCAL_LICENSE_KINDS to system/core 2021-02-19 12:59:05 -08:00
libasyncio Set min_sdk_version 2021-12-02 09:23:42 +09:00
libbinderwrapper [LSC] Add LOCAL_LICENSE_KINDS to system/core 2021-02-19 12:59:05 -08:00
libcrypto_utils Set min_sdk_version 2021-12-02 09:23:42 +09:00
libcutils Allow to run fsck.f2fs in first_stage_ramdisk 2022-01-10 21:35:21 +00:00
libdiskconfig [LSC] Add LOCAL_LICENSE_KINDS to system/core 2021-02-19 12:59:05 -08:00
libgrallocusage [LSC] Add LOCAL_LICENSE_KINDS to system/core 2021-02-19 12:59:05 -08:00
libkeyutils Make libfs_mgr dependencies vendor_ramdisk_available. 2021-07-23 16:50:06 -07:00
libmodprobe Split up the system/core/ TEST_MAPPING. 2021-08-16 16:37:10 -07:00
libnetutils Move libipchecksum to frameworks/libs/net. 2021-12-16 19:38:01 +00:00
libpackagelistparser Split up the system/core/ TEST_MAPPING. 2021-08-16 16:37:10 -07:00
libprocessgroup libprocessgroup: Add fd caching support for SetProcessProfiles 2022-01-25 00:05:34 +00:00
libsparse Merge "libsparse: no xrange() in python3." 2022-01-21 00:53:23 +00:00
libstats Make libstatspull_bindgen available to virt apex. 2022-01-14 10:29:51 +00:00
libsuspend libsuspend: vendor_available. 2021-11-02 13:52:40 -07:00
libsync libsync: remove hridya@ from OWNERS file 2022-01-05 16:59:03 -08:00
libsystem [LSC] Add LOCAL_LICENSE_KINDS to system/core 2021-02-19 12:59:05 -08:00
libsysutils Fix 32-bit userspace on 64-bit kernel quota2 compatibility. 2021-10-25 16:24:49 -07:00
libusbhost [LSC] Add LOCAL_LICENSE_KINDS to system/core 2021-02-19 12:59:05 -08:00
libutils Use 0 instead of NULL for comparison to char16_t 2022-01-13 13:41:59 -08:00
libvndksupport Check vendor namespace for SPHAL namespace 2021-11-22 10:57:44 +09:00
llkd llkd: Disable in userdebug builds by default 2021-11-04 16:21:46 -07:00
mini_keyctl Merge "Make libmini_keyctl_static available in recovery" 2021-11-23 17:54:31 +00:00
mkbootfs Rename system/cote/cpio/ -> system/core/mkbootfs/ 2021-05-05 19:03:36 +08:00
property_service remove 'net.qtaguid_enabled' property 2021-11-10 15:52:38 -08:00
reboot [LSC] Add LOCAL_LICENSE_KINDS to system/core 2021-02-19 12:59:05 -08:00
rootdir init.rc: Set permissions to cgroup.procs files 2022-01-25 00:05:47 +00:00
run-as [LSC] Add LOCAL_LICENSE_KINDS to system/core 2021-02-19 12:59:05 -08:00
sdcard [LSC] Add LOCAL_LICENSE_KINDS to system/core 2021-02-19 12:59:05 -08:00
set-verity-state Remove support for AVB 1.0. 2021-11-30 00:57:49 -08:00
shell_and_utilities libprocessgroup/tools: Add settaskprofile command-line tool 2021-11-09 22:35:51 +00:00
storaged Merge "storaged: Fix bug in empty check" 2021-12-11 03:07:39 +00:00
toolbox toolbox/generate-input.h-labels.py: python3. 2021-08-17 14:34:55 -07:00
trusty storageproxyd: Use alternate data path if in DSU state 2022-01-21 14:41:17 -08:00
usbd usbd - remove unused libcutils dep 2021-06-28 23:56:29 +00:00
watchdogd [LSC] Add LOCAL_LICENSE_KINDS to system/core 2021-02-19 12:59:05 -08:00
.clang-format Add a 2 width option of clang format. 2017-03-10 13:01:39 -08:00
.clang-format-2 Move clang-formats to build. 2019-01-18 14:26:33 -08:00
.clang-format-4 Move clang-formats to build. 2019-01-18 14:26:33 -08:00
.gitignore Ignore adb/*.pyc files 2015-08-11 12:59:58 -07:00
CleanSpec.mk snapshotctl don't auto-merge. 2020-03-03 13:19:49 -08:00
METADATA Add METADATA to system/core: Apache2+BSD=NOTICE 2020-04-29 13:16:41 -07:00
MODULE_LICENSE_APACHE2 auto import from //depot/cupcake/@135843 2013-07-30 13:56:49 -07:00
OWNERS Remove baligh@ from owners. CodeShuffle done. 2020-10-17 00:28:10 +00:00
PREUPLOAD.cfg Add AOSP preupload hook. 2020-04-23 11:02:00 -07:00