Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,8 @@ public void addNewSession() {

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

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

File iiabCliScript = new File(hostBinDir, "iiab");
StringBuilder cliStr = new StringBuilder();

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

java.io.FileOutputStream fosCli = new java.io.FileOutputStream(iiabCliScript);
java.io.FileOutputStream fosCli = new java.io.FileOutputStream(iiabScript);
fosCli.write(cliStr.toString().getBytes());
fosCli.close();
iiabCliScript.setExecutable(true);
iiabScript.setExecutable(true);

} catch (Exception e) {
Log.e(TAG, "Failed to create host scripts", e);
Expand Down Expand Up @@ -977,6 +978,9 @@ public void addNewSession() {
// persistent history would require replacing /system/bin/sh with a fuller
// shell (e.g. a bundled bash / busybox ash) — see ADFA-4709.
mkshrc.append("export HISTSIZE=5000\n");
// K2GO-446: targetSdk 35 W^X blocks execve of app-data-dir files, so run the
// generated iiab script through the interpreter instead of exec'ing it directly.
mkshrc.append("iiab() { /system/bin/sh \"").append(iiabScript.getAbsolutePath()).append("\" \"$@\"; }\n");
fosMkshrc.write(mkshrc.toString().getBytes());
fosMkshrc.close();
} catch (Exception e) {
Expand All @@ -988,6 +992,9 @@ public void addNewSession() {
"TERM=xterm-256color",
"HOME=" + workingDirectory.getAbsolutePath(),
"ENV=" + mkshrcFile.getAbsolutePath(),
// K2GO-446: writable TMPDIR so mksh can spool the iiab script's here-docs
// (unset by default, mksh then falls back to a non-writable path).
"TMPDIR=" + activity.getCacheDir().getAbsolutePath(),
// Include the system bins and our W^X fake prefix bins
"PATH=/sbin:/system/sbin:/system/bin:/system/xbin:" + workingDirectory.getAbsolutePath() + "/usr/bin"
};
Expand Down
Loading