> mm, bpf: introduce bpf_oom_kill_process() BPF kfunc TL;DR: bpf_oom_kill_process() may kill an OOM_SCORE_ADJ_MIN-protected vfork parent, because it doesn't reject in_vfork() tasks like oom_badness() does. The kill could also free no memory. > diff --git a/mm/oom_kill.c b/mm/oom_kill.c > --- a/mm/oom_kill.c > +++ b/mm/oom_kill.c [ ... ] > +__bpf_kfunc int bpf_oom_kill_process(struct oom_control *oc, > + struct task_struct *task, > + const char *message__str) > +{ > + struct task_struct *p; > + > + if (oom_unkillable_task(task)) > + return -EPERM; > + > + if (oc->memcg && !mem_cgroup_task_in_hierarchy(task, oc->memcg)) > + return -EINVAL; > + > + p = find_lock_task_mm(task); > + if (!p) > + return -ESRCH; > + > + if (p->signal->oom_score_adj == OOM_SCORE_ADJ_MIN) { > + task_unlock(p); > + return -EINVAL; > + } > + > + if (mm_flags_test(MMF_OOM_SKIP, p->mm)) { > + task_unlock(p); > + return -ESRCH; > + } > + > + /* paired with put_task_struct() in oom_kill_process() */ > + get_task_struct(p); > + task_unlock(p); > + > + oc->chosen = p; > + oom_kill_process(oc, message__str); Can this kill a task that is protected with OOM_SCORE_ADJ_MIN? The checks here mirror the exclusions in oom_badness(), but in_vfork() is not among them: adj = (long)p->signal->oom_score_adj; if (adj == OOM_SCORE_ADJ_MIN || mm_flags_test(MMF_OOM_SKIP, p->mm) || in_vfork(p)) { __set_oom_adj() skips vfork children, so a vfork child can hold a different oom_score_adj than the parent it shares an mm with. For example: P has oom_score_adj = OOM_SCORE_ADJ_MIN and calls vfork() child C raises its own oom_score_adj to 0 before exec the bpf_oom_ops handler picks C (it reports the full RSS of P's mm) bpf_oom_kill_process(oc, C, ...) passes every check above oom_kill_process() then reaches __oom_kill_process(), which sends SIGKILL to every process sharing the victim's mm without checking oom_score_adj: for_each_process(p) { if (!process_shares_mm(p, mm)) continue; ... do_send_sig_info(SIGKILL, SEND_SIG_PRIV, p, PIDTYPE_TGID); } So P is killed as well, which contradicts the commit message statement that tasks protected with OOM_SCORE_ADJ_MIN "are rejected in the kernel". Killing C also frees no memory, since P still pins the mm. If init is the vfork parent, __oom_kill_process() sets MMF_OOM_SKIP on init's mm and skips the reaper, so the kill makes no progress. Should the kfunc also reject in_vfork(p) while holding task_lock(p), as oom_badness() does? bpf_oom_kill_process() is unchanged at the end of the series, so this is not fixed by a later patch. > + oc->chosen = NULL; > + > + return 0; > +} [ ... ] --- AI reviewed your patch. Please fix the bug or email reply why it's not a bug. See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md CI run summary: https://github.com/kernel-patches/bpf/actions/runs/46974333971