Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2395547pxb; Mon, 20 Sep 2021 21:17:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw63PTTJMPejVThv/kpMd9XLf+cD+ToYkQj182STWMmAS8l5Q39MplqC6kc5heURJo7EqmU X-Received: by 2002:a17:906:4f19:: with SMTP id t25mr25871686eju.440.1632197820809; Mon, 20 Sep 2021 21:17:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632197820; cv=none; d=google.com; s=arc-20160816; b=N0NIjAvOfkO0YV6DwxARtiRXMTfVOjcRGWBeTZC6ZwDdd2v7MGd+gNslWxbSKdSDHc DbV5CxWDCjQCs7JY8/6Xa3E5RR3YndvY8gNp8TGt7eY/Yy6/486Y7SYpHBoCJMD4fVto y74H9MoV0na+DO032oN/Bdt2uI1mSWOvqiWDqIZnUm/qpqht/HJtSL25PU4JYuq11UEF 8C8yUYXd4lMVG6LoThoeWVZBupOvx+cNj4H7KPWCISty2xkGq3dIVvlQSIDUfRmdwZbr a+iqqBnnjK7MVXxl7yQtwnEfmDKSzXKJn8PCEHMF2riF/Sgri+h1Tu870Ey/khClEJ7m o90w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7uXIJs5mRSIbXHEJsjpUJp+dV5wEKdr2ixlAn36TjlY=; b=Z6knJpIvsdYRM0WUl8bsUM4/B7c8PQgCYOLpCIyYTsaNkzu1ozr/f4YXPIPc7VFfT/ zfRKIodhbbYMvpoV4NgVVts91vAx1mSe7NzvOr20ptSG0F4pKr3y05lwF/NSD7kYVs6V elrxm9g+ueYc9UZOL7zv+6kvGC5Gwv+vJGQP2OKYHDfug1QQ1y7cQNZGyvoIcTdoCupO f4qZ6QtDyURA8ia0ZbvLUplRwXGdzfQfqsCuYWff9xIYLNdXS8/L1Atq9GBcIgCz7lta WWwRZFfOCSyalJYsUUkCLeeg9JIZeWxfgQ/aa984BaxsQE/K93KsMSExg0jO1lZkBDfK LeHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EPJBdx15; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hx2si18575369ejc.561.2021.09.20.21.16.32; Mon, 20 Sep 2021 21:17:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EPJBdx15; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355180AbhITS43 (ORCPT + 99 others); Mon, 20 Sep 2021 14:56:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:37162 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1385444AbhITSu0 (ORCPT ); Mon, 20 Sep 2021 14:50:26 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D8ECC63375; Mon, 20 Sep 2021 17:34:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632159272; bh=n8+TiQ4yNKT8/fz9Ul5M3sOI9kFv2BGLFwuALFg8MVU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EPJBdx15H59Mw2ojb5d3aKlmXeY+lgVZ3cY1go8x8oqwB6xiNLkw17R7NV6yj6y/a A4CnMqqo1HYNurZ2jVJHDT5wpX0RRi+3MsPJm62wNPxN+8GvEXiEDNAGd8t1tT2S/Q KVU54RA8Bd1X3htaY7oLSnhwhdS5UmP3OWcQ1Oz0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Matthieu Baerts , Benjamin Hesmans , Florian Westphal , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 5.14 155/168] netfilter: socket: icmp6: fix use-after-scope Date: Mon, 20 Sep 2021 18:44:53 +0200 Message-Id: <20210920163926.763218527@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163921.633181900@linuxfoundation.org> References: <20210920163921.633181900@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Benjamin Hesmans [ Upstream commit 730affed24bffcd1eebd5903171960f5ff9f1f22 ] Bug reported by KASAN: BUG: KASAN: use-after-scope in inet6_ehashfn (net/ipv6/inet6_hashtables.c:40) Call Trace: (...) inet6_ehashfn (net/ipv6/inet6_hashtables.c:40) (...) nf_sk_lookup_slow_v6 (net/ipv6/netfilter/nf_socket_ipv6.c:91 net/ipv6/netfilter/nf_socket_ipv6.c:146) It seems that this bug has already been fixed by Eric Dumazet in the past in: commit 78296c97ca1f ("netfilter: xt_socket: fix a stack corruption bug") But a variant of the same issue has been introduced in commit d64d80a2cde9 ("netfilter: x_tables: don't extract flow keys on early demuxed sks in socket match") `daddr` and `saddr` potentially hold a reference to ipv6_var that is no longer in scope when the call to `nf_socket_get_sock_v6` is made. Fixes: d64d80a2cde9 ("netfilter: x_tables: don't extract flow keys on early demuxed sks in socket match") Acked-by: Matthieu Baerts Signed-off-by: Benjamin Hesmans Reviewed-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/ipv6/netfilter/nf_socket_ipv6.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/net/ipv6/netfilter/nf_socket_ipv6.c b/net/ipv6/netfilter/nf_socket_ipv6.c index 6fd54744cbc3..aa5bb8789ba0 100644 --- a/net/ipv6/netfilter/nf_socket_ipv6.c +++ b/net/ipv6/netfilter/nf_socket_ipv6.c @@ -99,7 +99,7 @@ struct sock *nf_sk_lookup_slow_v6(struct net *net, const struct sk_buff *skb, { __be16 dport, sport; const struct in6_addr *daddr = NULL, *saddr = NULL; - struct ipv6hdr *iph = ipv6_hdr(skb); + struct ipv6hdr *iph = ipv6_hdr(skb), ipv6_var; struct sk_buff *data_skb = NULL; int doff = 0; int thoff = 0, tproto; @@ -129,8 +129,6 @@ struct sock *nf_sk_lookup_slow_v6(struct net *net, const struct sk_buff *skb, thoff + sizeof(*hp); } else if (tproto == IPPROTO_ICMPV6) { - struct ipv6hdr ipv6_var; - if (extract_icmp6_fields(skb, thoff, &tproto, &saddr, &daddr, &sport, &dport, &ipv6_var)) return NULL; -- 2.30.2