Skip to content

Commit d7a6f73

Browse files
K2GO-446 fix(terminal): run iiab orchestrator through the interpreter
At targetSdk 35 Android W^X (neverallow app_data_file:file execute_no_trans) blocks execve of a file in the app data dir, so the host shell could not run the generated iiab script directly ("Permission denied") and iiab --login was unreachable. Define iiab as a .mkshrc function that runs the script through /system/bin/sh; read and interpret are allowed, only execute is blocked. The ninja symlinks and proot run from nativeLibraryDir and are unaffected.
1 parent 087362a commit d7a6f73

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎controller/app/src/main/java/org/appdevforall/k2go/TerminalController.java‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,8 @@ public void addNewSession() {
590590

591591
String hostShell = "/system/bin/sh";
592592
File workingDirectory = activity.getFilesDir(); // Start in the app's secure root
593+
// K2GO-446: single source for the generated iiab script path (writer and .mkshrc wrapper).
594+
File iiabScript = new File(new File(workingDirectory, "usr/bin"), "iiab");
593595

594596
try {
595597
File hostBinDir = new File(activity.getFilesDir(), "usr/bin");
@@ -653,7 +655,6 @@ public void addNewSession() {
653655
File tmpDir = new File(activity.getFilesDir(), "proot_tmp");
654656
if (!tmpDir.exists()) tmpDir.mkdirs();
655657

656-
File iiabCliScript = new File(hostBinDir, "iiab");
657658
StringBuilder cliStr = new StringBuilder();
658659

659660
// ADFA-4630: resolve the app's effective DNS (user's custom config when enabled,
@@ -890,10 +891,10 @@ public void addNewSession() {
890891
cliStr.append(" do_login\n");
891892
cliStr.append("fi\n");
892893

893-
java.io.FileOutputStream fosCli = new java.io.FileOutputStream(iiabCliScript);
894+
java.io.FileOutputStream fosCli = new java.io.FileOutputStream(iiabScript);
894895
fosCli.write(cliStr.toString().getBytes());
895896
fosCli.close();
896-
iiabCliScript.setExecutable(true);
897+
iiabScript.setExecutable(true);
897898

898899
} catch (Exception e) {
899900
Log.e(TAG, "Failed to create host scripts", e);
@@ -977,6 +978,9 @@ public void addNewSession() {
977978
// persistent history would require replacing /system/bin/sh with a fuller
978979
// shell (e.g. a bundled bash / busybox ash) — see ADFA-4709.
979980
mkshrc.append("export HISTSIZE=5000\n");
981+
// K2GO-446: targetSdk 35 W^X blocks execve of app-data-dir files, so run the
982+
// generated iiab script through the interpreter instead of exec'ing it directly.
983+
mkshrc.append("iiab() { /system/bin/sh \"").append(iiabScript.getAbsolutePath()).append("\" \"$@\"; }\n");
980984
fosMkshrc.write(mkshrc.toString().getBytes());
981985
fosMkshrc.close();
982986
} catch (Exception e) {

0 commit comments

Comments
 (0)