Skip to content

Android tagets: Piped su call vs --command option #386

@ptosi

Description

@ptosi

This is with (Google Pixel 2):

walleye:/ # su --version
15.3:MAGISKSU (topjohnwu)

and (host):

$ adb --version
Android Debug Bridge version 1.0.40
Version 28.0.2-5303910

The way devlib.AndroidTarget.execute works relies on su and there seems to be a difference in behaviour between a call to that method and actually running a command inside of su inside of an adb shell.

I am unsure about the reason but, as an example (the device is connected through adb and there exists a /sdcard/devlib-target/perf.data file on the device):

Python 3.6.7 (default, Oct 22 2018, 11:32:17)
>>> import devlib
>>> t = devlib.AndroidTarget()
>>> print(t.execute('cd /sdcard/devlib-target && /data/local/tmp/bin/perf report', as_root=True))
incompatible file format (rerun with -v to learn more)Warning:
Kernel address maps (/proc/{kallsyms,modules}) were restricted.

Check /proc/sys/kernel/kptr_restrict before running 'perf record'.

As no suitable kallsyms nor vmlinux was found, kernel samples
can't be resolved.

Samples in kernel modules can't be resolved as well.

Error:
The - file has no samples!
# ========
# captured on: Mon May 13 18:35:09 2019
# ========
#

while

$ adb shell
walleye:/ $ su
walleye:/ # cd /sdcard/devlib-target
walleye:/sdcard/devlib-target # /data/local/tmp/bin/perf report

gives the expected result.

In fact, going through adb shell with oneliners:

$ adb shell "echo 'cd /sdcard/devlib-target && /data/local/tmp/bin/perf report' | su"
incompatible file format (rerun with -v to learn more)Warning:
Kernel address maps (/proc/{kallsyms,modules}) were restricted.

Check /proc/sys/kernel/kptr_restrict before running 'perf record'.

As no suitable kallsyms nor vmlinux was found, kernel samples
can't be resolved.

Samples in kernel modules can't be resolved as well.

Error:
The - file has no samples!
# ========
# captured on: Mon May 13 18:22:58 2019
# ========
#

while the following works:

$ adb shell "su -c 'cd /sdcard/devlib-target && /data/local/tmp/bin/perf report'"

I am puzzled by this and believe that it is partially due to how perf is doing something (notice that it's supposed to read $(pwd)/perf.data by default, but the error message refers to "the - file"). However, the fact that the behaviour of perf depends on how su is called implies that su itself behaves differently.

Now, the solution might be to use -c (which seems to be somewhat standard) but I have no idea of the consequences this might have; in particular, when using other distributions of su. Was there a reason for using echo CMD | su?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions