Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2928639rwb; Mon, 15 Aug 2022 14:14:15 -0700 (PDT) X-Google-Smtp-Source: AA6agR6Cg48ae8YFVbN2b2FT9dibzU4QWQGNk4FAUbhLZ19mZuiqs++nh/DFIteHczJ4ZTF3ddjB X-Received: by 2002:a63:be09:0:b0:41f:12f5:6475 with SMTP id l9-20020a63be09000000b0041f12f56475mr15408585pgf.396.1660597957538; Mon, 15 Aug 2022 14:12:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660597957; cv=none; d=google.com; s=arc-20160816; b=hwfckOpRHrwo0XA4CtmH7bGamhrj7tyd4PiGnK+I4wh2T6BeNfyWg8ED0mQVA6Wujt bTy7ouwOFgQsYjvy1b/m68h2q1mgyRuwfp/MVdpCmhozWtzhhW14y3DGk3GjCp7ySGPb fHIOt7KqIniOHobVIr/T26XShWXAiuFN+hxQi9dOAFCYKEJbiCaX5yO4nntctUHlWJx6 3I7jyPm0+RvE5EMEXnUFpIjxFUDBxmMMNcMr1We8jYDFfqKp2ZIupjYrjvh3qKk9/ET1 dPwViWTlO/YAg+6gQ0ra18/s76GegY/TRqhV9pArD2wQcy19eHAScIp1To9P7zAtyL9s LFBg== 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=9uGYgVX57HZ8Gzu72Qz7RWjy7A7fGrMZpAAHq801Q+w=; b=O2dKFtA2IMtcFKSSvGT8YD7wLIPZd9yyA81XTfkufkKHRD9shvUj7zAzszaWDw+pwy E4wdaLlru9UyLCm2K03ftaVg5s3EuIK1lGlCBYnOYBMVSZHsKykRJYwd7Lq34rguxzEw /2eV2g63J4grY/A5RcgLtCd3PyjhNKaUuylFUjKHoT9vzfjRpvD/n2TBBACVZGMmSRyd Vmj1zLk4g65HPofMCSLraZm7hH7yPWqgg9beFvKy69jtJLb5lr3IqvsPMjHOUHhWnpzh tL2Mq0vs0G807yDOFu8Fh0TwEYmtEU5GbQ+mSJwd3kEDZXdU0CfuVtxoe3/iCWQoJESd JAOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JbL9p6j4; 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 e8-20020a636908000000b00410ac395252si11233156pgc.512.2022.08.15.14.12.25; Mon, 15 Aug 2022 14:12:37 -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=JbL9p6j4; 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 S1348247AbiHOUcW (ORCPT + 99 others); Mon, 15 Aug 2022 16:32:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347738AbiHOU0d (ORCPT ); Mon, 15 Aug 2022 16:26:33 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28F219DFA8; Mon, 15 Aug 2022 12:03:40 -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 E41F761299; Mon, 15 Aug 2022 19:03:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E2C00C433D7; Mon, 15 Aug 2022 19:03:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660590207; bh=pMLp0+qYNKEIUa9AGUAmCf0y2RNO1+e4eW/XAxC26Kg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JbL9p6j4Cn0XwGsSWa21uXcOIMhAPMn0nMfW35ay8rAo8fpUYPCjYpaR+TIrBU6sE gl6RCpvWKQB6G1Vi0EMKW7Jxc/OFXQiDhDpVNjHHuZpzvym4fsf8wLxE1pBmK4iDaU asKUB/ZJLxLVo/tyVGgHw+7gbYf8XuLOgKwhMQwo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Florian Westphal , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 5.18 0186/1095] netfilter: nft_queue: only allow supported familes and hooks Date: Mon, 15 Aug 2022 19:53:05 +0200 Message-Id: <20220815180437.333474752@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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 47f4f510ad586032b85c89a0773fbb011d412425 ] Trying to use 'queue' statement in ingress (for example) triggers a splat on reinject: WARNING: CPU: 3 PID: 1345 at net/netfilter/nf_queue.c:291 ... because nf_reinject cannot find the ruleset head. The netdev family doesn't support async resume at the moment anyway, so disallow loading such rulesets with a more appropriate error message. v2: add 'validate' callback and also check hook points, v1 did allow ingress use in 'table inet', but that doesn't work either. (Pablo) Signed-off-by: Florian Westphal Reviewed-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/nft_queue.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/net/netfilter/nft_queue.c b/net/netfilter/nft_queue.c index 15e4b7640dc0..da29e92c03e2 100644 --- a/net/netfilter/nft_queue.c +++ b/net/netfilter/nft_queue.c @@ -68,6 +68,31 @@ static void nft_queue_sreg_eval(const struct nft_expr *expr, regs->verdict.code = ret; } +static int nft_queue_validate(const struct nft_ctx *ctx, + const struct nft_expr *expr, + const struct nft_data **data) +{ + static const unsigned int supported_hooks = ((1 << NF_INET_PRE_ROUTING) | + (1 << NF_INET_LOCAL_IN) | + (1 << NF_INET_FORWARD) | + (1 << NF_INET_LOCAL_OUT) | + (1 << NF_INET_POST_ROUTING)); + + switch (ctx->family) { + case NFPROTO_IPV4: + case NFPROTO_IPV6: + case NFPROTO_INET: + case NFPROTO_BRIDGE: + break; + case NFPROTO_NETDEV: /* lacks okfn */ + fallthrough; + default: + return -EOPNOTSUPP; + } + + return nft_chain_validate_hooks(ctx->chain, supported_hooks); +} + static const struct nla_policy nft_queue_policy[NFTA_QUEUE_MAX + 1] = { [NFTA_QUEUE_NUM] = { .type = NLA_U16 }, [NFTA_QUEUE_TOTAL] = { .type = NLA_U16 }, @@ -164,6 +189,7 @@ static const struct nft_expr_ops nft_queue_ops = { .eval = nft_queue_eval, .init = nft_queue_init, .dump = nft_queue_dump, + .validate = nft_queue_validate, .reduce = NFT_REDUCE_READONLY, }; @@ -173,6 +199,7 @@ static const struct nft_expr_ops nft_queue_sreg_ops = { .eval = nft_queue_sreg_eval, .init = nft_queue_sreg_init, .dump = nft_queue_sreg_dump, + .validate = nft_queue_validate, .reduce = NFT_REDUCE_READONLY, }; -- 2.35.1