Received: by 10.223.185.116 with SMTP id b49csp1041249wrg; Fri, 23 Feb 2018 10:50:55 -0800 (PST) X-Google-Smtp-Source: AH8x226aHTYAtdt4ojnJVZWW5ACfKBn2RInWjvVHWHg8RR6ngs7D3PB5W7PuYMdj6p9mj/P8sKp8 X-Received: by 2002:a17:902:b28b:: with SMTP id u11-v6mr2573846plr.146.1519411854970; Fri, 23 Feb 2018 10:50:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519411854; cv=none; d=google.com; s=arc-20160816; b=wSadM+FItXxjag5UrbgxLiuQiphSGnO1RWyAcR7Rwf0XdOXUKAxsMgdCvMWQDvfXv5 JT06tY7YzgJSYUQdJD73LCu2VmtymEWmGHEG+N65uedCWy1W9COx2NBTLMo9VottlCF0 593PgxqVmB9rL4aBPO9WsKSRIX6f6dGMgtzzMrVvj/iTH7XsfVAZtwnwlsiPh4PpybuN Rz0rS3yGi4HuSF2M4A1Yk+wmnc1NhvdLfY2ygwI3kNa9eqdQlaXJ9CSwHitLsII6bpJn SJ3cC1h8/2Wd+mfss5AZ2oo7Mo1a4j3yjl8uuEs09+Whba7/VBhgOcxNDE5C9aanXOg/ myyA== 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=lVfKCvwud4g9zUwRMKYXglCYageY0G9tOAMCLtwMFsE=; b=vOuwTuJFNsqHpX5ekmeZBWZsw8tz/GZMKiQAfKigkTESLxMXQcJ1bxVPvEabO4d9D6 Ni+qc2R232NwoLen7N/OSmcFJbmCeZEL2hMAFF1Q5JoSnzSSRkofvCPXnO72SFrybYTJ kBuzyBuHz5A4ODC6bzcPlgTRVmNtfdbYcmaRLJa58ovFedv2ka65IdiliSpABguI7rnA T8j0MnEbM36j3iTuYzy3zE1712y7sT1IHXYj+WxaNI91J/0owGIqptTws5G17kotwqCJ AK+pl3Cs/ZLT5HEXfLZjSLZyYW9bQq7iF0k7FLhXFAkOxTA0Jh6kIX1RQh4/Nw2OgRHI 5CKg== 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 x8-v6si2095839plv.166.2018.02.23.10.50.40; Fri, 23 Feb 2018 10:50:54 -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 S934552AbeBWSta (ORCPT + 99 others); Fri, 23 Feb 2018 13:49:30 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:45288 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934016AbeBWSt0 (ORCPT ); Fri, 23 Feb 2018 13:49:26 -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 C91CB1180; Fri, 23 Feb 2018 18:49:25 +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.14 011/159] xfrm: skip policies marked as dead while rehashing Date: Fri, 23 Feb 2018 19:25:19 +0100 Message-Id: <20180223170744.559775565@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170743.086611315@linuxfoundation.org> References: <20180223170743.086611315@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.14-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 @@ -610,7 +610,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; }