termux / proot

An chroot-like implementation using ptrace.
https://wiki.termux.com/wiki/PRoot
Other
761 stars 160 forks source link

function not implemented in xiaomi, run success in other devices #120

Closed nawbc closed 4 years ago

nawbc commented 4 years ago

I compile the binary for aarch64 and armv7, and create a right alpine env. proot tested successfully using nokia x6 and honor v10, but all xiaomi devices fail to run redmi k20 (miui12 android10) , xiaomi 8 (miui12 android10) xiaomi 7 (miui 11 android 9)

  List<String> getArguments(List<String> cmds) {
    return [
      '-0',
      '--link2symlink',
      '-r',
      '$filesPath/rootfs',
      '-b',
      '/dev/',
      '-b',
      '/sys/',
      '-b',
      '/proc/',
      '-w',
      '/root',
      '/usr/bin/env',
      '-i',
      'HOME=/root',
      'PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin/',
      'LANG=C.UTF-8',
      ...cmds
    ];
  }

log

I/flutter ( 6319): proot info: Checking for f2fs case sensitivity bug
I/flutter ( 6319): proot info: f2fs bug not present on device
I/flutter ( 6319): proot info: binding = /proc
I/flutter ( 6319): proot info: binding = /sys
I/flutter ( 6319): proot info: binding = /dev
I/flutter ( 6319): proot info: binding = /data/data/com.sewerganger.lan_express/files/rootfs:/
I/flutter ( 6319): proot info: vpid 1: translate("/" + "/usr/bin/env")
I/flutter ( 6319): proot info: vpid 1:          -> "/data/data/com.sewerganger.lan_express/files/rootfs/bin/busybox"
I/flutter ( 6319): proot info: vpid 1: translate("/" + "/usr/bin/env")
I/flutter ( 6319): proot info: vpid 1:          -> "/data/data/com.sewerganger.lan_express/files/rootfs/usr/bin/env"
I/flutter ( 6319): proot info: exe = /usr/bin/env
I/flutter ( 6319): proot info: argv = /usr/bin/env -i HOME=/root PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin/ LANG=C.UTF-8 apk
I/flutter ( 6319): proot info: initial cwd = /root
I/flutter ( 6319): proot info: verbose level = 9
I/flutter ( 6319): proot info: pid 12151: access to "/proc/12151/fd" (fd 3) won't be translated until closed
I/flutter ( 6319): proot info: pid 12151: access to "/dev/ion" (fd 73) won't be translated until closed
I/flutter ( 6319): proot info: pid 12151: access to "/data/data/com.sewerganger.lan_express/
michalbednarski commented 4 years ago

This log is either cut or captured with too low verbosity, try capturing with -v 9 or PROOT_VERBOSE=9

(also, does same problem occur withing Termux app?)

nawbc commented 4 years ago

@michalbednarski hi i have added PROOT_VERBOSE=9 to env that is all the log and termux runs well, i have tried android 10 devices but all failed, stderr: function not implemented, nokia x6(android 9) and honor v10(android 8) success

code

  Future<ProcessResult> testProot(List<String> cmds,
      {Map<String, String> env}) async {
    bool seccomp = await Store.getBool(SANDBOX_NO_SECCOMP) ?? true;

    return Process.run(
      '$filesPath/proot',
      getTestArguments(cmds),
      workingDirectory: '/',
      environment: {
        'PROOT_NO_SECCOMP': seccomp ? '1' : '0',
        'PROOT_TMP_DIR': '$filesPath/tmp',
        'PROOT_VERBOSE': '9',
        ...?env
      },
      includeParentEnvironment: true,
    );
  }
  Future<ProcessResult> installNodeJs() async {
    return runProot(['apk', 'add', '--allow-untrusted', '/root/nodejs.apk']);
  }

the proot binay i compiled https://github.com/sewerganger/lan_express_desktop_bug_report the alpine env

image

michalbednarski commented 4 years ago

code

        'PROOT_NO_SECCOMP': seccomp ? '1' : '0',

proot checks presence of PROOT_NO_SECCOMP variable, so PROOT_NO_SECCOMP=0 is same as PROOT_NO_SECCOMP=1 (and setting this variable can cause problems as it prevents detection of syscall order which might be needed for handling of blocked syscalls). Try removing this variable.

Additional notes on PROOT_NO_SECCOMP and PROOT_ASSUME_NEW_SECCOMP env variables When you use `PROOT_NO_SECCOMP`, proot assumes old seccomp-SIGTRAP order as using that variable skips detection. Applying workarounds with new order requires adding `PROOT_ASSUME_NEW_SECCOMP`. Proot informs about detected syscall order when running without `PROOT_NO_SECCOMP` and at least `-v 1` proot info: ptrace acceleration (seccomp mode 2, new syscall order) enabled "new" syscall order means running on kernel that includes following commit https://github.com/torvalds/linux/commit/a5cd110cb8369d6b37ef5ccfe56b3fa1338c9615

If removing that env variable didn't help this log still looks cut to me, try running that command through shell and using >& file.txt redirect instead of capturing results from app.

nawbc commented 4 years ago

@michalbednarski thank you very much, i remove the PROOT_NO_SECCOMP , everything goes well