Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp2968412imm; Sun, 1 Jul 2018 09:21:49 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdPJOTIOaJeg8mTn7HM0YzOZnE1dux8Xs6QS70smgH+/pSKt/oHutNFOhczYpVActN1l6Wf X-Received: by 2002:a62:4255:: with SMTP id p82-v6mr22297854pfa.227.1530462109565; Sun, 01 Jul 2018 09:21:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530462109; cv=none; d=google.com; s=arc-20160816; b=yMgnovX1EwduE6KCJP6Z/8RJD4m1Vixj9bh+H5jwiaXLs6WvpV9UkN3L6FKr4mjztT HQPAFXcpeEEq9mwNdOP+pXA6DO/Bcd2UTOGPdeAKT/hKpD+bVwc4jKQTFa3Nv0gk82LA /g/NC8YfroyjzPGw32E44j8DH9sGuHQZ5cGLt6NBQ2zERj/TRwivr5qcaYqvVrhBaWU/ qL7R/zm8bH1BpXdgydNdbcO0J/+nxLjOExu03flEUhfn8JAdBkA6UtIq+AWuman9wVUV TAFHo//yGibhvtej6Sm+bkXCj37fYAQcnKacJoPhmViKWG6gZhAz1dPeTaJr56Exb8VN 64Zg== 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=Jh78UlbjfSNgxB3QDV1rzTriMNo5+AsK8lJA1kHC7s0=; b=Y5zWMDYBX7R9pODycGihBkNXkcqFM9yiK8h96HuN3b9tW5NmhHsg5qaq+bqJZ5l3UD 0Ip/hdm0qi1VTZHg+Oq6plTcNIXtOuTf4ellxphoDKm9mcP5vqxVPbHPp8UwIUrUyBHO SxH62TUjsEjyVATwEJbXhYwc3PpeL/001mNAwJFp+QsZW+1VDoGNLWL+L9pxCVtuwheL MugXkq9JKF8hSNgxl2fSaWV3+istMOgj/gzrkHiQgMoh6mm/5GArvLgm7Mt6zcVe3q+3 2yJPVwesXwM9tMGH/2OIPFwocrsJtnBRyjRLIGpBTTjPUcpo3W2/DMKJw9BE/QSN11dA dn+w== 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 i5-v6si14921662pfe.27.2018.07.01.09.21.35; Sun, 01 Jul 2018 09:21:49 -0700 (PDT) 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 S965028AbeGAQTr (ORCPT + 99 others); Sun, 1 Jul 2018 12:19:47 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:33262 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965012AbeGAQTm (ORCPT ); Sun, 1 Jul 2018 12:19:42 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id E45FB49B; Sun, 1 Jul 2018 16:19:41 +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 , Zubin Mithra Subject: [PATCH 4.4 076/105] xfrm: skip policies marked as dead while rehashing Date: Sun, 1 Jul 2018 18:02:26 +0200 Message-Id: <20180701153154.914240155@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701153149.382300170@linuxfoundation.org> References: <20180701153149.382300170@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.4-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 Cc: Zubin Mithra 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 @@ -626,7 +626,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; }