1. Why do I need installd
As you can see from the output below, System_server runs as the system user. We know that Packagemanager runs in System_server. In other words, Packagemanager's identity is also the system user.
[Email protected]:/$ busybox PS
Busyboxps
PID USER Time COMMAND
......
701 System 0:23 System_server
146 Install 0:00/system/bin/installd
However, the system user does not have permission to access the application directory. The output below shows that the current user is system and it cannot access the/data/data/com.xiaomi.shop directory (this directory should be a directory for Xiaomi App Store apps).
[Email protected]:/data/data$ ID
Id
uid=1000 (system) gid=1000 (System) CONTEXT=U:R:TOOLBOX:S0
[Email protected]:/data/data$ ls-l com.xiaomi.shop
Ls-lcom.xiaomi.shop
Opendir failed, Permission denied
This is the reason why INSTALLD exists.
2. Why can INSTALLD access the application's directory (such as/data/data/com.xiaomi.shop)?
The source program for INSTALLD is in the FRAMEWORKS\NATIVE\CMDS\INSTALLD directory.
The following code is in the Install.c file.
static void Drop_privileges () {
......
struct __user_cap_header_struct capheader;
struct __user_cap_data_struct capdata[2];
memset (&capheader, 0,sizeof (Capheader));
memset (&capdata, 0, sizeof (capdata));
Capheader.version =_linux_capability_version_3;
capheader.pid = 0;
Capdata[cap_to_index (cap_dac_override)].permitted |= cap_to_mask (cap_dac_override);
......
if (Capset (&capheader, &capdata[0]) < 0) {
Aloge ("Capset failed:%s\n", Strerror (errno));
Exit (1);
}
}
int main (const int argc__unused, const char *argv[] __unused) {
......
Drop_privileges ();
......
}
As you can see from the code above, the INSTALLD process has cap_dac_override privileges (Privilege). According to Http://linux.die.net/man/7/capabilities, for processes with cap_dac_override privileges, Linux skips the check of read, write, and execute permissions on the file. Therefore, INSTALLD can access files in any directory.
Cap_dac_override
Bypass file read, write, and executepermission checks. (DAC is an abbreviation of "discretionary AccessControl".)
The meaning of the INSTALLD process in Android