Skip to content

Commit 5d89917

Browse files
Florian Westphalgregkh
authored andcommitted
xfrm: skip policies marked as dead while rehashing
commit 862591b upstream. syzkaller triggered following KASAN splat: BUG: KASAN: slab-out-of-bounds in xfrm_hash_rebuild+0xdbe/0xf00 net/xfrm/xfrm_policy.c:618 read of size 2 at addr ffff8801c8e92fe4 by task kworker/1:1/23 [..] Workqueue: events xfrm_hash_rebuild [..] __asan_report_load2_noabort+0x14/0x20 mm/kasan/report.c:428 xfrm_hash_rebuild+0xdbe/0xf00 net/xfrm/xfrm_policy.c:618 process_one_work+0xbbf/0x1b10 kernel/workqueue.c:2112 worker_thread+0x223/0x1990 kernel/workqueue.c:2246 [..] The reproducer triggers: 1016 if (error) { 1017 list_move_tail(&walk->walk.all, &x->all); 1018 goto out; 1019 } in xfrm_policy_walk() via pfkey (it sets tiny rcv space, dump callback returns -ENOBUFS). In this case, *walk is located the pfkey socket struct, so this socket becomes visible in the global policy list. It looks like this is intentional -- phony walker has walk.dead set to 1 and all other places skip such "policies". Ccing original authors of the two commits that seem to expose this issue (first patch missed ->dead check, second patch adds pfkey sockets to policies dumper list). Fixes: 880a6fa ("xfrm: configure policy hash table thresholds by netlink") Fixes: 12a169e ("ipsec: Put dumpers on the dump list") Cc: Herbert Xu <herbert@gondor.apana.org.au> Cc: Timo Teras <timo.teras@iki.fi> Cc: Christophe Gouault <christophe.gouault@6wind.com> Reported-by: syzbot <bot+c028095236fcb6f4348811565b75084c754dc729@syzkaller.appspotmail.com> Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7589803 commit 5d89917

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

net/xfrm/xfrm_policy.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,8 @@ static void xfrm_hash_rebuild(struct work_struct *work)
643643

644644
/* re-insert all policies by order of creation */
645645
list_for_each_entry_reverse(policy, &net->xfrm.policy_all, walk.all) {
646-
if (xfrm_policy_id2dir(policy->index) >= XFRM_POLICY_MAX) {
646+
if (policy->walk.dead ||
647+
xfrm_policy_id2dir(policy->index) >= XFRM_POLICY_MAX) {
647648
/* skip socket policies */
648649
continue;
649650
}

0 commit comments

Comments
 (0)