Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2353234pxb; Mon, 20 Sep 2021 19:51:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzH5GhVu/1G0zNck3cGnFGoppoMHfky8Mtw5RAyomlqydz8ZTyu196oAue61K9Qt7u3uja X-Received: by 2002:a17:906:3b56:: with SMTP id h22mr31757491ejf.141.1632192671650; Mon, 20 Sep 2021 19:51:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632192671; cv=none; d=google.com; s=arc-20160816; b=CVI0R94rWdBxndn+PWP5pDdSwVPa2F4JMdZX/gfZHw1RwlQjDHAhXC6heqDWwK3PqG YrQnP/2TTovOzi9e/GkAVC4yDg2cMCcb2fw4hadlw5gJ2jVpa4i286+rJFoCZ9XFQYoL UCE0B78jr5dQD0iCp3mJCcE6u7TRq555WqKN0qO+jq5YcMSce8qmtUVPQeoWfgtNKlfe I3QWpY4jjj6G08xo3jkd138G7t3/tg3KaXtcPAGCROoG7cX/o9FNW85auvzrxpi6mv7L awhH2C+Edsj9IfUpzJlfLZDnmPXmwQKgnu52zLUiF4vLX7UL0rmJ0aNcv0q9X0CzxsOX N5FA== 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=h3w9gS4Z2UDHFDuEcKtTpdURYxpHi3pxWozBRdfUVps66igH6sTk9fQuw7gFudcH/p E2AANTlHpe0ZBlFS7+wNzydxGzs0clzBly0dlDzw4yWF78RzISoOkLGE0XAqSSAe4MBY rT8v8gkt7av2FZOz17tL1WC50O5k2Y7ME+z+QoYB5LOQlswMGGYDdIoB956mcVM4zLn7 HB71rc/t0zRq8BRtHh0VjBuJyybKBxAtMzaK5lzLVMtwGhGnZx8dBrG/CcV4bBnt17Wa rkCzI5Uq6gJf6c+PNfaCA/VcmplRM5x1dGJutfGZPgcCSme5dFMjBiV5DzduAjSIMAts xVZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XMNALItH; 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 v25si20352782edl.596.2021.09.20.19.50.48; Mon, 20 Sep 2021 19:51:11 -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=XMNALItH; 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 S1381487AbhITSiX (ORCPT + 99 others); Mon, 20 Sep 2021 14:38:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:52526 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380334AbhITSda (ORCPT ); Mon, 20 Sep 2021 14:33:30 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5050A63303; Mon, 20 Sep 2021 17:28:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158898; bh=n8+TiQ4yNKT8/fz9Ul5M3sOI9kFv2BGLFwuALFg8MVU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XMNALItHOpAz39aeFTGrPv2ZFG0QTB/gBMwbWIboXnbtYG53OISfvfhMCJdhWk78y xR3/GH//Yku9614cgYHu+4yX8nIbdHDhXb72z8FfPaJ+2kn6wpOMpw1IDGEmwLaNBe +eWwH2Xerd9vrdPwRBP2XeWe4J+KAToivXWzlsqw= 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.10 107/122] netfilter: socket: icmp6: fix use-after-scope Date: Mon, 20 Sep 2021 18:44:39 +0200 Message-Id: <20210920163919.314979559@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163915.757887582@linuxfoundation.org> References: <20210920163915.757887582@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