net_sched: hold rtnl lock in tcindex_partial_destroy_work()
Subsystems (3)
PATCH 1/1 net_sched: hold rtnl lock in tcindex_partial_destroy_work()
syzbot reported a use-after-free in tcindex_dump(). This is due to the lack of RTNL in the deferred rcu work. We queue this work with RTNL in tcindex_change(), later, tcindex_dump() is called:
fh = tp->ops->get(tp, t->tcm_handle);
...
err = tp->ops->change(..., &fh, ...);
tfilter_notify(..., fh, ...);but there is nothing to serialize the pending tcindex_partial_destroy_work() with tcindex_dump().
Fix this by simply holding RTNL in tcindex_partial_destroy_work(), so that it won't be called until RTNL is released after tc_new_tfilter() is completed.
--- net/sched/cls_tcindex.c | 2 ++ 1 file changed, 2 insertions(+)
net/sched/cls_tcindex.c +2 -0
@@ -261,8 +261,10 @@ static void tcindex_partial_destroy_work(struct work_struct *work) struct tcindex_data, rwork); +rtnl_lock ();kfree (p->perfect);kfree (p); +rtnl_unlock (); }static void tcindex_free_perfect_hash (struct tcindex_data *cp)
Signature · 1 line
2.21.1
PATCH 1/1 net_sched: keep alloc_hash updated after hash allocation
In commit 599be01ee567 ("net_sched: fix an OOB access in cls_tcindex") I moved cp->hash calculation before the first tcindex_alloc_perfect_hash(), but cp->alloc_hash is left untouched. This difference could lead to another out of bound access.
cp->alloc_hash should always be the size allocated, we should update it after this tcindex_alloc_perfect_hash().
--- net/sched/cls_tcindex.c | 1 + 1 file changed, 1 insertion(+)
net/sched/cls_tcindex.c +1 -0
@@ -359,6 +359,7 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base,if (tcindex_alloc_perfect_hash (net, cp) <0 ) goto errout; + cp->alloc_hash = cp->hash;for (i =0 ; i <min (cp->hash, p->hash); i++) cp->perfect[i].res = p->perfect[i].res; balloc =1 ;
Signature · 1 line
2.21.1
David Miller
maintainerRe: [Patch net] net_sched: keep alloc_hash updated after hash allocation
From: Cong Wang <[email protected]>
Date: Wed, 11 Mar 2020 22:42:28 -0700
Quoted 8 lines
In commit
599be01ee567("net_sched: fix an OOB access incls_tcindex") I movedcp->hashcalculation before the firsttcindex_alloc_perfect_hash(), butcp->alloc_hashis left untouched. This difference could lead to another out of bound access.
cp->alloc_hashshould always be the size allocated, we should update it after thistcindex_alloc_perfect_hash().
Quoted 6 lines
Reported-and-tested-by [email protected]Reported-and-tested-by [email protected]Fixes 599be01ee567 ("net_sched: fix an OOB access in cls_tcindex")Cc Jamal Hadi Salim <[email protected]>Cc Jiri Pirko <[email protected]>Signed-off-by Cong Wang <[email protected]>
Also applied and queued up for -stable, thanks.
David Miller
maintainerFrom: Cong Wang <[email protected]>
Date: Wed, 11 Mar 2020 22:42:27 -0700
Quoted 16 lines
syzbot reported a use-after-free in
tcindex_dump(). This is due to the lack of RTNL in the deferred rcu work. We queue this work with RTNL intcindex_change(), later,tcindex_dump()is called:fh = tp->ops->get(tp, t->tcm_handle); ... err = tp->ops->change(..., &fh, ...); tfilter_notify(..., fh, ...);but there is nothing to serialize the pending
tcindex_partial_destroy_work()withtcindex_dump().Fix this by simply holding RTNL in
tcindex_partial_destroy_work(), so that it won't be called until RTNL is released aftertc_new_tfilter()is completed.
Quoted 5 lines
Reported-and-tested-by [email protected]Fixes 3d210534cc93 ("net_sched: fix a race condition in tcindex_destroy()")Cc Jamal Hadi Salim <[email protected]>Cc Jiri Pirko <[email protected]>Signed-off-by Cong Wang <[email protected]>
Applied and queued up for -stable, thanks Cong.