Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added
setpriv
inutil-linux
.Android
7
and some Android devices8
do not support ambient capabilities and will returnactivate capabilities: Invalid argument
when runningsetpriv
.strace shows
"prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, CAP_CHOWN, 0, 0) = -1 EINVAL (Invalid argument)"
This was an issue with
libcap-ng
where support forPR_CAP_AMBIENT
was checked at compile time, sosetpriv
only worked on Android >7
/8
whencapng_apply()
was called.4.3 kernel PR_CAP_AMBIENT
https://github.com/util-linux/util-linux/blob/v2.37.1/sys-utils/setpriv.c#L1010
https://github.com/stevegrubb/libcap-ng/blob/v0.8.2/src/cap-ng.c#L59
https://github.com/stevegrubb/libcap-ng/blob/v0.8.2/src/cap-ng.c#L716
https://source.android.com/devices/architecture/kernel/android-common
This has been fixed in
libcap-ng
by checkingPR_CAP_AMBIENT
at runtime with187ed535
.libcap-ng
0.8.3
has not been released yet and so we use a pre release version0.8.3~pre1
.stevegrubb/libcap-ng#28
stevegrubb/libcap-ng@187ed535
Let me know if someone is willing to test it out. I have confirmed its working on android
7
, did some basic run test on android10
avd as well and it ran fine, but since patching selinux policy isn't working on it, so can't fully test dropping to app context currently. Thesetrpriv
binary should help people who want to run commands in termux or other app contexts from scripts running asroot
.nsenter
is already provided byutil-linux
. I'll release a script soon for it as well. Check https://android.stackexchange.com/questions/217016/how-to-run-a-program-in-an-app-context-with-magisk for details.