1

I am trying to create some volatile (tmpfs) storage for my Android, to avoid clutter.

I am trying to follow the previous questions:

making manually mounted partition folders write accessible to all apps

and

How to bind mount a folder inside /sdcard with correct permissions?

The way I am doing is by adding an "init script" into a magisk "service.d" directory:

# cat /sbin/.magisk/img/.core/service.d/001-tmpfs.sh                             

#!/system/bin/sh
while [ "$(getprop sys.boot_completed)" != 1 ];
do
  sleep 1
done

su -mm -c mount -v none -t tmpfs -o size=4g,nosuid,nodev,noexec,noatime,context=u:object_r:sdcardfs:s0,uid=0,gid=9997,mode=0777 /mnt/runtime/write/emulated/0/Download/tmpfs-cleared-on-reboot 

Seems plain and simple, only doesn't work in the sense that the folder is mounted successfully, and files disappear after a reboot, if copied there by root. But an ordinary app cannot copy anything there. FX Explorer, for example, says "Access was denied."

It does work though if I set setenforce 0, which seems to indicate that there is a SELinux problem.

The only relevant error in dmesg looks the following:

[ 3181.763111] [20200731_13:36:57.002188]@1 type=1400 audit(1596173815.897:12245): avc: denied { create } for pid=5870 comm="Thread-139" name=233339202D5370656E63657220477265656E62657267206F6E20696E7472696E7369632076732E20696E737472756D656E74616C2076616C7565732C206F766572636F6E666964656E63652C20616E6420686F7720746F2061637475616C6C79207570646174652062656C6965667320696D70726F76656420617564696F2E6D7033 scontext=u:r:untrusted_app:s0:c104,c256,c512,c768 tcontext=u:object_r:sdcardfs:s0 tclass=file permissive=0

It appears if I try to copy some file into this directory.

ls -lahZ /mnt/runtime/write/emulated/0/Download/ gives

drwxrwxrwx   2 root everybody u:object_r:sdcardfs:s0   40 2020-07-31 13:25 tmpfs-cleared-on-reboot

ls -larhtZ /storage/emulated/0/Download/

drwxrwxrwx   2 root everybody u:object_r:sdcardfs:s0   40 2020-07-31 13:25 tmpfs-cleared-on-reboot

Which is strange, because the other files in the directory have permissions like this:

drwxrwx--x   2 root sdcard_rw u:object_r:sdcardfs:s0 4.0K 2020-07-30 20:04 pdfs-scientific_papers-toread

the group is different. I am not sure whether this is related or not.

But anyway, I cannot copy anything into this directory as a normal app.

I can copy stuff there as root, and it disappears on reboot, as expected. But where is the permissions problem?

This is Android 9 on OnePlus 5t.

6
  • Great! How do I make it appear as a subfolder under Download? Commented Jul 31, 2020 at 15:42
  • That is exactly the story I am asking in this question. Moreover, the "bind mount WhatsApp" question is even linked to as "prior research" within the first three lines of this question. Commented Aug 1, 2020 at 5:35
  • what happen when you mount it uid=0,gid=1015,mode=0771 instead?
    – alecxs
    Commented Aug 1, 2020 at 10:20
  • 1
    Then the group is changed into sdcard_rw, but it does not help. After this change, other apps are not just not able to write anything into this directory, but also not allowed to cd into it. Commented Aug 3, 2020 at 4:42
  • maybe the permissions on underlaying tmpfs needs also to adjusted. i recommend to try with fat32 sdcard partition first. once you figured out working permissions you can adapt to tmpfs
    – alecxs
    Commented Aug 3, 2020 at 7:20

0

You must log in to answer this question.

Browse other questions tagged .