Skip to contentSkip to conversation

net/sched Bind logic fixes for cls_fw, cls_u32 and cls_route

PATCH Applied Jamal Hadi Salim 5 participants 8 messages Jul 29, 2023 – Aug 1, 2023

Subsystems (3)
lore
Share & tools
lore

Jamal Hadi Salim

author maintainer
#0 lore raw

v2 cover net/sched Bind logic fixes for cls_fw, cls_u32 and cls_route

From: valis <[email protected]>

Three classifiers (cls_fw, cls_u32 and cls_route) always copy tcf_result struct into the new instance of the filter on update.

This causes a problem when updating a filter bound to a class, as tcf_unbind_filter() is always called on the old instance in the success path, decreasing filter_cnt of the still referenced class and allowing it to be deleted, leading to a use-after-free.

This patch set fixes this issue in all affected classifiers by no longer copying the tcf_result struct from the old filter.

v1 -> v2:
- Resubmission and SOB by Jamal

valis (3):
net/sched: cls_u32: No longer copy tcf_result on update to avoid
use-after-free
net/sched: cls_fw: No longer copy tcf_result on update to avoid
use-after-free
net/sched: cls_route: No longer copy tcf_result on update to avoid
use-after-free

 net/sched/cls_fw.c    | 1 -
 net/sched/cls_route.c | 1 -
 net/sched/cls_u32.c   | 1 -
 3 files changed, 3 deletions(-)

--
2.34.1

author maintainer
#1 lore raw

PATCH v2 1/3 net/sched: cls_u32: No longer copy tcf_result on update to avoid use-after-free

From: valis <[email protected]>

When u32_change() is called on an existing filter, the whole tcf_result struct is always copied into the new instance of the filter.

This causes a problem when updating a filter bound to a class, as tcf_unbind_filter() is always called on the old instance in the success path, decreasing filter_cnt of the still referenced class and allowing it to be deleted, leading to a use-after-free.

Fix this by no longer copying the tcf_result struct from the old filter.

Fixes de5df63228fc ("net: sched: cls_u32 changes to knode must appear atomic to readers")
---
 net/sched/cls_u32.c | 1 -
 1 file changed, 1 deletion(-)
net/sched/cls_u32.c +0 -1
index 907e58841fe8..da4c179a4d41 100644
@@ -826,7 +826,6 @@ static struct tc_u_knode *u32_init_knode(struct net *net, struct tcf_proto *tp,
 
 	new->ifindex = n->ifindex;
 	new->fshift = n->fshift;
-	new->res = n->res;
 	new->flags = n->flags;
 	RCU_INIT_POINTER(new->ht_down, ht);
 
Signature · 1 line
2.34.1
author maintainer
#2 lore raw

PATCH v2 2/3 net/sched: cls_fw: No longer copy tcf_result on update to avoid use-after-free

In reply to Jamal Hadi Salim

From: valis <[email protected]>

When fw_change() is called on an existing filter, the whole tcf_result struct is always copied into the new instance of the filter.

This causes a problem when updating a filter bound to a class, as tcf_unbind_filter() is always called on the old instance in the success path, decreasing filter_cnt of the still referenced class and allowing it to be deleted, leading to a use-after-free.

Fix this by no longer copying the tcf_result struct from the old filter.

Fixes e35a8ee5993b ("net: sched: fw use RCU")
---
 net/sched/cls_fw.c | 1 -
 1 file changed, 1 deletion(-)
net/sched/cls_fw.c +0 -1
index 8641f8059317..c49d6af0e048 100644
@@ -267,7 +267,6 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,
 			return -ENOBUFS;
 
 		fnew->id = f->id;
-		fnew->res = f->res;
 		fnew->ifindex = f->ifindex;
 		fnew->tp = f->tp;
 
Signature · 1 line
2.34.1
author maintainer
#3 lore raw

PATCH v2 3/3 net/sched: cls_route: No longer copy tcf_result on update to avoid use-after-free

In reply to Jamal Hadi Salim

From: valis <[email protected]>

When route4_change() is called on an existing filter, the whole tcf_result struct is always copied into the new instance of the filter.

This causes a problem when updating a filter bound to a class, as tcf_unbind_filter() is always called on the old instance in the success path, decreasing filter_cnt of the still referenced class and allowing it to be deleted, leading to a use-after-free.

Fix this by no longer copying the tcf_result struct from the old filter.

Fixes 1109c00547fc ("net: sched: RCU cls_route")
---
 net/sched/cls_route.c | 1 -
 1 file changed, 1 deletion(-)
net/sched/cls_route.c +0 -1
index d0c53724d3e8..1e20bbd687f1 100644
@@ -513,7 +513,6 @@ static int route4_change(struct net *net, struct sk_buff *in_skb,
 	if (fold) {
 		f->id = fold->id;
 		f->iif = fold->iif;
-		f->res = fold->res;
 		f->handle = fold->handle;
 
 		f->tp = fold->tp;
Signature · 1 line
2.34.1
Reviewed-by on the v2 series
#4 lore raw
In reply to Jamal Hadi Salim
Quoted 24 lines · Jamal Hadi Salim

From: valis <[email protected]>

Three classifiers (cls_fw, cls_u32 and cls_route) always copy tcf_result struct into the new instance of the filter on update.

This causes a problem when updating a filter bound to a class, as tcf_unbind_filter() is always called on the old instance in the success path, decreasing filter_cnt of the still referenced class and allowing it to be deleted, leading to a use-after-free.

This patch set fixes this issue in all affected classifiers by no longer copying the tcf_result struct from the old filter.

v1 -> v2:
- Resubmission and SOB by Jamal

valis (3):
net/sched: cls_u32: No longer copy tcf_result on update to avoid
use-after-free
net/sched: cls_fw: No longer copy tcf_result on update to avoid
use-after-free
net/sched: cls_route: No longer copy tcf_result on update to avoid
use-after-free

Quoted 4 lines
  net/sched/cls_fw.c    | 1 -
  net/sched/cls_route.c | 1 -
  net/sched/cls_u32.c   | 1 -
  3 files changed, 3 deletions(-)

For the series,

Reviewed-by Tested-by on the v2 series
#5 lore raw
In reply to Jamal Hadi Salim
Quoted 24 lines · Jamal Hadi Salim

From: valis <[email protected]>

Three classifiers (cls_fw, cls_u32 and cls_route) always copy tcf_result struct into the new instance of the filter on update.

This causes a problem when updating a filter bound to a class, as tcf_unbind_filter() is always called on the old instance in the success path, decreasing filter_cnt of the still referenced class and allowing it to be deleted, leading to a use-after-free.

This patch set fixes this issue in all affected classifiers by no longer copying the tcf_result struct from the old filter.

v1 -> v2:
- Resubmission and SOB by Jamal

valis (3):
net/sched: cls_u32: No longer copy tcf_result on update to avoid
use-after-free
net/sched: cls_fw: No longer copy tcf_result on update to avoid
use-after-free
net/sched: cls_route: No longer copy tcf_result on update to avoid
use-after-free

Quoted 7 lines
  net/sched/cls_fw.c    | 1 -
  net/sched/cls_route.c | 1 -
  net/sched/cls_u32.c   | 1 -
  3 files changed, 3 deletions(-)

--
2.34.1

For the series,

Tested-by Reviewed-by on the v2 series
#6 lore raw
In reply to Jamal Hadi Salim
Quoted 25 lines · Jamal Hadi Salim

From: valis <[email protected]>

Three classifiers (cls_fw, cls_u32 and cls_route) always copy tcf_result struct into the new instance of the filter on update.

This causes a problem when updating a filter bound to a class, as tcf_unbind_filter() is always called on the old instance in the success path, decreasing filter_cnt of the still referenced class and allowing it to be deleted, leading to a use-after-free.

This patch set fixes this issue in all affected classifiers by no longer copying the tcf_result struct from the old filter.

v1 -> v2:
- Resubmission and SOB by Jamal

valis (3):
net/sched: cls_u32: No longer copy tcf_result on update to avoid
use-after-free
net/sched: cls_fw: No longer copy tcf_result on update to avoid
use-after-free
net/sched: cls_route: No longer copy tcf_result on update to avoid
use-after-free

Quoted 5 lines
 net/sched/cls_fw.c    | 1 -
 net/sched/cls_route.c | 1 -
 net/sched/cls_u32.c   | 1 -
 3 files changed, 3 deletions(-)

For the series,

Quoted 2 lines

--
2.34.1

#7 lore raw
In reply to Jamal Hadi Salim
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

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

Quoted 11 lines · On Sat, 29 Jul 2023 08:31:59 -0400 you wrote:

From: valis <[email protected]>

Three classifiers (cls_fw, cls_u32 and cls_route) always copy tcf_result struct into the new instance of the filter on update.

This causes a problem when updating a filter bound to a class, as tcf_unbind_filter() is always called on the old instance in the success path, decreasing filter_cnt of the still referenced class and allowing it to be deleted, leading to a use-after-free.

[...]

Here is the summary with links:
- [net,v2,1/3] net/sched: cls_u32: No longer copy tcf_result on update to avoid use-after-free

    https://git.kernel.org/netdev/net/c/3044b16e7c6f
  - [net,v2,2/3] net/sched: cls_fw: No longer copy tcf_result on update to avoid use-after-free
    https://git.kernel.org/netdev/net/c/76e42ae83199
  - [net,v2,3/3] net/sched: cls_route: No longer copy tcf_result on update to avoid use-after-free
    https://git.kernel.org/netdev/net/c/b80b829e9e2c

You are awesome, thank you!

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