net/sched: act_api: use mutex in tcf_idr_check_alloc
Subsystems (3)
PATCH 1/1 net/sched: act_api: use mutex in tcf_idr_check_alloc
Currently, the NEWTFILTER path uses RCU to guard action idr accesses while the DELTFILTER path uses mutex to guard action accesses. This inconsistency leads to a race condition scenario, which can lead to erroneous operations on refcount, eventually leading to use-after-free situation.
In this patch, we revert the introduction of RCU back to mutex in the NEWFILTER path, which is consistent with the DELFILTER path, avoiding the race condition.
--- net/sched/act_api.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
net/sched/act_api.c +5 -7
@@ -874,36 +874,34 @@ int tcf_idr_check_alloc(struct tc_action_net *tn, u32 *index,u32 max;if (*index) { -rcu_read_lock (); +mutex_lock (&idrinfo->lock); p =idr_find (&idrinfo->action_idr, *index);if (IS_ERR (p)) {/* This means that another process allocated * index but did not assign the pointer yet. */ -rcu_read_unlock (); +mutex_unlock (&idrinfo->lock);return -EAGAIN ; }if (!p) {/* Empty slot, try to allocate it */ max = *index; -rcu_read_unlock (); +mutex_unlock (&idrinfo->lock); goto new; }if (!refcount_inc_not_zero (&p->tcfa_refcnt)) {/* Action was deleted in parallel */ -rcu_read_unlock (); +mutex_unlock (&idrinfo->lock);return -EAGAIN ; }if (bind)atomic_inc (&p->tcfa_bindcnt); *a = p; - -rcu_read_unlock (); - +mutex_unlock (&idrinfo->lock);return 1 ; }else {/* Find a slot */
Signature · 1 line
2.54.0
Quoted 10 lines · Kyle Zeng
Currently, the NEWTFILTER path uses RCU to guard action idr accesses while the DELTFILTER path uses mutex to guard action accesses. This inconsistency leads to a race condition scenario, which can lead to erroneous operations on refcount, eventually leading to use-after-free situation.
In this patch, we revert the introduction of RCU back to mutex in the NEWFILTER path, which is consistent with the DELFILTER path, avoiding the race condition.
Quoted 2 lines
Fixes 4b55e86736d5 ("net/sched: act_api: rely on rcu in tcf_idr_check_alloc")Signed-off-by Kyle Zeng <[email protected]>
cheers,
jamal
Quoted 53 lines
--- net/sched/act_api.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)net/sched/act_api.c +5
-8@@ -874,36 +874,34 @@ int tcf_idr_check_alloc(struct tc_action_net *tn, u32 *index,u32 max;if (*index) { -rcu_read_lock (); +mutex_lock (&idrinfo->lock); p =idr_find (&idrinfo->action_idr, *index);if (IS_ERR (p)) {/* This means that another process allocated * index but did not assign the pointer yet. */ -rcu_read_unlock (); +mutex_unlock (&idrinfo->lock);return -EAGAIN ; }if (!p) {/* Empty slot, try to allocate it */ max = *index; -rcu_read_unlock (); +mutex_unlock (&idrinfo->lock); goto new; }if (!refcount_inc_not_zero (&p->tcfa_refcnt)) {/* Action was deleted in parallel */ -rcu_read_unlock (); +mutex_unlock (&idrinfo->lock);return -EAGAIN ; }if (bind)atomic_inc (&p->tcfa_bindcnt); *a = p; - -rcu_read_unlock (); - +mutex_unlock (&idrinfo->lock);return 1 ; }else {/* Find a slot */ --2.54.0
Quoted 11 lines · Kyle Zeng
Currently, the NEWTFILTER path uses RCU to guard action idr accesses while the DELTFILTER path uses mutex to guard action accesses. This inconsistency leads to a race condition scenario, which can lead to erroneous operations on refcount, eventually leading to use-after-free situation.
In this patch, we revert the introduction of RCU back to mutex in the NEWFILTER path, which is consistent with the DELFILTER path, avoiding the race condition.Fixes 4b55e86736d5 ("net/sched: act_api: rely on rcu in tcf_idr_check_alloc")Signed-off-by Kyle Zeng <[email protected]>
Quoted 50 lines
--- net/sched/act_api.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)net/sched/act_api.c +5
-7@@ -874,36 +874,34 @@ int tcf_idr_check_alloc(struct tc_action_net *tn, u32 *index,u32 max;if (*index) { -rcu_read_lock (); +mutex_lock (&idrinfo->lock); p =idr_find (&idrinfo->action_idr, *index);if (IS_ERR (p)) {/* This means that another process allocated * index but did not assign the pointer yet. */ -rcu_read_unlock (); +mutex_unlock (&idrinfo->lock);return -EAGAIN ; }if (!p) {/* Empty slot, try to allocate it */ max = *index; -rcu_read_unlock (); +mutex_unlock (&idrinfo->lock); goto new; }if (!refcount_inc_not_zero (&p->tcfa_refcnt)) {/* Action was deleted in parallel */ -rcu_read_unlock (); +mutex_unlock (&idrinfo->lock);return -EAGAIN ; }if (bind)atomic_inc (&p->tcfa_bindcnt); *a = p; - -rcu_read_unlock (); - +mutex_unlock (&idrinfo->lock);return 1 ; }else {/* Find a slot */
Quoted 11 lines · Kyle Zeng
Currently, the NEWTFILTER path uses RCU to guard action idr accesses while the DELTFILTER path uses mutex to guard action accesses. This inconsistency leads to a race condition scenario, which can lead to erroneous operations on refcount, eventually leading to use-after-free situation.
In this patch, we revert the introduction of RCU back to mutex in the NEWFILTER path, which is consistent with the DELFILTER path, avoiding the race condition.Fixes 4b55e86736d5 ("net/sched: act_api: rely on rcu in tcf_idr_check_alloc")Signed-off-by Kyle Zeng <[email protected]>
Jakub Kicinski
maintainerQuoted 8 lines · On Tue, 26 May 2026 15:08:47 -0700 Kyle Zeng wrote:
Currently, the NEWTFILTER path uses RCU to guard action idr accesses while the DELTFILTER path uses mutex to guard action accesses. This inconsistency leads to a race condition scenario, which can lead to erroneous operations on refcount, eventually leading to use-after-free situation.
In this patch, we revert the introduction of RCU back to mutex in the NEWFILTER path, which is consistent with the DELFILTER path, avoiding the race condition.
The commit message is quite inadequate here. Looks like a run-of-the-mill UAF so you should explain the flow / race that leads to it properly.
Doing some extra digging with Jamal off-list we can't find the reason why normal RCU protection wouldn't work here so maybe hold off reposting until you hear from Jamal.
Jamal Hadi Salim
maintainerQuoted 11 lines · Jakub Kicinski
Quoted 8 lines · On Tue, 26 May 2026 15:08:47 -0700 Kyle Zeng wrote:
Currently, the NEWTFILTER path uses RCU to guard action idr accesses while the DELTFILTER path uses mutex to guard action accesses. This inconsistency leads to a race condition scenario, which can lead to erroneous operations on refcount, eventually leading to use-after-free situation.
In this patch, we revert the introduction of RCU back to mutex in the NEWFILTER path, which is consistent with the DELFILTER path, avoiding the race condition.
Quoted 7 lines
The commit message is quite inadequate here. Looks like a run-of-the-mill UAF so you should explain the flow / race that leads to it properly.
Doing some extra digging with Jamal off-list we can't find the reason why normal RCU protection wouldn't work here so maybe hold off reposting until you hear from Jamal.
Kyle, can you try the attached patch?
cheers,
jamal
I ran the PoC against Jamal's patch (with inserted mdelay calls) multiple times. And I confirm the issue does not reproduce with the new patch.
Best,
Kyle
Quoted 25 lines · Jamal Hadi Salim
Quoted 11 lines · Jakub Kicinski
Quoted 8 lines · On Tue, 26 May 2026 15:08:47 -0700 Kyle Zeng wrote:
Currently, the NEWTFILTER path uses RCU to guard action idr accesses while the DELTFILTER path uses mutex to guard action accesses. This inconsistency leads to a race condition scenario, which can lead to erroneous operations on refcount, eventually leading to use-after-free situation.
In this patch, we revert the introduction of RCU back to mutex in the NEWFILTER path, which is consistent with the DELFILTER path, avoiding the race condition.Quoted 7 lines
The commit message is quite inadequate here. Looks like a run-of-the-mill UAF so you should explain the flow / race that leads to it properly.
Doing some extra digging with Jamal off-list we can't find the reason why normal RCU protection wouldn't work here so maybe hold off reposting until you hear from Jamal.
Kyle, can you try the attached patch?
cheers,
jamal
Jamal Hadi Salim
maintainerQuoted 5 lines · Kyle Zeng
I ran the PoC against Jamal's patch (with inserted mdelay calls) multiple times. And I confirm the issue does not reproduce with the new patch.
Thanks Kyle. I will send the patch shortly.
cheers,
jamal
Quoted 29 lines
Best,
KyleQuoted 25 lines · Jamal Hadi Salim
Quoted 11 lines · Jakub Kicinski
Quoted 8 lines · On Tue, 26 May 2026 15:08:47 -0700 Kyle Zeng wrote:
Currently, the NEWTFILTER path uses RCU to guard action idr accesses while the DELTFILTER path uses mutex to guard action accesses. This inconsistency leads to a race condition scenario, which can lead to erroneous operations on refcount, eventually leading to use-after-free situation.
In this patch, we revert the introduction of RCU back to mutex in the NEWFILTER path, which is consistent with the DELFILTER path, avoiding the race condition.Quoted 7 lines
The commit message is quite inadequate here. Looks like a run-of-the-mill UAF so you should explain the flow / race that leads to it properly.
Doing some extra digging with Jamal off-list we can't find the reason why normal RCU protection wouldn't work here so maybe hold off reposting until you hear from Jamal.
Kyle, can you try the attached patch?
cheers,
jamal
Jamal Hadi Salim
maintainerQuoted 5 lines · Kyle Zeng
I ran the PoC against Jamal's patch (with inserted mdelay calls) multiple times. And I confirm the issue does not reproduce with the new patch.
Can you test v2 and put your tested-by if it passes. Sorry, there were issues caught by syzbot.
cheers,
jamal
Quoted 29 lines
Best,
KyleQuoted 25 lines · Jamal Hadi Salim
Quoted 11 lines · Jakub Kicinski
Quoted 8 lines · On Tue, 26 May 2026 15:08:47 -0700 Kyle Zeng wrote:
Currently, the NEWTFILTER path uses RCU to guard action idr accesses while the DELTFILTER path uses mutex to guard action accesses. This inconsistency leads to a race condition scenario, which can lead to erroneous operations on refcount, eventually leading to use-after-free situation.
In this patch, we revert the introduction of RCU back to mutex in the NEWFILTER path, which is consistent with the DELFILTER path, avoiding the race condition.Quoted 7 lines
The commit message is quite inadequate here. Looks like a run-of-the-mill UAF so you should explain the flow / race that leads to it properly.
Doing some extra digging with Jamal off-list we can't find the reason why normal RCU protection wouldn't work here so maybe hold off reposting until you hear from Jamal.
Kyle, can you try the attached patch?
cheers,
jamal