From: Florian Westphal Date: Sat, 6 Jan 2018 00:13:08 +0000 (+0100) Subject: xfrm: don't call xfrm_policy_cache_flush while holding spinlock X-Git-Tag: v4.14.22~151 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=85c31887a20da06fe2803b4ec1031b9af89c1899;p=platform%2Fkernel%2Flinux-rpi.git xfrm: don't call xfrm_policy_cache_flush while holding spinlock commit b1bdcb59b64f806ef08d25a85c39ffb3ad841ce6 upstream. xfrm_policy_cache_flush can sleep, so it cannot be called while holding a spinlock. We could release the lock first, but I don't see why we need to invoke this function here in first place, the packet path won't reuse an xdst entry unless its still valid. While at it, add an annotation to xfrm_policy_cache_flush, it would have probably caught this bug sooner. Fixes: ec30d78c14a813 ("xfrm: add xdst pcpu cache") Reported-by: syzbot+e149f7d1328c26f9c12f@syzkaller.appspotmail.com Signed-off-by: Florian Westphal Signed-off-by: Steffen Klassert Signed-off-by: Greg Kroah-Hartman --- diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c index 688ed34..27b9140 100644 --- a/net/xfrm/xfrm_policy.c +++ b/net/xfrm/xfrm_policy.c @@ -975,8 +975,6 @@ int xfrm_policy_flush(struct net *net, u8 type, bool task_valid) } if (!cnt) err = -ESRCH; - else - xfrm_policy_cache_flush(); out: spin_unlock_bh(&net->xfrm.xfrm_policy_lock); return err; @@ -1738,6 +1736,8 @@ void xfrm_policy_cache_flush(void) bool found = 0; int cpu; + might_sleep(); + local_bh_disable(); rcu_read_lock(); for_each_possible_cpu(cpu) {