net_sched: cls_route: remove the right filter from hashtable
Subsystems (3)
PATCH 1/1 net_sched: cls_route: remove the right filter from hashtable
route4_change() allocates a new filter and copies values from the old one. After the new filter is inserted into the hash table, the old filter should be removed and freed, as the final step of the update.
However, the current code mistakenly removes the new one. This looks apparently wrong to me, and it causes double "free" and use-after-free too, as reported by syzbot.
--- net/sched/cls_route.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/sched/cls_route.c +2 -2
@@ -534,8 +534,8 @@ static int route4_change(struct net *net, struct sk_buff *in_skb, fp = &b->ht[h];for (pfp =rtnl_dereference (*fp); pfp; fp = &pfp->next, pfp =rtnl_dereference (*fp)) { -if (pfp == f) { - *fp = f->next; +if (pfp == fold) { +rcu_assign_pointer (*fp, fold->next);break ; } }
Signature · 1 line
2.21.1
David Miller
maintainerFrom: Cong Wang <[email protected]>
Date: Fri, 13 Mar 2020 22:29:54 -0700
Quoted 9 lines
route4_change()allocates a new filter and copies values from the old one. After the new filter is inserted into the hash table, the old filter should be removed and freed, as the final step of the update.However, the current code mistakenly removes the new one. This looks apparently wrong to me, and it causes double "free" and use-after-free too, as reported by syzbot.
Quoted 8 lines
Reported-and-tested-by [email protected]Reported-and-tested-by [email protected]Reported-and-tested-by [email protected]Fixes 1109c00547fc ("net: sched: RCU cls_route")Cc Jamal Hadi Salim <[email protected]>Cc Jiri Pirko <[email protected]>Cc John Fastabend <[email protected]>Signed-off-by Cong Wang <[email protected]>
Applied and queued up for -stable, thanks Cong.