Skip to content

[Question/Bug maybe?] preserve/mirror file's selinux context #124

@Mark-Joy

Description

@Mark-Joy

On Android through adb, I have created a file and made an ext4 FS. I created a loop device with losetup and I mounted it on "/mnt/pass_through/0/xMySDCard/com.termux". Then I used bindfs to mirror it to "/data/data/com.termux"

losetup -fs /mnt/pass_through/0/430B-16F1/0-InternalData/InternalData.img
mount /dev/block/loop0 /mnt/pass_through/0/xMySDCard/com.termux
bindfs "/mnt/pass_through/0/xMySDCard/com.termux" "/data/data/com.termux"

Doing ls -laZ "/mnt/pass_through/0/xMySDCard/com.termux" gave:

130|onclite:/ # ls -laZ  "/mnt/pass_through/0/xMySDCard/com.termux"
total 24
drwxrwxr-x 6 u0_a175 u0_a175       u:object_r:app_data_file:s0:c175,c256,c512,c768  4096 2022-12-05 04:10 .
drwxrwxrwx 3 root    root          u:object_r:mnt_pass_through_file:s0                60 2022-12-06 08:11 ..
drwxrws--x 2 u0_a175 u0_a175_cache u:object_r:app_data_file:s0:c175,c256,c512,c768  4096 2022-12-04 05:43 cache
drwxrwx--x 4 u0_a175 u0_a175       u:object_r:app_data_file:s0:c175,c256,c512,c768  4096 2022-12-04 05:43 files
drwxrwx--x 2 u0_a175 u0_a175       u:object_r:app_data_file:s0:c175,c256,c512,c768  4096 2022-12-05 04:44 shared_prefs

Doing ls -laZ "/data/data/com.termux" gave:

onclite:/ # ls -laZ "/data/data/com.termux"
total 44
drwxrwxr-x   6 u0_a175 u0_a175 u:object_r:fuse:s0                         4096 2022-12-05 04:10 .
drwxrwx--x 206 system  system  u:object_r:system_data_file:s0:c512,c768  16384 2022-12-04 09:27 ..
drwxrws--x   2 u0_a175 u0_a175 u:object_r:fuse:s0                         4096 2022-12-04 05:43 cache
drwxrwx--x   4 u0_a175 u0_a175 u:object_r:fuse:s0                         4096 2022-12-04 05:43 files
drwxrwx--x   2 u0_a175 u0_a175 u:object_r:fuse:s0                         4096 2022-12-05 04:44 shared_prefs

Obviously, the selinux contexts are different.

When I tried with standard "mount -o bind"

mount -o bind "/mnt/pass_through/0/xMySDCard/com.termux" "/data/data/com.termux"

I got the correct selinux context

onclite:/ # ls -laZ "/data/data/com.termux"
total 44
drwxrwxr-x   6 u0_a175 u0_a175       u:object_r:app_data_file:s0:c175,c256,c512,c768   4096 2022-12-05 04:10 .
drwxrwx--x 206 system  system        u:object_r:system_data_file:s0:c512,c768         16384 2022-12-04 09:27 ..
drwxrws--x   2 u0_a175 u0_a175_cache u:object_r:app_data_file:s0:c175,c256,c512,c768   4096 2022-12-04 05:43 cache
drwxrwx--x   4 u0_a175 u0_a175       u:object_r:app_data_file:s0:c175,c256,c512,c768   4096 2022-12-04 05:43 files
drwxrwx--x   2 u0_a175 u0_a175       u:object_r:app_data_file:s0:c175,c256,c512,c768   4096 2022-12-05 04:44 shared_prefs```

Because selinux context was not mirrored/preserved, app is broken.

My question is, how to make bindfs behave like "mount -o bind" preserving selinux context?

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature request/PR

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions