Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp6778576rwn; Tue, 13 Sep 2022 08:55:10 -0700 (PDT) X-Google-Smtp-Source: AA6agR6wEpk5du3XEK4MO+WSiKM1szuEDtAl8x7qKQU6NGLwYXfZR2UfToLPb/aO2UNhX68i/6rP X-Received: by 2002:a17:907:80d:b0:73d:1e3f:3d83 with SMTP id wv13-20020a170907080d00b0073d1e3f3d83mr21886632ejb.372.1663084510461; Tue, 13 Sep 2022 08:55:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663084510; cv=none; d=google.com; s=arc-20160816; b=Oulhusa3Pauj8TycHgCvBd43Jy02G587+LA4RYQ+AAykoqtYYPZom2BYvxbyV3faV7 wTmM5nC8Bw60UiufYLQEDsbfzfsIxFMyUKvoWjfi4lJBNuuPuCkO83/eGCo624XoDzRq x+PXpdDFz7rgOFkaLrXwQGMz5Mk+lIcfWn0LJ9e/zBXlA9N5sqMD3mGkTTFe2q3vq7hF oqfg6fm09A4RVr/6gv91kZ4sup+k6n5PI22529qH9CETIcVX7TABZzy62qw8NHZmUfYH SWN0SHIP7JykeMw3GrjITA6ITnsM5FZ7W2rI99KMZtXKUNUyoNMYHxyiTGfqUCctA54y zryg== 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=12NfPYyZ+vJuRAmzRUG2hPjszRcmrRF3UBtg5+Wa/2w=; b=gi+0m/Z+UpdQm1gIGAVA0XMCZjjjgNMidTM9Rchho1h82HqjfwaMSbIFd20kH9u8KN tmXOZ3Nq5doUzrGx4PXlalE8RpuxH5H4Os8KgUUllcyuvegbR+DhgzRH2YO82KDibKpI v0vFuI/URrj9LInMUeJJIbW3UDqp/wcGiP/i67r8SgevXfFf3CXvn+S9+5pfjGS5/9JG hBg2y+DJBo5Vcdd7WNBbKP5TCxn2jM4rQMleHFtjzocJh2O63L8QOxhPMiiBupVEVsim WBKydRgQlmnMrDmVU/abLOWYbBs0/JjPYInw9Am1obxWHnBz0U3lbaO85a7aEsedBi/B VnSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=A7feDNdo; 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 su14-20020a17090703ce00b00733b061e7bdsi8167194ejb.637.2022.09.13.08.54.43; Tue, 13 Sep 2022 08:55:10 -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=A7feDNdo; 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 S236406AbiIMPaQ (ORCPT + 99 others); Tue, 13 Sep 2022 11:30:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236405AbiIMP2Q (ORCPT ); Tue, 13 Sep 2022 11:28:16 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B75917E02A; Tue, 13 Sep 2022 07:39: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 A1923B80FA3; Tue, 13 Sep 2022 14:37:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00FDCC433D7; Tue, 13 Sep 2022 14:37:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663079840; bh=7ZrUN5zfnkKmXyFUuuhSFt6n4LXxlZEioAODx00t/9o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A7feDNdoQYnqbI0UJkhkDFFy5GzOczs0j5/i6CSfpHTSYWTEefM13gVskCO5V66WX I8nuCFMSqChe8l8/nErlSVZ1VI2kWW/OzKxJdyS9OYw2cv7RVk8z9p2DIPkvAohmOt L/nzp76jeaXo7eFpWmj9x/QBMYMCf32czQbbefpk= 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.9 34/42] netfilter: br_netfilter: Drop dst references before setting. Date: Tue, 13 Sep 2022 16:08:05 +0200 Message-Id: <20220913140344.087722465@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140342.228397194@linuxfoundation.org> References: <20220913140342.228397194@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 11d4d18012fed..560a36c68be20 100644 --- a/net/bridge/br_netfilter_hooks.c +++ b/net/bridge/br_netfilter_hooks.c @@ -382,6 +382,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; } @@ -411,6 +412,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 8c08dd07419f6..54dcead37dfd0 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