All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [Patch net] net_sched: cls_route: remove the right filter from hashtable
@ 2020-03-14  5:29 Cong Wang
  2020-03-16  9:01 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Cong Wang @ 2020-03-14  5:29 UTC (permalink / raw
  To: netdev
  Cc: Cong Wang, syzbot+f9b32aaacd60305d9687,
	syzbot+2f8c233f131943d6056d, syzbot+9c2df9fd5e9445b74e01,
	Jamal Hadi Salim, Jiri Pirko, John Fastabend

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: syzbot+f9b32aaacd60305d9687@syzkaller.appspotmail.com
Reported-and-tested-by: syzbot+2f8c233f131943d6056d@syzkaller.appspotmail.com
Reported-and-tested-by: syzbot+9c2df9fd5e9445b74e01@syzkaller.appspotmail.com
Fixes: 1109c00547fc ("net: sched: RCU cls_route")
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: Jiri Pirko <jiri@resnulli.us>
Cc: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
---
 net/sched/cls_route.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/sched/cls_route.c b/net/sched/cls_route.c
index 6f8786b06bde..5efa3e7ace15 100644
--- a/net/sched/cls_route.c
+++ b/net/sched/cls_route.c
@@ -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;
 				}
 			}
-- 
2.21.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Patch net] net_sched: cls_route: remove the right filter from hashtable
  2020-03-14  5:29 [Patch net] net_sched: cls_route: remove the right filter from hashtable Cong Wang
@ 2020-03-16  9:01 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2020-03-16  9:01 UTC (permalink / raw
  To: xiyou.wangcong
  Cc: netdev, syzbot+f9b32aaacd60305d9687, syzbot+2f8c233f131943d6056d,
	syzbot+9c2df9fd5e9445b74e01, jhs, jiri, john.fastabend

From: Cong Wang <xiyou.wangcong@gmail.com>
Date: Fri, 13 Mar 2020 22:29:54 -0700

> 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: syzbot+f9b32aaacd60305d9687@syzkaller.appspotmail.com
> Reported-and-tested-by: syzbot+2f8c233f131943d6056d@syzkaller.appspotmail.com
> Reported-and-tested-by: syzbot+9c2df9fd5e9445b74e01@syzkaller.appspotmail.com
> Fixes: 1109c00547fc ("net: sched: RCU cls_route")
> Cc: Jamal Hadi Salim <jhs@mojatatu.com>
> Cc: Jiri Pirko <jiri@resnulli.us>
> Cc: John Fastabend <john.fastabend@gmail.com>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>

Applied and queued up for -stable, thanks Cong.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-03-16  9:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-14  5:29 [Patch net] net_sched: cls_route: remove the right filter from hashtable Cong Wang
2020-03-16  9:01 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.