]> git.baikalelectronics.ru Git - kernel.git/commit
net_sched: commit action insertions together
authorCong Wang <xiyou.wangcong@gmail.com>
Wed, 23 Sep 2020 03:56:24 +0000 (20:56 -0700)
committerDavid S. Miller <davem@davemloft.net>
Fri, 25 Sep 2020 02:46:21 +0000 (19:46 -0700)
commitfc793508d458f9ca5ebc1dc9add77dddf15119c0
treed8163a3a4d54a906afe9e176ec6b877212f291b9
parent60652792126acea0a5b81953bb07683ebcd61428
net_sched: commit action insertions together

syzbot is able to trigger a failure case inside the loop in
tcf_action_init(), and when this happens we clean up with
tcf_action_destroy(). But, as these actions are already inserted
into the global IDR, other parallel process could free them
before tcf_action_destroy(), then we will trigger a use-after-free.

Fix this by deferring the insertions even later, after the loop,
and committing all the insertions in a separate loop, so we will
never fail in the middle of the insertions any more.

One side effect is that the window between alloction and final
insertion becomes larger, now it is more likely that the loop in
tcf_del_walker() sees the placeholder -EBUSY pointer. So we have
to check for error pointer in tcf_del_walker().

Reported-and-tested-by: syzbot+2287853d392e4b42374a@syzkaller.appspotmail.com
Fixes: e8163a9d8626 ("net: sched: atomically check-allocate action")
Cc: Vlad Buslov <vladbu@mellanox.com>
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: Jiri Pirko <jiri@resnulli.us>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/sched/act_api.c