fix(kernel): observer init error handling and sucompat error overwrite#3597
Open
EasyGuo114514 wants to merge 3 commits into
Open
fix(kernel): observer init error handling and sucompat error overwrite#3597EasyGuo114514 wants to merge 3 commits into
EasyGuo114514 wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves KernelSU kernel-side robustness and observability by fixing two error-handling issues: (1) propagating failures from the package observer initialization, and (2) preventing escape_with_root_profile() status from being overwritten before sucompat logging.
Changes:
- Return and log
watch_one_dir()failures fromksu_observer_init()instead of always returning success. - Preserve
escape_with_root_profile()’s return value for sulog emission, independent of the laterexecveat()result.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| kernel/manager/pkg_observer.c | Adds error handling for observer init; needs additional safety to avoid double-put/UAF on module exit when init fails. |
| kernel/feature/sucompat.c | Separates profile-escape status from execveat result for correct sucompat sulog reporting; minor type cleanup recommended. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+115
to
+119
| if (ret) { | ||
| pr_err("observer init failed: %d\n", ret); | ||
| fsnotify_put_group(g); | ||
| return ret; | ||
| } |
ksu_observer_init() called watch_one_dir() and stored the return value in 'ret', but unconditionally returned 0 regardless of the result. If the /data/system directory could not be watched (e.g., path not ready, inode mark registration failed), the caller had no way to detect the failure and would assume the observer was operational. Return the actual error code and properly release the fsnotify group on failure to prevent a resource leak. Signed-off-by: EasyGuo114514 <2025520491@qq.com>
…itten In ksu_handle_execve_sucompat(), the return value of escape_with_root_profile() was stored in 'ret', which was then immediately overwritten by the execveat result. If the profile escape failed, the su execution would still proceed as if it succeeded, potentially running with incorrect privileges. Use a scoped local variable to keep the profile error separate from the execveat result, ensuring the sulog captures the correct status without interfering with execution flow. Signed-off-by: EasyGuo114514 <2025520491@qq.com>
… mismatch - Set g = NULL after fsnotify_put_group in ksu_observer_init error path to prevent use-after-free in ksu_observer_exit on module unload - Change profile_ret from long to int to match escape_with_root_profile return type and ksu_sulog_emit_pending parameter type Signed-off-by: EasyGuo114514 <2025520491@qq.com>
EasyGuo114514
force-pushed
the
fix/kernel-error-handling
branch
from
July 23, 2026 11:25
9fd27ff to
b98dc04
Compare
Author
|
fix it |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Details
1. ksu_observer_init returns error instead of always 0
ksu_observer_init() called watch_one_dir() and stored the return value in ret, but unconditionally returned 0 regardless of the result. Callers in init.c and boot_event.c had no way to detect the failure. Also fixes fsnotify_group leak on the error path.
2. escape_with_root_profile error overwritten by execveat result
In ksu_handle_execve_sucompat(), the return value of escape_with_root_profile() was stored in ret, which was immediately overwritten by the execveat result. A scoped local variable now keeps the profile error separate, ensuring sulog captures the correct status.
Changed files
Generated with Claude Code