[G2 Q&A, Help & Troubleshooting] siggey:
(1) BSD Reference Manual MKSH(1)

NAME

mksh, sh - MirBSD Korn shell

SYNOPSIS

mksh [-+abCefhiklmnprUuvXx] [-T [!]tty | -] [-+o option] [-c string | -s | file [argument ...]] builtin-name [argument ...]

DESCRIPTION

mksh is a command interpreter intended for both interactive and shell script use. Its command language is a superset of the sh(C) shell language and largely compatible to the original Korn shell.

I'm an Android user, so what's mksh?

mksh is a UNIX shell / command interpreter, similar to COMMAND.COM or CMD.EXE, which has been included with Android Open Source Project for a while now. Basically, it's a program that runs in a terminal (console window), takes user input and runs commands or scripts, which it can also be asked to do by other programs, even in the background. Any privilege pop-ups you might be encountering are thus not mksh issues but questions by some other program utilising it.

FILES

~/.mkshrc User mkshrc profile (non-privileged interactive shells); see Startup files. The location can be changed at compile time (for embedded systems); AOSP Android builds use /system/etc/mkshrc. ~/.profile User profile (non-privileged login shells); see Startup files near the top of this manual. /etc/profile System profile (login shells); see Startup files. /etc/shells Shell database. /etc/suid_profile Suid profile (privileged shells); see Startup files.

About Android L and SELinux

The developer preview of Android L hints at which restrictions for root apps, mainly with regard to SELinux, can be expected in future.*Chainfire*provides a very helpful, developer-aimed*explanation of the impact of SELinux*and thus I won’t dive into more details here.*Fact is: most root apps don’t work on the Android L developer preview.*At least, not yet. Development of root apps becomes more difficult. As a developer of a root app myself, I’m highly interested in understanding the reasons and fixing them as soon as possible. The restrictions present in the developer preview will most-likely be included in the official release of Android L and later versions. Further restrictions must be expected. Thus, even although the results I describe in this article show that superuser access can still be achieved (at least for some apps) it’s very well possible that these methods won’t work in a few months.

Setup

The following experiments were done on a Nexus 5 running the Android L developer preview. The device was rooted using the steps shown by XDA usersavoca*here. Thanks, savoca! Additionally,*SuperSU*2.00 by Chainfire was used. Thanks, Chainfire!

After setting up the device and rooting it, I tried to run my Android app RepetiTouch Pro. As expected, it did not work. Like many root apps, RepetiTouch uses an executable stored in its private app directory (under /data, e.g., /data/data/com.example.myapp/files/myexecutable) to handle the tasks which require superuser privileges. Trying to run this executable, called*eventserver*in this app, in a su shell results in

*

tmp-mksh: ./eventserver: can't execute: Permission denied

SELinux context experiments

Following this test, I experimented with various SELinux file contexts and additionally changed the file owner of this executable to root (the default file owner is similar to u0_a123). The file contexts can be listed via*ls -Z*and changed via the*chcon*command which is part of Android’s toolbox. Example:

#*

*

#*

#*

*

ls -Z eventserver

-rwx------ u0_a88 u0_a88 u:object_r:app_data_file:s0 eventserver

chcon u:object_r:system_file:s0 eventserver

ls -Z eventserver

-rwx------ u0_a88 u0_a88 u:object_r:system_file:s0 eventserver

SuperSU supports the*-cn/–context*argument to set the SELinux context, e.g.,

$*

su --context u:r:untrusted_app:s0

The default context is u:r:init:s0.

There were different results/errors:

“./eventserver: can’t execute: Permission denied” with error code 126 and different shells prepended, e.g., “tmp-mksh: ./eventserver: can’t execute: Permission denied”. For this error,*exec error*is used in the following.“error: only position independent executables (PIE) are supported.” with error code 1. For this error,*PIE error*is used in the following.success (which only means that the file could be executed, it still might not get access to other files or resources)

Default file context (u:object_r:app_data_file:s0)

su contextdefault ownerroot owneru:r:init:s0tmp-mksh: exec error tmp-mksh: exec erroru:r:untrusted_app:s0sh: <stdin>[1]: exec errorPIE erroru:r:system_app:s0sh: exec errorsh: exec erroru:r:system_server:s0sh: exec errorsh: exec error

_____________________________________Read more write less and be smart