Skip to content

kernel: fix raw find_user callsite patching - #17

Merged
backslashxx merged 3 commits into
aerath-stuff:masterfrom
JoyElliot:fix-raw-hook-cfi
Nov 16, 2026
Merged

backslashxx merged 3 commits into
aerath-stuff:masterfrom
JoyElliot:fix-raw-hook-cfi

Conversation

@JoyElliot

Copy link
Copy Markdown
Contributor

On a Redmi Note 12 Turbo (marble, 5.10.271-android12), the raw hook failed during initialization and fell back to Kprobes:

fgetpriority: patch_hook: gphook_find_user ret: 0
fgetpriority: arm64_branch_patch: callsite instruction not found!
fgetpriority: init: ret: -2
fgetpriority: init: raw branch patching fail! falling back to kprobes!
fgetpriority: init_kprobe: register find_user kprobe: 0
fgetpriority: init: ok!

With Clang CFI, taking the address of gphook_find_user can yield a jump-table entry. The second scan starts there and misses the call to gp_free_uid in the function body. Reuse the resolved body address for both scans.

The self-recursive placeholder also lets Clang discard the result of the call that will be redirected to find_user. Use a separate assembly stub so the hook preserves the returned pointer and releases its reference when filtering.

After the fix, the same device patched all four syscall callsites and logged:

fgetpriority: getpriority_hook_init: ok!
fgetpriority: init: ret: 0
fgetpriority: init: ok!

Built all eight ARM64 DDK targets locally. On marble, the four priority syscalls matched the original Kprobe behavior for the tested application UIDs. Same-UID operations succeeded, cross-UID lookups succeeded with seccomp disabled, and cross-UID operations returned ESRCH with seccomp enabled.

Resolve the hook body for both internal callsite scans. With Clang CFI, the function pointer can instead refer to a jump table entry.

Call find_user through an assembly stub in modules so the compiler preserves its return value across the runtime patch. Built-in builds can call find_user directly.
@backslashxx

Copy link
Copy Markdown
Collaborator

shut up on the self-recursive hook being removed by clang, its literally attributed.

@backslashxx

backslashxx commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

@JoyElliot try 98abc85

@JoyElliot

Copy link
Copy Markdown
Contributor Author

@JoyElliot try 98abc85

Sorry the PR didn’t meet your expectations. I tested 98abc85 on my device and confirmed that the raw hook initialized successfully without falling back to Kprobes. Thank you very much for your contribution.

@backslashxx

Copy link
Copy Markdown
Collaborator

@JoyElliot try 98abc85

Sorry the PR didn’t meet your expectations. I tested 98abc85 on my device and confirmed that the raw hook initialized successfully without falling back to Kprobes. Thank you very much for your contribution.

no worries, I'll add you as reported by

@backslashxx
backslashxx merged commit 178dd74 into aerath-stuff:master Nov 16, 2026
9 checks passed
@JoyElliot
JoyElliot deleted the fix-raw-hook-cfi branch November 16, 2026 05:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants