CVE-2026-58974 AI-generated analysis
platform/frameworks/base, WindowManagerService (services/core wm) and android.os.Binder
Adds a ROOT/SHELL calling-UID gate at the start of WindowManagerService.onShellCommand (via a new static helper Binder.enforceShellCommandUid) so that non-ADB callers can no longer run WindowManagerShellCommand commands through the binder shell-command transaction.
Root cause
Binder.onShellCommand's default implementation enforces that the calling UID is ROOT_UID or SHELL_UID before dispatching to handleShellCommand, and Binder.shellCommand calls onShellCommand directly with no check of its own (the Binder javadoc in the context notes that no permission checking is done before calling onShellCommand). WindowManagerService overrides onShellCommand and immediately executes new WindowManagerShellCommand(this).exec(...), so the default UID check never ran. As a result, a caller that could send the shell-command transaction to the IWindowManager binder could execute WindowManagerShellCommand commands without being shell or root.
How the fix works
- core/java/android/os/Binder.java: adds a public static @hide helper, enforceShellCommandUid(@Nullable ResultReceiver). It reads Binder.getCallingUid(). If that UID is neither Process.ROOT_UID nor Process.SHELL_UID, it sends -1 to the ResultReceiver (only when it is non-null) and throws SecurityException("Shell commands are only callable by ADB").
- core/java/android/os/Binder.java:onShellCommand: the inline UID check is replaced by a call to enforceShellCommandUid(resultReceiver). The logic is the same, except that the helper guards against a null receiver, although this parameter is annotated @NonNull.
- services/core/java/com/android/server/wm/WindowManagerService.java:onShellCommand: inserts Binder.enforceShellCommandUid(result) as the first statement, before new WindowManagerShellCommand(this).exec(...), so the WindowManagerShellCommand is never constructed or executed for a caller that is not ROOT or SHELL.
Completeness
- The gate covers the entire WindowManagerService.onShellCommand entry point, so every WindowManagerShellCommand subcommand reached through this path is protected at once.
- Only WindowManagerService's override is patched. The helper is added to Binder but is not applied to other services that override onShellCommand in the same way (see potential_variants). The material does not show whether those services rely on per-command checks inside their ShellCommand classes.
- The fix does not change WindowManagerShellCommand itself.
Behavior changes
- Callers of the shell-command transaction on IWindowManager whose UID is not ROOT or SHELL now get result code -1 on the ResultReceiver and a SecurityException instead of command execution.
- New @hide static API Binder.enforceShellCommandUid, available to other services.
- The failure path of the default Binder.onShellCommand now skips the send if the ResultReceiver is null (that parameter is annotated @NonNull).
Per major
- Android 14: same fix: platform/frameworks/base 7a769205eb33 in android-security-14.0.0_r31. Same code change in both files (Binder.java helper plus the WindowManagerService.onShellCommand gate), at different line offsets and with one extra blank javadoc line. 8/8 patched lines present.
- Android 15: same fix: platform/frameworks/base cc11ec1d5cdd in android-security-15.0.0_r19, the analysed commit. 8/8 patched lines present.
- Android 16: same fix: platform/frameworks/base b13f68610604 in android-security-16.0.0_r10. Same code change, at different line offsets and with one extra blank javadoc line. 8/8 patched lines present.
- Android 17: same fix: platform/frameworks/base c159476c145c in android-security-17.0.0_r3. Same code change, at different line offsets and with one extra blank javadoc line. 8/8 patched lines present.
Unknowns
- Which WindowManagerShellCommand subcommands were reachable and what privileged effects they had (the material does not include WindowManagerShellCommand).
- Whether the two Cherrypick-From sources correspond separately to the Binder helper and the WMS change, or to something else.
- Content of the referenced test (atest DisplayAreaTest) is not in the material.
- Whether other onShellCommand overriders perform caller checks inside their ShellCommand implementations.