From: Pablo Neira Ayuso <pablo@netfilter.org>
To: ZhilingZouzhilinz@nebusec.ai
Cc: netfilter-devel@vger.kernel.org, fw@strlen.de, phil@nwl.cc,
davem@davemloft.net, edumazet@google.com, pabeni@redhat.com,
horms@kernel.org, kaber@trash.net, vega@nebusec.ai,
zhilinz@nebusec.ai
Subject: Re: [PATCH nf 1/1] netfilter: xt_string: account textsearch configs
Date: Mon, 17 Aug 2026 17:48:09 +0200 [thread overview]
Message-ID: <aoMtOeAlywLdU5Pl@chamomile> (raw)
In-Reply-To: <9b7e9680b6908b65318a6f68b4228845eec38553.1786970189.git.zhilinz@nebusec.ai>
On Mon, Aug 17, 2026 at 08:44:55PM +0800, ZhilingZouzhilinz@nebusec.ai wrote:
> From: Zhiling Zou <zhilinz@nebusec.ai>
>
> string_mt_check() creates a textsearch configuration for every string
> match with GFP_KERNEL. Algorithm-private data, including Boyer-Moore
> tables,
Why the reference to Boyer-Moore? It looks a bit gratuitous? :-)
How does it relate to this issue at all? Knuth-Pratt-Morris
implementation also performs an internal memory allocation from
->init() path.
> [...] remains allocated for as long as the rule is installed.
>
> The xtables table blob is memcg accounted, but the textsearch
> configuration is not. A user with CAP_NET_ADMIN in a user and network
> namespace can therefore retain kernel memory outside its memory limit
> by installing many string matches.
This is news to me that you consider this a security issue... but fair
enough. We have taken many patches like this for net-next in the past.
We have more paths that could use GFP_KERNEL_ACCOUNT in x_tables, but
some of them need careful look because they might break existing
setups.
net/netfilter/x_tables.c: table = kmemdup(input_table, sizeof(struct xt_table), GFP_KERNEL);
net/netfilter/xt_CT.c: ct = nf_ct_tmpl_alloc(par->net, &zone, GFP_KERNEL);
net/netfilter/xt_IDLETIMER.c: info->timer->attr.attr.name = kstrdup(info->label, GFP_KERNEL);
net/netfilter/xt_IDLETIMER.c: info->timer->attr.attr.name = kstrdup(info->label, GFP_KERNEL);
net/netfilter/xt_LED.c: ledinternal->trigger_id = kstrdup(ledinfo->id, GFP_KERNEL);
net/netfilter/xt_dccp.c: dccp_optbuf = kmalloc(256 * 4, GFP_KERNEL);
net/netfilter/xt_hashlimit.c: hinfo->name = kstrdup(name, GFP_KERNEL);
net/netfilter/xt_repldata.h: tbl = kzalloc(term_offset + sizeof(*term), GFP_KERNEL);
I can post a patch to address this, no need for you to post it.
> Use GFP_KERNEL_ACCOUNT for the textsearch configuration so it is
> charged with the rest of the rule state.
textsearch_prepare also in net/sched/em_text.c uses GFP_KERNEL, maybe
you want to "fix" all textsearch_prepare() prepare callers?
Maybe you can just remove the allocation flag for textsearch_prepare()
and use GFP_KERNEL_ACCOUNT inconditionally.
> Fixes: 7567662ba896 ("[NETFILTER]: Add string match")
GFP_KERNEL_ACCOUNT came later than lib/textsearch.c, so this was never
converted to use it.
This Fixes: tag cannot be right.
> Cc: stable@vger.kernel.org
> Reported-by: Vega <vega@nebusec.ai>
> Signed-off-by: Zhiling Zou <zhilinz@nebusec.ai>
> ---
> net/netfilter/xt_string.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/netfilter/xt_string.c b/net/netfilter/xt_string.c
> index 8ce25bc9b2775..52c1deb02cdc6 100644
> --- a/net/netfilter/xt_string.c
> +++ b/net/netfilter/xt_string.c
> @@ -54,7 +54,7 @@ static int string_mt_check(const struct xt_mtchk_param *par)
> if (conf->u.v1.flags & XT_STRING_FLAG_IGNORECASE)
> flags |= TS_IGNORECASE;
> ts_conf = textsearch_prepare(conf->algo, conf->pattern, conf->patlen,
> - GFP_KERNEL, flags);
> + GFP_KERNEL_ACCOUNT, flags);
> if (IS_ERR(ts_conf))
> return PTR_ERR(ts_conf);
>
> --
> 2.43.0
>
prev parent reply other threads:[~2026-08-17 15:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-17 12:44 [PATCH nf 0/1] netfilter: xt_string: account textsearch configs Zhiling
2026-08-17 12:44 ` [PATCH nf 1/1] " Zhiling
2026-08-17 15:48 ` Pablo Neira Ayuso [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=aoMtOeAlywLdU5Pl@chamomile \
--to=pablo@netfilter.org \
--cc=ZhilingZouzhilinz@nebusec.ai \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=fw@strlen.de \
--cc=horms@kernel.org \
--cc=kaber@trash.net \
--cc=netfilter-devel@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=phil@nwl.cc \
--cc=vega@nebusec.ai \
--cc=zhilinz@nebusec.ai \
/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.