Android tmpfs可由用户写入

gre*_*til 5 android android-shell

在已 root 的 Android 6.0.1 设备上,我希望用户可以写入 tmpfs。我愿意:

mkdir /sdcard/test
su
mount -t tmpfs -o size=512m tmpfs /sdcard/test
#Note that the permissions of /sdcard/test have changed
chmod 0771 /sdcard/test
chown root:sdcard_rw /sdcard/test
exit
touch /sdcard/test/aa
Run Code Online (Sandbox Code Playgroud)

安装报告:

tmpfs /storage/emulated/0/test tmpfs rw,seclabel,relatime,size=524288k 0 0
Run Code Online (Sandbox Code Playgroud)

但我得到:

touch: '/sdcard/test/aa': Permission denied
Run Code Online (Sandbox Code Playgroud)

所以我无法以标准用户身份写入 /sdcard/test (通过 shell 或应用程序)。我究竟做错了什么?我也尝试在 /data/ 中创建安装,这是同样的问题。

编辑1:

我已经在 Android 4.4 设备上尝试过并且可以正常工作。因此,某些内容发生了变化,并且在更高版本中受到了限制。我想知道 5.x 是否也受到影响。

编辑2:

奇怪的是, mount 报告了两次挂载点:

tmpfs /mnt/runtime/default/emulated/0/test tmpfs rw,seclabel,relatime,size=524288k 0 0
tmpfs /storage/emulated/0/test tmpfs rw,seclabel,relatime,size=524288k 0 0
Run Code Online (Sandbox Code Playgroud)

编辑3:

当我以用户身份执行文件触摸时,内核报告以下内容:

[54484.588865] type=1400 audit(1452975001.917:150): avc: denied { write } for pid=30781 comm="touch" name="/" dev="tmpfs" ino=398770 scontext=u:r:shell:s0 tcontext=u:object_r:tmpfs:s0 tclass=dir permissive=0
Run Code Online (Sandbox Code Playgroud)

gre*_*til 2

“su -c setenforce 0”解决了这个问题。请参阅https://source.android.com/security/selinux/validate.html