Skip to content

Commit ef299cc

Browse files
congwangdavem330
authored andcommitted
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. Reported-and-tested-by: [email protected] Reported-and-tested-by: [email protected] Reported-and-tested-by: [email protected] Fixes: 1109c00 ("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]> Signed-off-by: David S. Miller <[email protected]>
1 parent 4ae649e commit ef299cc

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

net/sched/cls_route.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,8 @@ static int route4_change(struct net *net, struct sk_buff *in_skb,
534534
fp = &b->ht[h];
535535
for (pfp = rtnl_dereference(*fp); pfp;
536536
fp = &pfp->next, pfp = rtnl_dereference(*fp)) {
537-
if (pfp == f) {
538-
*fp = f->next;
537+
if (pfp == fold) {
538+
rcu_assign_pointer(*fp, fold->next);
539539
break;
540540
}
541541
}

0 commit comments

Comments
 (0)