Skip to contentSkip to conversation

net/sched: act_api: avoid dereferencing ERR_PTR in tcf_idrinfo_destroy

PATCH Superseded Shivani Gupta 3 participants 4 messages Jan 2 – Jan 7

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/sched: act_api: avoid dereferencing ERR_PTR in tcf_idrinfo_destroy

syzbot reported a crash in tc_act_in_hw() during netns teardown where tcf_idrinfo_destroy() passed an ERR_PTR(-EBUSY) value as a tc_action pointer, leading to an invalid dereference.

Guard against ERR_PTR entries when iterating the action IDR so teardown does not call tc_act_in_hw() on an error pointer.

---
 net/sched/act_api.c | 4 ++++
 1 file changed, 4 insertions(+)
net/sched/act_api.c +4 -0
index ff6be5cfe2b0..994f7ffe26a5 100644
@@ -940,6 +940,10 @@ void tcf_idrinfo_destroy(const struct tc_action_ops *ops,
 	int ret;
 
 	idr_for_each_entry_ul(idr, p, tmp, id) {
+		if (IS_ERR(p)) {
+			WARN_ON_ONCE(1);
+			continue;
+		}
 		if (tc_act_in_hw(p) && !mutex_taken) {
 			rtnl_lock();
 			mutex_taken = true;
Signature · 1 line
2.34.1
#1 lore raw
Quoted 11 lines · Shivani Gupta

syzbot reported a crash in tc_act_in_hw() during netns teardown where tcf_idrinfo_destroy() passed an ERR_PTR(-EBUSY) value as a tc_action pointer, leading to an invalid dereference.

Guard against ERR_PTR entries when iterating the action IDR so teardown does not call tc_act_in_hw() on an error pointer.

Thanks for the patch, Shivani.

Could you provide a Fixes tag for this while you are on it?

Quoted 9 lines
---
 net/sched/act_api.c | 4 ++++
 1 file changed, 4 insertions(+)
net/sched/act_api.c +0 -0
index ff6be5cfe2b0..994f7ffe26a5 100644

net/sched/act_api.c void tcf_idrinfo_destroy(const struct tc_action_ops *ops, · line 944

Quoted 5 lines
net/sched/act_api.c +2 -0
@@ -940,6 +940,10 @@ void tcf_idrinfo_destroy(const struct tc_action_ops *ops,
 	int ret;
 
 	idr_for_each_entry_ul(idr, p, tmp, id) {
+		if (IS_ERR(p)) {
+			WARN_ON_ONCE(1);

Hm, I guess we should remove this warning here since ERR_PTR is expected in some corner case?

Regards,
Cong Wang

#2 lore raw

PATCH v2 1/1 net/sched: act_api: avoid dereferencing ERR_PTR in tcf_idrinfo_destroy

In reply to Shivani Gupta

syzbot reported a crash in tc_act_in_hw() during netns teardown where tcf_idrinfo_destroy() passed an ERR_PTR(-EBUSY) value as a tc_action pointer, leading to an invalid dereference.

Guard against ERR_PTR entries when iterating the action IDR so teardown does not call tc_act_in_hw() on an error pointer.

Fixes 84a7d6797e6a ("net/sched: acp_api: no longer acquire RTNL in tc_action_net_exit()")
Reported-by [email protected]

---
v2:
- Drop WARN_ON_ONCE() as ERR_PTR can be expected in a corner case.
- Add Fixes: tag.

 net/sched/act_api.c | 3 +++
 1 file changed, 3 insertions(+)
net/sched/act_api.c +3 -0
index ff6be5cfe2b0..5e0a196ce66a 100644
@@ -940,6 +940,9 @@ void tcf_idrinfo_destroy(const struct tc_action_ops *ops,
 	int ret;
 
 	idr_for_each_entry_ul(idr, p, tmp, id) {
+		if (IS_ERR(p)) {
+			continue;
+		}
 		if (tc_act_in_hw(p) && !mutex_taken) {
 			rtnl_lock();
 			mutex_taken = true;
Signature · 1 line
2.34.1
#3 lore raw
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Mon, 5 Jan 2026 00:59:05 +0000 you wrote:

syzbot reported a crash in tc_act_in_hw() during netns teardown where tcf_idrinfo_destroy() passed an ERR_PTR(-EBUSY) value as a tc_action pointer, leading to an invalid dereference.

Guard against ERR_PTR entries when iterating the action IDR so teardown does not call tc_act_in_hw() on an error pointer.

[...]

Here is the summary with links:
- [v2] net/sched: act_api: avoid dereferencing ERR_PTR in tcf_idrinfo_destroy

    https://git.kernel.org/netdev/net/c/adb25a46dc0a

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html