Skip to contentSkip to conversation

net/sched: cls_api: Initialize miss_cookie_node when action miss is not used

PATCH Applied Ivan Vecera 4 participants 4 messages Apr 20, 2023 – Apr 22, 2023

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

PATCH v2 1/1 net/sched: cls_api: Initialize miss_cookie_node when action miss is not used

Function tcf_exts_init_ex() sets exts->miss_cookie_node ptr only when use_action_miss is true so it assumes in other case that the field is set to NULL by the caller. If not then the field contains garbage and subsequent tcf_exts_destroy() call results in a crash.
Ensure that the field .miss_cookie_node pointer is NULL when use_action_miss parameter is false to avoid this potential scenario.

Fixes 80cd22c35c90 ("net/sched: cls_api: Support hardware miss to tc action")
---
 net/sched/cls_api.c | 1 +
 1 file changed, 1 insertion(+)
net/sched/cls_api.c +1 -0
index 35785a36c80298..3c3629c9e7b65c 100644
@@ -3211,6 +3211,7 @@ int tcf_exts_init_ex(struct tcf_exts *exts, struct net *net, int action,
 #ifdef CONFIG_NET_CLS_ACT
 	exts->type = 0;
 	exts->nr_actions = 0;
+	exts->miss_cookie_node = NULL;
 	/* Note: we do not own yet a reference on net.
 	 * This reference might be taken later from tcf_exts_get_net().
 	 */
Signature · 1 line
2.39.2
Reviewed-by on v2 1/1
#1 lore raw
Quoted 19 lines · Ivan Vecera

Function tcf_exts_init_ex() sets exts->miss_cookie_node ptr only when use_action_miss is true so it assumes in other case that the field is set to NULL by the caller. If not then the field contains garbage and subsequent tcf_exts_destroy() call results in a crash.
Ensure that the field .miss_cookie_node pointer is NULL when use_action_miss parameter is false to avoid this potential scenario.

Fixes 80cd22c35c90 ("net/sched: cls_api: Support hardware miss to tc action")
---
  net/sched/cls_api.c | 1 +
  1 file changed, 1 insertion(+)
net/sched/cls_api.c +0 -0
index 35785a36c80298..3c3629c9e7b65c 100644

net/sched/cls_api.c int tcf_exts_init_ex(struct tcf_exts *exts, struct net *net, int action, · line 3217

Quoted 7 lines
net/sched/cls_api.c +1 -0
@@ -3211,6 +3211,7 @@ int tcf_exts_init_ex(struct tcf_exts *exts, struct net *net, int action,
  #ifdef CONFIG_NET_CLS_ACT
  	exts->type = 0;
  	exts->nr_actions = 0;
+	exts->miss_cookie_node = NULL;
  	/* Note: we do not own yet a reference on net.
  	 * This reference might be taken later from tcf_exts_get_net().
  	 */
Reviewed-by
#2 lore raw
Quoted 15 lines · Pedro Tammela
Quoted 14 lines · Ivan Vecera

Function tcf_exts_init_ex() sets exts->miss_cookie_node ptr only when use_action_miss is true so it assumes in other case that the field is set to NULL by the caller. If not then the field contains garbage and subsequent tcf_exts_destroy() call results in a crash.
Ensure that the field .miss_cookie_node pointer is NULL when use_action_miss parameter is false to avoid this potential scenario.

Fixes 80cd22c35c90 ("net/sched: cls_api: Support hardware miss to tc action")
---
  net/sched/cls_api.c | 1 +
  1 file changed, 1 insertion(+)
Quoted 14 lines

net/sched/cls_api.c int tcf_exts_init_ex(struct tcf_exts *exts, struct net *net, int action, · line 3217

Quoted 12 lines
net/sched/cls_api.c +1 -0
index 35785a36c80298..3c3629c9e7b65c 100644
@@ -3211,6 +3211,7 @@ int tcf_exts_init_ex(struct tcf_exts *exts, struct net *net, int action,
  #ifdef CONFIG_NET_CLS_ACT
  	exts->type = 0;
  	exts->nr_actions = 0;
+	exts->miss_cookie_node = NULL;
  	/* Note: we do not own yet a reference on net.
  	 * This reference might be taken later from tcf_exts_get_net().
  	 */
#3 lore raw
In reply to Ivan Vecera
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 9 lines · On Thu, 20 Apr 2023 20:36:33 +0200 you wrote:

Function tcf_exts_init_ex() sets exts->miss_cookie_node ptr only when use_action_miss is true so it assumes in other case that the field is set to NULL by the caller. If not then the field contains garbage and subsequent tcf_exts_destroy() call results in a crash.
Ensure that the field .miss_cookie_node pointer is NULL when use_action_miss parameter is false to avoid this potential scenario.

[...]

Here is the summary with links:
- [net,v2] net/sched: cls_api: Initialize miss_cookie_node when action miss is not used

    https://git.kernel.org/netdev/net/c/2cc8a008d62f

You are awesome, thank you!

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