* [PATCH net v2] net/sched: act_ife: return -EAGAIN after dropping rtnl_lock in load_metaops_and_vet()
@ 2026-11-22 12:45 YanXin Li via B4 Relay
2026-11-22 17:18 ` Stephen Hemminger
2026-11-23 12:48 ` netdev-bot+sashiko
0 siblings, 2 replies; 3+ messages in thread
From: YanXin Li via B4 Relay @ 2026-11-22 12:45 UTC (permalink / raw)
To: Jamal Hadi Salim, Jiri Pirko, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni
Cc: Simon Horman, netdev, linux-kernel, stable
From: YanXin Li <fadouse@pm.me>
load_metaops_and_vet() unlocks rtnl_lock() to invoke request_module()
when an IFE metadata provider module (such as act_meta_mark) is not
yet loaded, re-acquires rtnl_lock(), validates the metadata attribute,
and returns 0.
Returning 0 after dropping rtnl_lock() violates the serialization
contract of RTNL-locked classifiers (cls_basic, cls_flow, cls_fw,
cls_route, and cls_u32), which hold an unrefcounted filter pointer
(fold) across tcf_exts_validate() -> tcf_ife_init(). A concurrent
RTM_DELTFILTER can delete and RCU-free fold during the unlocked
request_module() window, after which basic_change() executes
list_replace_rcu(&fold->link, &fnew->link) and queues a second
deletion on the freed filter. Generic KASAN reports:
BUG: KASAN: slab-use-after-free in basic_change+0xf4c/0x1220
Read of size 8 at addr ffff88800e043c58 by task test_act_ife_rt/101
...
Allocated by task 101:
basic_change+0x1e0/0x1220
Freed by task 57:
...
Oops: general protection fault, probably for non-canonical address
KASAN: maybe wild-memory-access in range [0xdead000000000120-0xdead000000000127]
Every other TC module autoloader that drops rtnl_lock() during filter
updates (tc_action_load_ops(), tcf_em_validate(), and em_text_change())
returns -EAGAIN so tc_new_tfilter() and tcf_action_add() unwind and
replay under a fresh RTNL critical section.
Manipulating TC filters requires CAP_NET_ADMIN in the target network
namespace, which is reachable by an unprivileged local user inside a
user and network namespace when CONFIG_USER_NS=y, CONFIG_MODULES=y,
CONFIG_NET_ACT_IFE is enabled, and an IFE metadata module is not yet
loaded.
When load_metaops_and_vet() drops rtnl_lock() and loads the requested
metadata module, drop the module reference and return -EAGAIN so the
caller replays the request with fresh lookups. With this change, the
same concurrent RTM_NEWTFILTER and RTM_DELTFILTER sequence cleanly
loads act_meta_mark, replays without touching the deleted filter, and
completes with rc=0 and no KASAN or lockdep reports. A finite
two-thread state-space interleaving model found the old use-after-free
and no use-after-free, double-free, or deadlock in its reachable states
after the change.
The vulnerable code is present in upstream mainline v7.4-rc3.
Runtime verification and fix validation were performed in an x86-64
QEMU/KVM guest running mainline after v7.4-rc3 with Generic KASAN,
UBSAN, and lockdep.
This issue was discovered through LLM-assisted code audit and manual
code inspection of net/sched/act_ife.c.
Fixes: ef6980b6becb ("introduce IFE action")
Cc: stable@vger.kernel.org
Signed-off-by: YanXin Li <fadouse@pm.me>
---
Changes in v2:
- Resend via b4 because the archived v1 email has a corrupted diff and
cannot be applied.
- State how the issue was discovered and clarify the finite model scope.
- Link to v1: https://lore.kernel.org/r/20261122030728.9368-1-fadouse@pm.me
---
net/sched/act_ife.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/net/sched/act_ife.c b/net/sched/act_ife.c
index 5a527da0056..5d6ca124e00 100644
--- a/net/sched/act_ife.c
+++ b/net/sched/act_ife.c
@@ -275,6 +275,14 @@ static int load_metaops_and_vet(u32 metaid, void *val, int len, bool rtnl_held)
if (rtnl_held)
rtnl_lock();
ops = find_ife_oplist(metaid);
+ if (ops && rtnl_held) {
+ /* We dropped the RTNL mutex in order to perform the
+ * module load. Tell the caller to replay the request
+ * under a fresh RTNL critical section.
+ */
+ module_put(ops->owner);
+ return -EAGAIN;
+ }
#endif
}
---
base-commit: c44104f3642da720164042623e4832836aefdd8e
change-id: 20261122-b4-02-act-ife-rtnl-uaf-v2-102eba468698-d819f7ac7006
Best regards,
--
YanXin Li <fadouse@pm.me>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net v2] net/sched: act_ife: return -EAGAIN after dropping rtnl_lock in load_metaops_and_vet()
2026-11-22 12:45 [PATCH net v2] net/sched: act_ife: return -EAGAIN after dropping rtnl_lock in load_metaops_and_vet() YanXin Li via B4 Relay
@ 2026-11-22 17:18 ` Stephen Hemminger
2026-11-23 12:48 ` netdev-bot+sashiko
1 sibling, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2026-11-22 17:18 UTC (permalink / raw)
To: YanXin Li via B4 Relay
Cc: fadouse, Jamal Hadi Salim, Jiri Pirko, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman, netdev,
linux-kernel, stable
On Sun, 22 Nov 2026 20:45:52 +0800
YanXin Li via B4 Relay <devnull+fadouse.pm.me@kernel.org> wrote:
> + if (ops && rtnl_held) {
> + /* We dropped the RTNL mutex in order to perform the
> + * module load. Tell the caller to replay the request
> + * under a fresh RTNL critical section.
> + */
I prefer that comments stay in "short and sweet" style.
AI and new developers seem to like long comments.
This comment has the classic /* add one to i */ style...
In other words the comment doesn't tell human more than is already
obvious from the code.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net v2] net/sched: act_ife: return -EAGAIN after dropping rtnl_lock in load_metaops_and_vet()
2026-11-22 12:45 [PATCH net v2] net/sched: act_ife: return -EAGAIN after dropping rtnl_lock in load_metaops_and_vet() YanXin Li via B4 Relay
2026-11-22 17:18 ` Stephen Hemminger
@ 2026-11-23 12:48 ` netdev-bot+sashiko
1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sashiko @ 2026-11-23 12:48 UTC (permalink / raw)
To: fadouse
Cc: jhs, jiri, davem, edumazet, kuba, pabeni, horms, netdev,
linux-kernel, stable
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] This patch does not fully close the use-after-free it claims to
fix for cls_u32, one of the classifiers named in the commit message.
--
net/sched: act_ife: return -EAGAIN after dropping rtnl_lock in load_metaops_and_vet()
This patch changes load_metaops_and_vet() so that it returns -EAGAIN when
it has dropped rtnl_lock() to autoload an IFE metadata module and the
module then loads. The caller is then expected to replay the request under
a fresh RTNL critical section. The goal is to close a use-after-free in
RTNL-locked classifiers that hold unrefcounted pointers across
tcf_exts_validate().
> diff --git a/net/sched/act_ife.c b/net/sched/act_ife.c
> index 5a527da005661..5d6ca124e0047 100644
> --- a/net/sched/act_ife.c
> +++ b/net/sched/act_ife.c
> @@ -275,6 +275,14 @@ static int load_metaops_and_vet(u32 metaid, void *val, int len, bool rtnl_held)
> if (rtnl_held)
> rtnl_lock();
> ops = find_ife_oplist(metaid);
> + if (ops && rtnl_held) {
> + /* We dropped the RTNL mutex in order to perform the
> + * module load. Tell the caller to replay the request
> + * under a fresh RTNL critical section.
> + */
> + module_put(ops->owner);
> + return -EAGAIN;
> + }
> #endif
> }
[Severity: High]
Does this fully close the race for cls_u32? The commit message lists it as
one of the affected classifiers.
RTNL is still dropped around request_module(). The new -EAGAIN, and the
existing -ENOENT when the module does not load, both go back through the
classifier's error unwind before tc_new_tfilter() gets a chance to replay.
On the new-key path, u32_change() looks up a hash table pointer without
taking a reference. It then reserves a handle in that table and calls
u32_set_parms():
net/sched/cls_u32.c:u32_change() {
...
ht = u32_lookup_ht(tp->data, TC_U32_HTID(htid));
...
handle = gen_new_kid(ht, htid, &err);
...
err = u32_set_parms(net, tp, n, tb, tca[TCA_RATE],
flags, n->flags, extack);
...
}
u32_set_parms() reaches the RTNL drop like this:
u32_set_parms()
tcf_exts_validate_ex()
tcf_action_init()
tcf_ife_init()
load_metalist()
load_metaops_and_vet()
While RTNL is dropped, a concurrent RTM_DELTFILTER for that non-root hash
table can run u32_delete(). The pending knode is not linked yet and holds
no reference on ht, so the delete succeeds:
net/sched/cls_u32.c:u32_delete() {
...
if (refcount_dec_if_one(&ht->refcnt)) {
u32_destroy_hnode(tp, ht, extack);
...
}
u32_destroy_hnode() then calls idr_destroy(&ht->handle_idr) and
kfree_rcu(ht, rcu). request_module() sleeps while it waits for modprobe,
so a grace period can pass and ht can be freed.
When load_metaops_and_vet() then returns -EAGAIN, u32_change() unwinds to:
erridr:
idr_remove(&ht->handle_idr, handle);
return err;
Would this read and write the freed tc_u_hnode before tc_new_tfilter()
ever sees -EAGAIN?
The patch removes the success-path access to the freed table, which is the
ins = &ht->ht[TC_U32_HASH(handle)] lookup and the list insert. The stale
ht is still used on the error path, though.
tc_action_load_ops() also drops RTNL and returns -EAGAIN, so the same
unwind looks reachable through it too. Copying that pattern into act_ife
may therefore not be enough to protect cls_u32.
Could u32_change() hold a reference on ht across u32_set_parms() and drop
it on all exits? Alternatively, could this path avoid dropping RTNL at all?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261122-b4-02-act-ife-rtnl-uaf-v2-102eba468698-v2-1-67c413c45928%40pm.me
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-23 12:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-22 12:45 [PATCH net v2] net/sched: act_ife: return -EAGAIN after dropping rtnl_lock in load_metaops_and_vet() YanXin Li via B4 Relay
2026-11-22 17:18 ` Stephen Hemminger
2026-11-23 12:48 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox