Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp6832344rwn; Tue, 13 Sep 2022 09:33:38 -0700 (PDT) X-Google-Smtp-Source: AA6agR7dzYoK0GFcBLyY8AzSPn8JyPQTikGXzdsxWmUjG6nshJ20lLW/+Th/8BjGAuN8uHWiHB6y X-Received: by 2002:a17:902:ef46:b0:168:bac3:2fd4 with SMTP id e6-20020a170902ef4600b00168bac32fd4mr32074607plx.132.1663086818432; Tue, 13 Sep 2022 09:33:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663086818; cv=none; d=google.com; s=arc-20160816; b=kMOynM0oHc7Miru5iR8wqYNtHwKdQTIniLljrdk3Za+8P5if2UGHYbToaP4EYz3eYU iJGDmcBkdJIrdpJJ0R4LtrG3Cwp2pkB8TCG6xtiP/GZwWg5dqA6G3s9XjMifOFwFry8v 0nxEjFDY6PUXLkY+fDcvjXVGVb4M0S25HxpuqhQ5HpZUcODTzhQvhXf9cwoArlVJv3OR Z8Hw6M28zkeFbD3gOmff+MJsWUJ0UdRgm6ECGl871vd7iYHO5YhfwvoaY21xNHZHl/po WLrDiuqUBJ+ZjZ2U0hC7asAuaC8dkKJPNICOWcNrtiEQdQINkltpMkEo43YoM+hk+Y4j LKvg== 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=RCjiCKPyGDs4KekmvSpXaYwb+GTH9gsefntAhNUynKM=; b=hIyFtPXrlZjJR7wKKJ8cxkhkGtSQjnaoJzDDxefheJc/GNsBtuM94X/nprKp2jj1n7 uKrlFfqaYzISMRlwpRIi4oxTPPTS4svQQ1NfKhdjvd9oludhZ5IOcJWjnnTBWGJTASwG bk8yjc+UqSupfLvuRUp8a/LA4FFJsuV9sTse9qD2mWpZjPhmsI1TAdxyXEtEiMdM+6gD fMbBiQSkhmquTiMWCDPsprVF6+demOITggwCVvysaIW1jOBsM0XOMNqecw7EUs5zDAri 5y2bTRRRgkwhHMh0q6t81DHik7sdSS8xtFNFIgFB5nvIIZf0vXnYEJXCcrIguf54AG/j DC0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="RqO/hmYE"; 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 e1-20020a631e01000000b00438b7cb49fcsi10645027pge.485.2022.09.13.09.33.25; Tue, 13 Sep 2022 09:33: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="RqO/hmYE"; 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 S234290AbiIMOiI (ORCPT + 99 others); Tue, 13 Sep 2022 10:38:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232755AbiIMOgQ (ORCPT ); Tue, 13 Sep 2022 10:36:16 -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 38EB261D69; Tue, 13 Sep 2022 07:20:20 -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 6CB3DB80FA1; Tue, 13 Sep 2022 14:20:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7CFCC433C1; Tue, 13 Sep 2022 14:20:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663078817; bh=XfoVHhO2KwoVqCnflZpVxrBPhafIjjfzPTnfE+4PjpE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RqO/hmYETvcoKUGLh9xGiKQpDbxkglmyKnzd+tcUNROc4yqYuNr45qB5iYijmaauQ D1JPAjb9vvvxSKJp7VKivsPgJ9zTNjIq/YJZOmw6NAY/WCUfA8Ov8TBkWHwIA2To2k 2atuk8Ge9oUTyWw7SlutB+x//EWBVefvL6j4xhwE= 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 5.15 067/121] netfilter: br_netfilter: Drop dst references before setting. Date: Tue, 13 Sep 2022 16:04:18 +0200 Message-Id: <20220913140400.244398540@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140357.323297659@linuxfoundation.org> References: <20220913140357.323297659@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 10a2c7bca7199..a718204c4bfdd 100644 --- a/net/bridge/br_netfilter_hooks.c +++ b/net/bridge/br_netfilter_hooks.c @@ -384,6 +384,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; } @@ -413,6 +414,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 e4e0c836c3f51..6b07f30675bb0 100644 --- a/net/bridge/br_netfilter_ipv6.c +++ b/net/bridge/br_netfilter_ipv6.c @@ -197,6 +197,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