Skip to content

fix(samsung): restore late-load ksud initialization on restricted Samsung kernels - #9

Open
chloropine wants to merge 1 commit into
diabl0w:mainfrom
chloropine:fix/samsung-late-load-ksud
Open

chloropine wants to merge 1 commit into
diabl0w:mainfrom
chloropine:fix/samsung-late-load-ksud

Conversation

@chloropine

Copy link
Copy Markdown

Summary

Restore functional ksud initialization on Samsung kernels where the KernelSU module can load successfully but userspace cannot reacquire the driver FD or install /data/adb/ksud.

Original failure

DFRoot reported that ksud started and the Manager detected KernelSU in jailbreak/LKM mode, but the Superuser list did not load and executed ksud instances could not obtain the [ksu_driver] FD. After driver recovery, installation stopped at:

Failed to change SELinux context for /data/adb/ksud: Invalid argument

This is the KernelSU-side failure class described in DFRoot discussion #69.

Fixes

  1. Preserve the existing reboot kprobe and add a fallback through the already active syscall dispatcher. Both paths share one helper that installs the anonymous driver FD, copies it to userspace, and closes it if the copy fails. This handles restricted Samsung kernels where the reboot kprobe cannot be registered or reached while leaving the existing path unchanged.
  2. Keep the normal u:object_r:ksu_file:s0 label attempt. If and only if the active SELinux policy rejects that context with EINVAL, retain the valid context assigned to the newly copied file by the active policy. Empty or unlabeled contexts fall back to system_file; all other labeling errors remain fatal. The final context is read back and logged. Global SELinux remains Enforcing.

Verification

  • cargo ndk -t arm64-v8a check
  • cargo ndk -t arm64-v8a clippy
  • cargo fmt --check
  • cargo ndk -t arm64-v8a -P 31 build --release
  • Android 13 5.15 DDK module build using android13-5.15-20260828, including check_symbol
  • git diff --check

The reporter confirmed that the resulting build works on a locked Straight Talk Galaxy A15 5G (SM-S156V, MT6835, Android 16, kernel 5.15.189-android13-8-33641424): the Superuser UI loads and authorized Termux root works. Exact su -c id output was not provided, so no command output is quoted here.

Scope and caveats

No bootloader unlock, partition flashing, SELinux disablement, or Knox modification is introduced. Compatibility beyond the reported device and any Knox impact remain unverified.

Thanks to the original KernelSU developers and contributors, diabl0w for the Samsung/DFRoot integration, and the developers who documented Samsung SEPF behavior.

moesuito added a commit to moesuito/KernelSU that referenced this pull request Nov 23, 2026
This fork only exists to validate diabl0w/KernelSU PR diabl0w#9 on the Galaxy S23 Ultra (SM-S918B, android13-5.15). It will not be maintained; the tested APK is linked from the release and the upstream project should be used instead.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@moesuito

moesuito commented Nov 23, 2026 •

Copy link
Copy Markdown

Validated this PR on a Samsung Galaxy S23 Ultra (SM-S918B, One UI 9 / Android 17,
firmware S918BXXUAGZIF, kernel 5.15.197-android13-8, KMI android13-5.15) with DFRoot
temporary root. Built from main @ 76a088c5 + this PR (5eed7735).

All tested flows pass:

  • DFRoot LAUNCH ROOT succeeds (the reboot kprobe path is blocked on this kernel; the
    syscall-dispatcher fallback is used).
  • KernelSU detects jailbreak/LKM mode.
  • The SuperUser tab loads normally (no infinite "Refreshing…").
  • adb shell su -c id returns uid=0(root).
  • Module ZIP installation succeeds; the previous Error: No such file or directory (os error 2)
    is gone.

Build-side note only: on a Windows checkout (core.autocrlf=true), installer.sh was embedded
with CRLF and broke module installs (umask: illegal mode: 022). Rebuilding with LF fixed it.
This is unrelated to the PR logic; no kernel changes beyond the PR were required.

Tested APK (frozen validation fork, not maintained):
https://github.com/moesuito/KernelSU/releases/tag/samsung-v2.2-pr9-s23-lf

This was validated only on the SM-S918B above; other Samsung KMIs were not tested. The fix
addresses the exact S23 Ultra failure class from
DFRoot discussion #69, so I'd encourage
merging it.

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.

2 participants