mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: bot+bpf-ci@kernel.org
To: bgardon@google.com,ast@kernel.org,daniel@iogearbox.net,andrii@kernel.org,akpm@linux-foundation.org,hannes@cmpxchg.org,mhocko@kernel.org,shakeel.butt@linux.dev,roman.gushchin@linux.dev,tj@kernel.org
Cc: jp.kobryn@linux.dev,eddyz87@gmail.com,memxor@gmail.com,martin.lau@linux.dev,song@kernel.org,yonghong.song@linux.dev,jolsa@kernel.org,emil@etsalapatis.com,ihor.solodrai@linux.dev,rientjes@google.com,surenb@google.com,joshdon@google.com,sweettea-kernel@dorminy.me,zhouchuyi@bytedance.com,laoar.shao@gmail.com,benbwgardon@gmail.com,bpf@vger.kernel.org,linux-mm@kvack.org,cgroups@vger.kernel.org,linux-kernel@vger.kernel.org,bgardon@google.com,shuah@kernel.org,linux-kselftest@vger.kernel.org,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf-next v4 14/17] selftests/bpf: Add negative and verifier tests for BPF OOM kfuncs
Date: Wed,  2 Dec 2026 21:58:45 +0000 (UTC)	[thread overview]
Message-ID: <1b32a0a4bbe62cb2ff6335450462becf094e1740c78a7a2bbd35fc44c6a7e366@mail.kernel.org> (raw)
In-Reply-To: <20261202210415.517651-15-bgardon@google.com>

[-- Attachment #1: Type: text/plain, Size: 3195 bytes --]

> selftests/bpf: Add negative and verifier tests for BPF OOM kfuncs

TL;DR: Test issue: the global proactive-kill selftest may SIGKILL unrelated
host tasks or whole cgroups (test_progs included) outside the root pid
namespace or with memory.oom.group set; the worker also isn't put in a test
cgroup.

> diff --git a/tools/testing/selftests/bpf/prog_tests/test_oom_kfunc_neg.c b/tools/testing/selftests/bpf/prog_tests/test_oom_kfunc_neg.c
> new file mode 100644
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/test_oom_kfunc_neg.c

[ ... ]

> +void serial_test_oom_kfunc_neg(void)
> +{

[ ... ]

> +	memory_holder_init(&worker);

[ ... ]

> +	/* Global proactive kill (origin__nullable == NULL) must succeed */
> +	args.cgroup_id = 0;
> +	args.pid = worker.pid;
> +	args.flags = 0;
> +	args.wait_on_oom_lock = 1;
> +	if (!ASSERT_OK(bpf_prog_test_run_opts(prog_fd, &topts), "run_global") ||
> +	    !ASSERT_OK((int)topts.retval, "global_retval"))
> +		goto cleanup;
> +
> +	ASSERT_EQ(waitpid(worker.pid, &status, 0), worker.pid, "waitpid_global");

Can this global kill hit processes other than the worker?

With origin == NULL, bpf_oom_proactive_kill() skips the
mem_cgroup_task_in_hierarchy() check, so only the pid lookup and the
bpf_oom_kill_process() checks guard the victim.

proactive_kill_prog() resolves the victim with bpf_task_from_pid(), which
uses find_task_by_pid_ns(pid, &init_pid_ns).  worker.pid is the value
fork() returned in test_progs' own pid namespace.  If test_progs runs in a
non-root pid namespace, such as a privileged container, whichever host
task has that pid number gets SIGKILL and the call returns 0.  The real
worker is never signalled, so waitpid(worker.pid, ...) blocks until the
watchdog fires.

The worker is also never moved into a test cgroup, unlike test_oom.c,
test_oomd.c, test_psi.c and test_oom_proactive_kill.c, which call
setup_cgroup_environment().  It stays in test_progs' memory cgroup.  With
oc->memcg == NULL, oom_kill_process() calls mem_cgroup_get_oom_group(victim,
NULL), which walks up to the root:

    for (; memcg; memcg = parent_mem_cgroup(memcg)) {
        if (READ_ONCE(memcg->oom_group))
            oom_group = memcg;

        if (memcg == oom_domain)
            break;
    }

and then mem_cgroup_scan_tasks(oom_group, oom_kill_memcg_member, ...) sends
SIGKILL to every task in that group.  If any non-root ancestor of
test_progs' cgroup has memory.oom.group=1, for example a systemd unit with
OOMPolicy=kill, would this kill test_progs and every other process in that
cgroup?

In the usual vmtest setup (root cgroup, root pid namespace) neither case
occurs.

Would it make sense to place the worker in a cgroup created with
setup_cgroup_environment()/create_and_get_cgroup() as the sibling test
does, and either skip the global case when not in the root pid namespace,
or have the BPF program check that the task it found is the caller's child
(or use bpf_task_from_vpid())?


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

  reply	other threads:[~2026-12-02 21:58 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 21:03 [PATCH bpf-next v4 00/17] mm: BPF OOM Ben Gardon
2026-12-02 21:03 ` [PATCH bpf-next v4 01/17] bpf: mark struct oom_control's memcg field as TRUSTED_OR_NULL Ben Gardon
2026-12-02 21:03 ` [PATCH bpf-next v4 02/17] mm, bpf: introduce BPF OOM struct ops Ben Gardon
2026-12-02 21:59   ` bot+bpf-ci
2026-12-03  5:40   ` kernel test robot
2026-12-02 21:03 ` [PATCH bpf-next v4 03/17] mm, bpf: introduce bpf_oom_kill_process() BPF kfunc Ben Gardon
2026-12-02 21:58   ` bot+bpf-ci
2026-12-02 21:03 ` [PATCH bpf-next v4 04/17] mm, bpf: introduce bpf_out_of_memory() " Ben Gardon
2026-12-02 21:59   ` bot+bpf-ci
2026-12-02 21:03 ` [PATCH bpf-next v4 05/17] selftests/bpf: Add BPF OOM struct ops test Ben Gardon
2026-12-02 21:03 ` [PATCH bpf-next v4 06/17] sched/psi: add a tracepoint to psi_avgs_work() Ben Gardon
2026-12-02 21:03 ` [PATCH bpf-next v4 07/17] sched/psi: add cgroup_id field to psi_group structure Ben Gardon
2026-12-02 21:03 ` [PATCH bpf-next v4 08/17] mm, bpf: allow calling bpf_out_of_memory() from a PSI tracepoint Ben Gardon
2026-12-02 21:03 ` [PATCH bpf-next v4 09/17] selftests/bpf: Enable CONFIG_PSI Ben Gardon
2026-12-02 21:04 ` [PATCH bpf-next v4 10/17] selftests/bpf: Add PSI tracepoint OOM test Ben Gardon
2026-12-02 21:04 ` [PATCH bpf-next v4 11/17] selftests/bpf: Add systemd-oomd style OOM policy test Ben Gardon
2026-12-02 21:58   ` bot+bpf-ci
2026-12-02 21:04 ` [PATCH bpf-next v4 12/17] mm, bpf: introduce bpf_oom_proactive_kill() for proactive OOM prevention Ben Gardon
2026-12-02 21:58   ` bot+bpf-ci
2026-12-03  1:19   ` Alexei Starovoitov
2026-12-02 21:04 ` [PATCH bpf-next v4 13/17] selftests/bpf: Add bpf_oom_proactive_kill() proactive OOM test Ben Gardon
2026-12-02 21:04 ` [PATCH bpf-next v4 14/17] selftests/bpf: Add negative and verifier tests for BPF OOM kfuncs Ben Gardon
2026-12-02 21:58   ` bot+bpf-ci [this message]
2026-12-02 21:04 ` [PATCH bpf-next v4 15/17] mm, bpf: introduce bpf_mem_cgroup_raise_max() kfunc Ben Gardon
2026-12-02 21:58   ` bot+bpf-ci
2026-12-02 21:04 ` [PATCH bpf-next v4 16/17] selftests/bpf: Add bpf_mem_cgroup_raise_max() OOM test Ben Gardon
2026-12-02 21:04 ` [PATCH bpf-next v4 17/17] Documentation/bpf: Document BPF OOM handling and kfuncs Ben Gardon
2026-12-02 21:58   ` bot+bpf-ci
2026-12-02 21:38 ` [PATCH bpf-next v4 00/17] mm: BPF OOM Ben Gardon
2026-12-03  1:24 ` Alexei Starovoitov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1b32a0a4bbe62cb2ff6335450462becf094e1740c78a7a2bbd35fc44c6a7e366@mail.kernel.org \
    --to=bot+bpf-ci@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=benbwgardon@gmail.com \
    --cc=bgardon@google.com \
    --cc=bpf@vger.kernel.org \
    --cc=cgroups@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=hannes@cmpxchg.org \
    --cc=ihor.solodrai@linux.dev \
    --cc=jolsa@kernel.org \
    --cc=joshdon@google.com \
    --cc=jp.kobryn@linux.dev \
    --cc=laoar.shao@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=martin.lau@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mason@kernel.org \
    --cc=memxor@gmail.com \
    --cc=mhocko@kernel.org \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=shakeel.butt@linux.dev \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=surenb@google.com \
    --cc=sweettea-kernel@dorminy.me \
    --cc=tj@kernel.org \
    --cc=yonghong.song@linux.dev \
    --cc=zhouchuyi@bytedance.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®