Skip to content

kernel: add missing NULL checks on allocation paths#3572

Open
palazik wants to merge 1 commit into
tiann:mainfrom
palazik:fix/kernel-alloc-null-checks
Open

kernel: add missing NULL checks on allocation paths#3572
palazik wants to merge 1 commit into
tiann:mainfrom
palazik:fix/kernel-alloc-null-checks

Conversation

@palazik

@palazik palazik commented Jul 11, 2026

Copy link
Copy Markdown

Two kernel allocation sites dereference their result without checking for failure, which panics the kernel under memory pressure.

1. kernel/manager/throne_tracker.cmy_actor()

struct apk_path_hash *apk_data = kzalloc(sizeof(struct apk_path_hash), GFP_KERNEL);
apk_data->hash = hash;   // NULL deref if kzalloc fails

Every other allocation in this file is checked (e.g. the data_path alloc 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.cadd_filename_trans()

trans = kcalloc(1, sizeof(*trans), GFP_KERNEL);
struct filename_trans_key *new_key = kzalloc(sizeof(*new_key), GFP_KERNEL);
*new_key = key;                        // NULL deref
new_key->name = kstrdup(key.name, ..); // unchecked
trans->next = last;                    // NULL deref

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.

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.
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.

1 participant