Received: by 10.223.185.116 with SMTP id b49csp1105546wrg; Fri, 23 Feb 2018 12:02:24 -0800 (PST) X-Google-Smtp-Source: AH8x225JjHnnZzOOaOzN5fsPSNCgMceb5JSXbC4bUbepCNW0tt16TGiJyTYoV/DnsRLUIwn0/vP7 X-Received: by 2002:a17:902:ab8f:: with SMTP id f15-v6mr2756618plr.214.1519416144179; Fri, 23 Feb 2018 12:02:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519416144; cv=none; d=google.com; s=arc-20160816; b=pMZmHEbWqQ3xYR6QeM6DauRSp2WeKGWpphaPwS5LQzZ+3tsb2STTMFCtg57V/PoJ2t mN+UHckzaMT4SFSSKATRTa3CKl7lu5cbYeW/ZQAtsKIzNL7GpAaRhGT1wLbKzCSdijsf 1MtjGMTvMIloEo7eZ+liesYpBEJjsFgD0HZh+4IvplQ5m1idgK6SHjl11XB2ezF0qZzh zRymK3X1a46AXeyxMWoaXI4YuJES+hlNxtE0CtZ8cRImnyxtwADtu/JmyQuTvTsti3N7 Kh6aZBDXbhLb5L+G2lPyjfifNOZtSXOS8q7FCRfe0XFyjtQiKQJBQ4c+o1DBqRFeCR74 sFuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=ZXP8zZ+hYLYJZ5fDVm2Q81HGIMdvoL+KINTMZMVHDmM=; b=fLALLVlfChJgOvCZqMsNx9B7/qhvRBEC6AGEcXICJEPjDlGJccWMtaggn9xwWewYbE GCF2GF/gAM2JDHt4tPT36IOwIWFu2C8BUNgRyliy7NE8fHhqfyDGArYZteQ2UqiQjdmn i0rwmoOD3RHOC9OUtejqjSBbk8hRUp3LkfA116exL1C8me5k5Xi7GXdM2H2qTMF2Yzit m5SzL09DmdXDtZpFy8N2jkVNmzwDBtmOtPm1oInU62GUEJCsVUjF3JBXVNY8rFjXb5g3 QJYhdnuiwylgRfxNPhxfQD+FZ+DfV4Gx7v6+xiVd0zJuhtWJhV6gea9FU9TDIBsrmy9e 2H3g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e4-v6si2218268pln.655.2018.02.23.12.02.09; Fri, 23 Feb 2018 12:02:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933319AbeBWSnc (ORCPT + 99 others); Fri, 23 Feb 2018 13:43:32 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:42230 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932961AbeBWSn2 (ORCPT ); Fri, 23 Feb 2018 13:43:28 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id C981510BE; Fri, 23 Feb 2018 18:43:27 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Herbert Xu , Timo Teras , Christophe Gouault , syzbot , Florian Westphal , Steffen Klassert Subject: [PATCH 4.9 005/145] xfrm: skip policies marked as dead while rehashing Date: Fri, 23 Feb 2018 19:25:11 +0100 Message-Id: <20180223170725.421935424@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170724.669759283@linuxfoundation.org> References: <20180223170724.669759283@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Florian Westphal commit 862591bf4f519d1b8d859af720fafeaebdd0162a 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: 880a6fab8f6ba5b ("xfrm: configure policy hash table thresholds by netlink") Fixes: 12a169e7d8f4b1c ("ipsec: Put dumpers on the dump list") Cc: Herbert Xu Cc: Timo Teras Cc: Christophe Gouault Reported-by: syzbot Signed-off-by: Florian Westphal Signed-off-by: Steffen Klassert Signed-off-by: Greg Kroah-Hartman --- net/xfrm/xfrm_policy.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/net/xfrm/xfrm_policy.c +++ b/net/xfrm/xfrm_policy.c @@ -643,7 +643,8 @@ static void xfrm_hash_rebuild(struct wor /* re-insert all policies by order of creation */ list_for_each_entry_reverse(policy, &net->xfrm.policy_all, walk.all) { - if (xfrm_policy_id2dir(policy->index) >= XFRM_POLICY_MAX) { + if (policy->walk.dead || + xfrm_policy_id2dir(policy->index) >= XFRM_POLICY_MAX) { /* skip socket policies */ continue; }