Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3315802rwa; Tue, 23 Aug 2022 02:39:44 -0700 (PDT) X-Google-Smtp-Source: AA6agR4OTwRpvrXpJCioO9+nuJyLjO/1ZHXBadCzIp6VBQqVk8jXaqn79VvAfWItfOYY75peJKfP X-Received: by 2002:a63:90c9:0:b0:42a:306e:5e2b with SMTP id a192-20020a6390c9000000b0042a306e5e2bmr17395978pge.380.1661247584333; Tue, 23 Aug 2022 02:39:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661247584; cv=none; d=google.com; s=arc-20160816; b=xopyDc8AJEClpglgnVAg1IRuKscx6zdeBNPsr7APUvfndG5ThTuuJbMC/WkVbTFuFD 1cTYnyvIqLCNjumOevTVvDI852VxWurfngJHwyo0HDOMqpNYqvyqEg79LHqjaruOXJDm rO3T36ydSuZV7Q+zx2ssxIykKOzf14fdgR+HGOX0ndpJzY3fFii52tYIPmEtDQiUVUda NWyJ5hPWaa3zU8Qfs47htPUBXQG2gyDjBZ+b+YQBIp0JM+O+ZxhEzyMsV4jcU7QmycPE NE7fHFq3cF+9Wy2plrfLigeRfzL4ccZuEhLfx2UfNi6biFlE4U62cTTcdpaFP6x7vtTa hNsQ== 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=zXpTMz858/M5CZvrp+woq7MCm247n4kiTKFLODgNO5o=; b=KPTCcpcPTlh+UvEIz7e1jGKI6hSO2HN5gzrBOOhpsVRullfE7Dd5FSGK9tcBYseDCL cqsl+KZgK0A91tF+v+KeTE63Jd6h7BPcnUoWGbsskQpe5UHwXg3SP+WKHNHVrE0T+wM2 fAGZxMJSFJDFBueWRrDtLTHTG1dGuGgBnZU0w8yhm52jdRZOFtX/cwydQe1SVvGR7XCt nXR46uPqdjrmLyTW908srYXfu1VaXh2MKySwyXdshjBU9Z54/sswRmTsMYBEan2kr1Iw pHFF94LnpRQ1tYlrZhsg/TjUFox+0HWHumWvjv59w4dXY/UzO4PFrcnQg0biqMgNnn8d lobA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TJSH4q6A; 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 138-20020a630090000000b0041183daa0ffsi14706000pga.761.2022.08.23.02.39.31; Tue, 23 Aug 2022 02:39:44 -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=TJSH4q6A; 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 S242067AbiHWIOM (ORCPT + 99 others); Tue, 23 Aug 2022 04:14:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242065AbiHWIKd (ORCPT ); Tue, 23 Aug 2022 04:10:33 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58A2B696ED; Tue, 23 Aug 2022 01:07:24 -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 dfw.source.kernel.org (Postfix) with ESMTPS id BBA19611A8; Tue, 23 Aug 2022 08:07:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7BFE9C433C1; Tue, 23 Aug 2022 08:07:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661242043; bh=QNfINd91NqgJ9BUqFSr2vO2WJPc3BM8wKhR0VOZG5r4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TJSH4q6Az0TXVHESSsBBALcdckEZqwh486+SJOUt7nbX/oZ5SK+NCQHIA9G2gGUs5 OZbYu3O85LM1pwtJNW6RZLi7ctzq5kXT96kePrg9cX/eYVS7Rlka+AtC4xCKYNZYgI G/hV7zX31WsB7mNcapOK5TRIUNb0Yx2sHlzoDTYU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hangbin Liu , Florian Westphal , Jakub Kicinski Subject: [PATCH 5.19 050/365] netfilter: nf_tables: fix crash when nf_trace is enabled Date: Tue, 23 Aug 2022 09:59:11 +0200 Message-Id: <20220823080120.280846182@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080118.128342613@linuxfoundation.org> References: <20220823080118.128342613@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: Florian Westphal commit 399a14ec7993d605740de7b2cd5c0ce8407d12ed upstream. do not access info->pkt when info->trace is not 1. nft_traceinfo is not initialized, except when tracing is enabled. The 'nft_trace_enabled' static key cannot be used for this, we must always check info->trace first. Pass nft_pktinfo directly to avoid this. Fixes: e34b9ed96ce3 ("netfilter: nf_tables: avoid skb access on nf_stolen") Reported-by: Hangbin Liu Signed-off-by: Florian Westphal Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/netfilter/nf_tables_core.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/net/netfilter/nf_tables_core.c b/net/netfilter/nf_tables_core.c index 3ddce24ac76d..cee3e4e905ec 100644 --- a/net/netfilter/nf_tables_core.c +++ b/net/netfilter/nf_tables_core.c @@ -34,25 +34,23 @@ static noinline void __nft_trace_packet(struct nft_traceinfo *info, nft_trace_notify(info); } -static inline void nft_trace_packet(struct nft_traceinfo *info, +static inline void nft_trace_packet(const struct nft_pktinfo *pkt, + struct nft_traceinfo *info, const struct nft_chain *chain, const struct nft_rule_dp *rule, enum nft_trace_types type) { if (static_branch_unlikely(&nft_trace_enabled)) { - const struct nft_pktinfo *pkt = info->pkt; - info->nf_trace = pkt->skb->nf_trace; info->rule = rule; __nft_trace_packet(info, chain, type); } } -static inline void nft_trace_copy_nftrace(struct nft_traceinfo *info) +static inline void nft_trace_copy_nftrace(const struct nft_pktinfo *pkt, + struct nft_traceinfo *info) { if (static_branch_unlikely(&nft_trace_enabled)) { - const struct nft_pktinfo *pkt = info->pkt; - if (info->trace) info->nf_trace = pkt->skb->nf_trace; } @@ -96,7 +94,6 @@ static noinline void __nft_trace_verdict(struct nft_traceinfo *info, const struct nft_chain *chain, const struct nft_regs *regs) { - const struct nft_pktinfo *pkt = info->pkt; enum nft_trace_types type; switch (regs->verdict.code) { @@ -110,7 +107,9 @@ static noinline void __nft_trace_verdict(struct nft_traceinfo *info, break; default: type = NFT_TRACETYPE_RULE; - info->nf_trace = pkt->skb->nf_trace; + + if (info->trace) + info->nf_trace = info->pkt->skb->nf_trace; break; } @@ -271,10 +270,10 @@ nft_do_chain(struct nft_pktinfo *pkt, void *priv) switch (regs.verdict.code) { case NFT_BREAK: regs.verdict.code = NFT_CONTINUE; - nft_trace_copy_nftrace(&info); + nft_trace_copy_nftrace(pkt, &info); continue; case NFT_CONTINUE: - nft_trace_packet(&info, chain, rule, + nft_trace_packet(pkt, &info, chain, rule, NFT_TRACETYPE_RULE); continue; } @@ -318,7 +317,7 @@ nft_do_chain(struct nft_pktinfo *pkt, void *priv) goto next_rule; } - nft_trace_packet(&info, basechain, NULL, NFT_TRACETYPE_POLICY); + nft_trace_packet(pkt, &info, basechain, NULL, NFT_TRACETYPE_POLICY); if (static_branch_unlikely(&nft_counters_enabled)) nft_update_chain_stats(basechain, pkt); -- 2.37.2