Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3077331rwe; Mon, 29 Aug 2022 05:34:14 -0700 (PDT) X-Google-Smtp-Source: AA6agR6MTZP5+zQ0CTwW+xVlXjTnR5nOyhQaqeqKiJJVChgtXfdiorgSyZJp5ay5Yj6xsDoboLsf X-Received: by 2002:a17:902:eccb:b0:174:5227:ace6 with SMTP id a11-20020a170902eccb00b001745227ace6mr12855764plh.18.1661776454274; Mon, 29 Aug 2022 05:34:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661776454; cv=none; d=google.com; s=arc-20160816; b=diQ67sEPopuvLtIvmcICYiGm1xCzFJCoKHhy041HzLZKGc9WbdE6uh1kBjK7Q7+axG 5Ub0TQt96Hf27Q1sGPghbvQyW2yp8Vnkxa3j5CMzgdR5OQDShihsLLGUZpNiziU6ThUg tgVe2aOtqd53v8zDiizX4UEciZ1/sO+4L95o2dlJTPJnswuqF4sqvpLma5QWeJCdn6XV u7aTOq1PAarxq7pWrZ/wJqTNMA/5KhWPcgP+qGv9xSTmNBMKmuGrqVXK0KJRzPxpVkcP 10RgKruoYvkFgi/ftnHHMA+E1gPfLQkz6fEt0w/eNgFUNpC/od0tZMKmvlNIZexupH5J hI/Q== 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=m/7wvMgCeNhjCTsxAayx/yanGv8My3XyM+gsWigerDo=; b=lpT1Jhi6yyv0KACI0NhRA2r/7UoXn5Ki00E7Wne9jEfnDayoJ2nRAbYJImBN/cT2LQ 33KqkvxcZhOJoqUvlhWF9JK3yJ/Pzzcj3YX2ItzRElw2Pg/k89WsuH3Vi+whrILjsyQy cgm1s07CCJTQTub12/FJ0SYnb7xx9GYwQJD8djg+7lzdqX2HE5zef6yXkQtv8My2OqIS FvlFSlWpUXW00PaMrRNw0kJfqFdxTrQOZArtu6lYHFEnAIEuYm/TV+iuaakyVRAZz1Wj dPKNrS9I/AX8x8SFe7PE/P/3X+s38lxo1Goqju/AWDG5EtOJivX+CC41TCQbUi23rTl3 0X4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GjngkI1R; 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 nv18-20020a17090b1b5200b001fddccc9214si1953590pjb.171.2022.08.29.05.34.01; Mon, 29 Aug 2022 05:34:14 -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=GjngkI1R; 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 S231648AbiH2LVv (ORCPT + 99 others); Mon, 29 Aug 2022 07:21:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231642AbiH2LUh (ORCPT ); Mon, 29 Aug 2022 07:20:37 -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 262E775CCD; Mon, 29 Aug 2022 04:13:36 -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 95DD1611B3; Mon, 29 Aug 2022 11:13:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A50CFC433C1; Mon, 29 Aug 2022 11:13:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661771614; bh=DHfQ2MVPDKZLOla2IysgKsIAjBu/fzi98akwzPOfeyI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GjngkI1RTrzRfWHL1I/kBEswLnxMjaD6JhAnFrrCNT2rEucRi3GGYqWwoM10TPHuY jT/9NLCeDwOoeFJXsaWBpXhADadmZeOHXdAPjIhK4xY0JsVcowuZEWT8+BiXNGF4oP aSrtuQIdNIo1NkE9uEJZeLmomgVLIlc1FohKbZQQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shell Chen , Florian Westphal , Sasha Levin Subject: [PATCH 5.19 050/158] netfilter: nft_tproxy: restrict to prerouting hook Date: Mon, 29 Aug 2022 12:58:20 +0200 Message-Id: <20220829105810.840201024@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220829105808.828227973@linuxfoundation.org> References: <20220829105808.828227973@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 [ Upstream commit 18bbc3213383a82b05383827f4b1b882e3f0a5a5 ] TPROXY is only allowed from prerouting, but nft_tproxy doesn't check this. This fixes a crash (null dereference) when using tproxy from e.g. output. Fixes: 4ed8eb6570a4 ("netfilter: nf_tables: Add native tproxy support") Reported-by: Shell Chen Signed-off-by: Florian Westphal Signed-off-by: Sasha Levin --- net/netfilter/nft_tproxy.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/net/netfilter/nft_tproxy.c b/net/netfilter/nft_tproxy.c index 801f013971dfa..a701ad64f10af 100644 --- a/net/netfilter/nft_tproxy.c +++ b/net/netfilter/nft_tproxy.c @@ -312,6 +312,13 @@ static int nft_tproxy_dump(struct sk_buff *skb, return 0; } +static int nft_tproxy_validate(const struct nft_ctx *ctx, + const struct nft_expr *expr, + const struct nft_data **data) +{ + return nft_chain_validate_hooks(ctx->chain, 1 << NF_INET_PRE_ROUTING); +} + static struct nft_expr_type nft_tproxy_type; static const struct nft_expr_ops nft_tproxy_ops = { .type = &nft_tproxy_type, @@ -321,6 +328,7 @@ static const struct nft_expr_ops nft_tproxy_ops = { .destroy = nft_tproxy_destroy, .dump = nft_tproxy_dump, .reduce = NFT_REDUCE_READONLY, + .validate = nft_tproxy_validate, }; static struct nft_expr_type nft_tproxy_type __read_mostly = { -- 2.35.1