kernel: add missing NULL checks on allocation paths#3572
Open
palazik wants to merge 1 commit into
Open
Conversation
Two allocation sites dereferenced their result without checking for failure, which panics the kernel under memory pressure: - throne_tracker.c: search_manager()'s directory actor allocated a new apk_path_hash node and immediately wrote to it. Skip the entry (like the existing data_path allocation a few lines above) when allocation fails. - sepolicy.c: add_filename_trans() allocated a filename_trans_datum, a filename_trans_key, and kstrdup'd the name, then dereferenced all three unconditionally. Bail out (returning false) and free the partial allocations on failure.
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.
Two kernel allocation sites dereference their result without checking for failure, which panics the kernel under memory pressure.
1.
kernel/manager/throne_tracker.c—my_actor()Every other allocation in this file is checked (e.g. the
data_pathalloc a few lines above skips the entry on failure). This one wasn't. Fixed by skipping the entry (FILLDIR_ACTOR_CONTINUE) when the allocation fails.2.
kernel/selinux/sepolicy.c—add_filename_trans()Three unchecked allocations, all dereferenced immediately. Fixed by checking each and bailing out (
return false, matching the function's existing error style), freeing the partial allocations on the way out.Both are OOM-only robustness fixes; no behavior change on the success path.