From: Breno Leitao <leitao@debian.org>
To: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: netdev@vger.kernel.org, Jiri Pirko <jiri@resnulli.us>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
stable@vger.kernel.org, vega@nebusec.ai,
Victor Nogueira <victor@mojatatu.com>,
Panagiotis Issaris <takis@issaris.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>
Subject: Re: [PATCH net] net/sched: account classifier filter allocations to memcg
Date: Wed, 19 Aug 2026 09:42:59 -0700 [thread overview]
Message-ID: <aoXc9DH1G6aLtC0I@gmail.com> (raw)
In-Reply-To: <20260819143733.57538-1-jhs@mojatatu.com>
On Wed, Aug 19, 2026 at 10:37:33AM -0400, Jamal Hadi Salim wrote:
> Allocations in the tc classifier *_change() paths (filter objects,
> per-CPU counters, and per-filter aux data) use plain GFP_KERNEL without
> __GFP_ACCOUNT, allowing unprivileged users to pin kernel memory outside
> memcg charging. The shared tcf_exts_init_ex() action array allocation in
> cls_api.c was also uncharged; this patch closes it along with the
> per-classifier filter-object/percpu/aux allocations that remain
> unaccounted.
>
> Add GFP_KERNEL_ACCOUNT to:
> - the shared tcf_exts_init_ex() action array (cls_api.c), common to every
> filter of every classifier (32 pointers, 256 bytes);
> - the filter-object, per-CPU-counter, and per-filter aux allocations in
> cls_basic, cls_bpf, cls_cgroup, cls_flow, cls_flower, cls_fw,
> cls_matchall, cls_route and cls_u32;
> - the u32_init_knode() replace-path knode allocation (cls_u32.c), which
> allocates the same struct tc_u_knode + sel.keys on every replace of an
> existing knode and was missed by the create-path-only conversion.
>
> Also fix the cls_basic error path: basic_change() inserts fnew into the
> IDR before allocating the per-CPU counter. If alloc_percpu() fails the
> errout path kfree'd fnew without idr_remove, leaving a dangling pointer
> in the IDR. With GFP_KERNEL_ACCOUNT the percpu alloc becomes failable
> on demand (memcg at memory.max), making the dead path attacker-reachable
> and burning the handle permanently. Add the idr_remove on the percpu
> failure path, matching the basic_set_parms failure-path pattern.
>
> Note: vega@nebusec.ai provided a poc for basic_cls, but it was easy to
> extend to the other classifiers.
>
> Conditions to recreate the bug:
> - CONFIG_NET_SCHED, CONFIG_NET_CLS_* (the classifier being used),
> CONFIG_NET_CLS_ACT, CONFIG_MEMCG, CONFIG_USER_NS, CONFIG_NET_NS.
> - Unprivileged user in a fresh user+network namespace (unshare -Urn),
> or root with CAP_NET_ADMIN.
> - Create a large number of tc filters (e.g. tc filter add dev lo
> ingress ... <classifier> ...) while watching a memcg-limited cgroup:
> system slab grows far faster than memory.current, pinning kernel
> memory outside memcg charging.
>
> Fixes: 0da974f4f303 ("[NET]: Conversions from kmalloc+memset to k(z|c)alloc.")
> Reported-by: vega@nebusec.ai
> Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
Reviewed-by: Breno Leitao <leitao@debian.org>
prev parent reply other threads:[~2026-08-19 16:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-19 14:37 [PATCH net] net/sched: account classifier filter allocations to memcg Jamal Hadi Salim
2026-08-19 16:42 ` Breno Leitao [this message]
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=aoXc9DH1G6aLtC0I@gmail.com \
--to=leitao@debian.org \
--cc=ast@kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stable@vger.kernel.org \
--cc=takis@issaris.org \
--cc=vega@nebusec.ai \
--cc=victor@mojatatu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.