Whamcloud - gitweb
AOSP: e2fsdroid: Correctly process the root inode
authorLuis Hector Chavez <lhchavez@google.com>
Tue, 19 Jun 2018 21:50:40 +0000 (14:50 -0700)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 24 Jun 2018 03:18:48 +0000 (23:18 -0400)
This change ensures that the root inode has the correct uid/gid by
calling androidify_inode() on it. It also sets android_configure = 1
when the u/gid mapping is provided.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Google-Bug-Id: 78561186
Google-Bug-Id: 110415537
Test: $ m  # With BOARD_SYSTEMIMAGE_UID_MAP=655360 0 5000
      $ simg2img ${OUT}/{system.img,system.raw.img}
      $ mkdir tmp
      $ sudo mount -o loop ${OUT}/system.raw.img tmp
      $ stat --format="%u %g" tmp
      655360 655360
Change-Id: I842a32b6d64439f9f16b9c6b66de20d4e4418aa8
From AOSP commit: ee3f0f37c34d68aa7a96a36dea369acae312772c

contrib/android/e2fsdroid.c
contrib/android/perms.c

index 237df51..e784428 100644 (file)
@@ -265,10 +265,12 @@ int main(int argc, char *argv[])
                case 'u':
                        if (!parse_ugid_map(optarg, &uid_map))
                                exit(EXIT_FAILURE);
+                       android_configure = 1;
                        break;
                case 'g':
                        if (!parse_ugid_map(optarg, &gid_map))
                                exit(EXIT_FAILURE);
+                       android_configure = 1;
                        break;
                default:
                        usage(EXIT_FAILURE);
index 74ef4b8..746b94b 100644 (file)
@@ -129,7 +129,12 @@ static errcode_t set_perms_and_caps(ext2_filsys fs, ext2_ino_t ino,
 
        /* Permissions */
        if (params->fs_config_func != NULL) {
-               params->fs_config_func(params->filename, S_ISDIR(inode.i_mode),
+               const char *filename = params->filename;
+               if (strcmp(filename, params->mountpoint) == 0) {
+                       /* The root of the filesystem needs to be an empty string. */
+                       filename = "";
+               }
+               params->fs_config_func(filename, S_ISDIR(inode.i_mode),
                                       params->target_out, &uid, &gid, &imode,
                                       &capabilities);
                uid = resolve_ugid(params->uid_map, uid);
@@ -299,10 +304,7 @@ errcode_t __android_configure_fs(ext2_filsys fs, char *src_dir,
        if (strlen(mountpoint) == 1 && mountpoint[0] == '/')
                params.path = "";
 
-       retval = set_selinux_xattr(fs, EXT2_ROOT_INO, &params);
-       if (retval)
-               return retval;
-       retval = set_timestamp(fs, EXT2_ROOT_INO, &params);
+       retval = androidify_inode(fs, EXT2_ROOT_INO, &params);
        if (retval)
                return retval;