Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp6768487rwn; Tue, 13 Sep 2022 08:46:38 -0700 (PDT) X-Google-Smtp-Source: AA6agR4kv/dZb44VPTOB66xL9xzn8YsGpnUvqDnaa4fS5mFGptG1NAuwDIbM5DxzNi48rSCYu1Au X-Received: by 2002:a05:6402:27cf:b0:451:6ccc:4ea0 with SMTP id c15-20020a05640227cf00b004516ccc4ea0mr12312657ede.193.1663083998436; Tue, 13 Sep 2022 08:46:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663083998; cv=none; d=google.com; s=arc-20160816; b=XeokvK6aO9leq6ErQNsVOc7XAYI0zr2TaGIrLL74PzhH6bcXtDqUt5sVH5logSWzjd oxM0CvLgvyImQSHSZ1eHygjTgflPG4mzGQKqzJiIKWkr8iibZzCh9elYJbn7z1ig3NoZ Bym0usAB5qYJIkbvE/Q9pMqcNzD+0p0Aa7WpIWEfR+C4Tykw/ZoqonqQqXDBZWSlRb4e Np7/fCT9gO8CEYCkgAiWYWZJ2QDvXYlMVDr8ievwv3CKrKN+GLv5esQHCgDjWEP7Dgt+ eBEsBiwueT2JrmSFyKu498U5VmxLSMWEk/mBMxdgvSgmLlZDIPJm9Goe5Y0sKXbsbOMh wEKA== 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=jX6zmjVHB2rBAVWfWwAA+O8ydygbM/IHsr+4Jj+L/iU=; b=ZZXPnT2zvVsMR0tCS1ZQ3GivuVN6/q2L2i6OhRQOQrqyINnWrZo/d5AwkDapfoHSyT 8Gb6UUuY7S9Miwm+3Owsk8UF4Bs7f9Kk4WFFXnc4EcBr+1AWTiu52h1hwmzUGk6t7eKA ckifogMqWZgWmZdCFUWE+uPZ3QkyQjqllaWEXpenzLfcGONjEdPi/GK3aoWl9iJK5AI9 ak9o9Roi1Pg9rjOS//I13/eAKOMEhmjYquvvrPWe7hkRTZyfbMdPhqOhwdlJeqxZmEt8 qqUZQFWMs+XDPILpF6w3d1SJ4BDrxRHuUF2Ch5NrQ9LtA2k5G+l9lBpfgqWkxWwNDBg5 kNyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=isfCVlHH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e2-20020a170906314200b0073101ba70bdsi7830751eje.927.2022.09.13.08.46.10; Tue, 13 Sep 2022 08:46:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=isfCVlHH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S235974AbiIMPUa (ORCPT + 99 others); Tue, 13 Sep 2022 11:20:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235952AbiIMPSi (ORCPT ); Tue, 13 Sep 2022 11:18:38 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0759F79A4F; Tue, 13 Sep 2022 07:35:26 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id DEDD1B80EFA; Tue, 13 Sep 2022 14:33:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C34CC433C1; Tue, 13 Sep 2022 14:33:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663079603; bh=eHBm7y0fVUA8Gl2U1lMAhWBmoOpB3KW/PvPqGbc644w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=isfCVlHHCLptsnpQn6+G2ZvWF6dzHViE9Vkn21hauyCRSVX34HgoMpOodPWlfo1Al 1fd6Zq6y7XgfmalUTx/YM/h0MySisbShUss7zOVwYiHKJwdBT6v5Fch7EVZSp+qOQ/ OmQeoicTIXH2Cj4QTaVfZ0jJ9G+ShWhkBroCQHUQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Harsh Modi , Florian Westphal , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 4.19 64/79] netfilter: br_netfilter: Drop dst references before setting. Date: Tue, 13 Sep 2022 16:07:22 +0200 Message-Id: <20220913140351.979662545@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140348.835121645@linuxfoundation.org> References: <20220913140348.835121645@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Harsh Modi [ Upstream commit d047283a7034140ea5da759a494fd2274affdd46 ] The IPv6 path already drops dst in the daddr changed case, but the IPv4 path does not. This change makes the two code paths consistent. Further, it is possible that there is already a metadata_dst allocated from ingress that might already be attached to skbuff->dst while following the bridge path. If it is not released before setting a new metadata_dst, it will be leaked. This is similar to what is done in bpf_set_tunnel_key() or ip6_route_input(). It is important to note that the memory being leaked is not the dst being set in the bridge code, but rather memory allocated from some other code path that is not being freed correctly before the skb dst is overwritten. An example of the leakage fixed by this commit found using kmemleak: unreferenced object 0xffff888010112b00 (size 256): comm "softirq", pid 0, jiffies 4294762496 (age 32.012s) hex dump (first 32 bytes): 00 00 00 00 00 00 00 00 80 16 f1 83 ff ff ff ff ................ e1 4e f6 82 ff ff ff ff 00 00 00 00 00 00 00 00 .N.............. backtrace: [<00000000d79567ea>] metadata_dst_alloc+0x1b/0xe0 [<00000000be113e13>] udp_tun_rx_dst+0x174/0x1f0 [<00000000a36848f4>] geneve_udp_encap_recv+0x350/0x7b0 [<00000000d4afb476>] udp_queue_rcv_one_skb+0x380/0x560 [<00000000ac064aea>] udp_unicast_rcv_skb+0x75/0x90 [<000000009a8ee8c5>] ip_protocol_deliver_rcu+0xd8/0x230 [<00000000ef4980bb>] ip_local_deliver_finish+0x7a/0xa0 [<00000000d7533c8c>] __netif_receive_skb_one_core+0x89/0xa0 [<00000000a879497d>] process_backlog+0x93/0x190 [<00000000e41ade9f>] __napi_poll+0x28/0x170 [<00000000b4c0906b>] net_rx_action+0x14f/0x2a0 [<00000000b20dd5d4>] __do_softirq+0xf4/0x305 [<000000003a7d7e15>] __irq_exit_rcu+0xc3/0x140 [<00000000968d39a2>] sysvec_apic_timer_interrupt+0x9e/0xc0 [<000000009e920794>] asm_sysvec_apic_timer_interrupt+0x16/0x20 [<000000008942add0>] native_safe_halt+0x13/0x20 Florian Westphal says: "Original code was likely fine because nothing ever did set a skb->dst entry earlier than bridge in those days." Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Harsh Modi Acked-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/bridge/br_netfilter_hooks.c | 2 ++ net/bridge/br_netfilter_ipv6.c | 1 + 2 files changed, 3 insertions(+) diff --git a/net/bridge/br_netfilter_hooks.c b/net/bridge/br_netfilter_hooks.c index 55c7cdf5e7b83..35642dc96852a 100644 --- a/net/bridge/br_netfilter_hooks.c +++ b/net/bridge/br_netfilter_hooks.c @@ -385,6 +385,7 @@ static int br_nf_pre_routing_finish(struct net *net, struct sock *sk, struct sk_ /* - Bridged-and-DNAT'ed traffic doesn't * require ip_forwarding. */ if (rt->dst.dev == dev) { + skb_dst_drop(skb); skb_dst_set(skb, &rt->dst); goto bridged_dnat; } @@ -414,6 +415,7 @@ static int br_nf_pre_routing_finish(struct net *net, struct sock *sk, struct sk_ kfree_skb(skb); return 0; } + skb_dst_drop(skb); skb_dst_set_noref(skb, &rt->dst); } diff --git a/net/bridge/br_netfilter_ipv6.c b/net/bridge/br_netfilter_ipv6.c index 09d5e0c7b3ba4..995d86777e7cb 100644 --- a/net/bridge/br_netfilter_ipv6.c +++ b/net/bridge/br_netfilter_ipv6.c @@ -201,6 +201,7 @@ static int br_nf_pre_routing_finish_ipv6(struct net *net, struct sock *sk, struc kfree_skb(skb); return 0; } + skb_dst_drop(skb); skb_dst_set_noref(skb, &rt->dst); } -- 2.35.1