Skip to content

fix(root): enforce command deadlines while draining output - #6234

Closed
wangtong10086 wants to merge 1 commit into
2dust:masterfrom
wangtong10086:fix/root-command-deadlines
Closed

wangtong10086 wants to merge 1 commit into
2dust:masterfrom
wangtong10086:fix/root-command-deadlines

Conversation

@wangtong10086

Copy link
Copy Markdown

Root commands can block before reaching their timeout because stdout is read to EOF before waitFor. A detached child that retains stdout can also keep an otherwise completed su command waiting.

Add a bounded process runner that drains available output while checking a monotonic deadline, caps retained output, preserves nonzero exit status, and closes streams on exit. Root scripts also run inside Android's timeout so the root shell has its own deadline. Root availability checks use the same runner. Command strings are omitted from failure logs, and generated scripts use owner-only read/write permissions.

Validation on this branch:

  • :app:testPlaystoreDebugUnitTest --tests com.v2ray.ang.root.RootProcessRunnerTest
  • :app:testPlaystoreDebugUnitTest — 85 tests passed.
  • :app:compilePlaystoreDebugKotlin
  • Android 16 / arm64: a probe loaded this exact runner implementation from an installed personal build. A silent command with a 150 ms deadline returned in 155 ms; inherited stdout returned in 11 ms; 1 MiB output retained 4096 bytes and returned in 129 ms; exit status 4 and stderr were preserved. A device timeout test prevented a child from writing a delayed marker after termination.

Not run: runtime checks on Android 7–15 and non-arm64 devices; those devices were unavailable. The runner avoids Process.waitFor(timeout, unit) to retain API 24–25 compatibility. The device probe validates command execution; it does not establish lifecycle correctness for the upstream root service as a whole.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant