Skip to content

Commit 6880241

Browse files
committed
unconditionally apply SELinux labels to symlinks
At the end of the OTA script, we walk through /system, updating all the permissions on the filesystem, including the UID, GID, standard UNIX permissions, capabilities, and SELinux labels. In the case of a symbolic link, however, we want to skip most of those operations. The UID, GID, UNIX permissions, and capabilities don't meaningfully apply to symbolic links. However, that's not true with SELinux labels. The SELinux label on a symbolic link is important. We need to make sure the label on the symbolic link is always updated, even if none of the other attributes are updated. This change unconditionally updates the SELinux label on the symbolic link itself. lsetfilecon() is used, so that the link itself is updated, not what it's pointing to. In addition, drop the ENOTSUP special case. SELinux has been a requirement since Android 4.4. Running without filesystem extended attributes is no longer supported, and we shouldn't even try to handle non-SELinux updates anymore. (Note: this could be problematic if these scripts are ever used to produce OTA images for 4.2 devices) Bug: 18079773 Change-Id: I87f99a1c88fe02bb2914f1884cac23ce1b385f91
1 parent 168f777 commit 6880241

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

updater/install.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -770,9 +770,17 @@ static int ApplyParsedPerms(
770770
{
771771
int bad = 0;
772772

773+
if (parsed.has_selabel) {
774+
if (lsetfilecon(filename, parsed.selabel) != 0) {
775+
uiPrintf(state, "ApplyParsedPerms: lsetfilecon of %s to %s failed: %s\n",
776+
filename, parsed.selabel, strerror(errno));
777+
bad++;
778+
}
779+
}
780+
773781
/* ignore symlinks */
774782
if (S_ISLNK(statptr->st_mode)) {
775-
return 0;
783+
return bad;
776784
}
777785

778786
if (parsed.has_uid) {
@@ -815,15 +823,6 @@ static int ApplyParsedPerms(
815823
}
816824
}
817825

818-
if (parsed.has_selabel) {
819-
// TODO: Don't silently ignore ENOTSUP
820-
if (lsetfilecon(filename, parsed.selabel) && (errno != ENOTSUP)) {
821-
uiPrintf(state, "ApplyParsedPerms: lsetfilecon of %s to %s failed: %s\n",
822-
filename, parsed.selabel, strerror(errno));
823-
bad++;
824-
}
825-
}
826-
827826
if (parsed.has_capabilities && S_ISREG(statptr->st_mode)) {
828827
if (parsed.capabilities == 0) {
829828
if ((removexattr(filename, XATTR_NAME_CAPS) == -1) && (errno != ENODATA)) {

0 commit comments

Comments
 (0)