Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp6024495pxb; Mon, 14 Feb 2022 13:22:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJzb7yOWHMKAM8Qmpdf/acsfA4oiwJCJ/JE5GUGMlPAYOO2mkotmPCEGWln9DxA5Lm1BlHWf X-Received: by 2002:a05:6a00:1a53:: with SMTP id h19mr617104pfv.65.1644873762173; Mon, 14 Feb 2022 13:22:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644873762; cv=none; d=google.com; s=arc-20160816; b=vtH0kHT9Zf+0sfNAOzIDFENBh2muf/VQzfQ5cUmOElOw3l5Oj+8VqOaWWJw6hk/AIR XFm8P3ByMssRhiogM8a5RY3HVCeIwHO3Gws1J9DXRflpUGKOd0UoiKezz8FCMwaT7xlD V8+vSLPKAq/ob+X2kpx1A87NtRf5MhgrR2NdGHawrt4KaP9+UemdZU9siBNF1yusp9QI y+NA/Fnoyr73YPOXsxyCZ2A68O4ocAt3uQa3/bzfLGPeP5dcR4HKBFKFbgN+JcSB/a/J uwsz3r4Bf0hJx8DLnwhKayuODwpxH3aTiRZoLUjUbftQRJuSX3EyJRZKjFDUEk7rTKOt HIew== 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=qi4htwqUmHWpW589WSF3d0d05irybebr+yd1SHKaBlc=; b=C4YVHNgKvWsbjJGCZtKWEEeu7CmdYvewR5gQKAE6zf5qQM7oIGJjNuWgsALctzmoPV ELkXOE+tdjMTKyEjCHuF0+1T1jwEWAhby5BKUD4TnXcaE+H6wLzVrpe8MnVaTDY6eTDe KZBls+xiKAH+dNx9keLjwVrjAZabfwvLCOyzLjAhy8LUTaWKYyjVFsGfN8pHCXsrbWFm XIgL+W+nXKk6Dwt1XF1bN4ETuMHhB7sqw9SAQcd3/JFjKB6abnzTN4exJSLzG+4dKJ66 IUIahaMOnXRcdp5vZHc7p7w2pkZ7u5AWkyOf3uibikAjtb9BdriJ8ufnB8Rz1V/C70ho xLhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LVJeGEBm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id a14si6227261plh.214.2022.02.14.13.22.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Feb 2022 13:22:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LVJeGEBm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A53A51AD154; Mon, 14 Feb 2022 12:39:09 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243049AbiBNJo0 (ORCPT + 99 others); Mon, 14 Feb 2022 04:44:26 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:33984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244986AbiBNJlC (ORCPT ); Mon, 14 Feb 2022 04:41:02 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26215A184; Mon, 14 Feb 2022 01:36:48 -0800 (PST) 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 C64F4B80DC4; Mon, 14 Feb 2022 09:36:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D388BC340E9; Mon, 14 Feb 2022 09:36:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644831405; bh=h/90sFQJ4ADpeoVXdbJhADLAI2IKpcQnwVbtczvVWjg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LVJeGEBmloFVjenri8+GQbqerYy2l6KI55vt5u9iidsJJn71sseGtW9HRAhZhP3Gx 4ax0PlVrc5x4VEGpBFTk//ylK+h0gY+bkjLFI8adP5btjVk2tBDI6rTtrbQVWSjBjg 28fNmsLBLIc/p6wR9tcQa0L68/gVVLHdqv2DtHjc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Paolo Abeni , Vlad Buslov , Antoine Tenart , "David S. Miller" , Sasha Levin Subject: [PATCH 5.4 44/71] net: do not keep the dst cache when uncloning an skb dst and its metadata Date: Mon, 14 Feb 2022 10:26:12 +0100 Message-Id: <20220214092453.530126018@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220214092452.020713240@linuxfoundation.org> References: <20220214092452.020713240@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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: Antoine Tenart [ Upstream commit cfc56f85e72f5b9c5c5be26dc2b16518d36a7868 ] When uncloning an skb dst and its associated metadata a new dst+metadata is allocated and the tunnel information from the old metadata is copied over there. The issue is the tunnel metadata has references to cached dst, which are copied along the way. When a dst+metadata refcount drops to 0 the metadata is freed including the cached dst entries. As they are also referenced in the initial dst+metadata, this ends up in UaFs. In practice the above did not happen because of another issue, the dst+metadata was never freed because its refcount never dropped to 0 (this will be fixed in a subsequent patch). Fix this by initializing the dst cache after copying the tunnel information from the old metadata to also unshare the dst cache. Fixes: d71785ffc7e7 ("net: add dst_cache to ovs vxlan lwtunnel") Cc: Paolo Abeni Reported-by: Vlad Buslov Tested-by: Vlad Buslov Signed-off-by: Antoine Tenart Acked-by: Paolo Abeni Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- include/net/dst_metadata.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/net/dst_metadata.h b/include/net/dst_metadata.h index 14efa0ded75dd..b997e0c1e3627 100644 --- a/include/net/dst_metadata.h +++ b/include/net/dst_metadata.h @@ -123,6 +123,19 @@ static inline struct metadata_dst *tun_dst_unclone(struct sk_buff *skb) memcpy(&new_md->u.tun_info, &md_dst->u.tun_info, sizeof(struct ip_tunnel_info) + md_size); +#ifdef CONFIG_DST_CACHE + /* Unclone the dst cache if there is one */ + if (new_md->u.tun_info.dst_cache.cache) { + int ret; + + ret = dst_cache_init(&new_md->u.tun_info.dst_cache, GFP_ATOMIC); + if (ret) { + metadata_dst_free(new_md); + return ERR_PTR(ret); + } + } +#endif + skb_dst_drop(skb); dst_hold(&new_md->dst); skb_dst_set(skb, &new_md->dst); -- 2.34.1