Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E818BC433EF for ; Wed, 16 Mar 2022 17:44:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353864AbiCPRqM (ORCPT ); Wed, 16 Mar 2022 13:46:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344405AbiCPRqM (ORCPT ); Wed, 16 Mar 2022 13:46:12 -0400 Received: from orbyte.nwl.cc (orbyte.nwl.cc [IPv6:2001:41d0:e:133a::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D7A739684 for ; Wed, 16 Mar 2022 10:44:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nwl.cc; s=mail2022; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=3h8heVKeSq8ILbSxSQp8J9mZT+CZ/eHlQ3nUjL12m6o=; b=TJvewTad6pru1M3gllJB959D1q KFHnnxgUX41BI9vQuuTJuxuSC1IZdtRZqOZ14HwbVHS5J3sizm0wu+qdgrfFJiuYx68U0OkeHrtyR bugyZlI/71K0pnnGqpI0+O5IhXGMiz7Ie4/XDW0NmVI94pWbjXaofCfezC+BBDGkoXEl9n6UJlgTx Orp1chbjma/6A9eYe5sXKh3g759reXKSPngzdp/YzOeN1yxwZ1cWW6HVtTRvmA5teMzmkbIjl8fyH q/dAKvAVeRxzG9wnVHNbNUs8hUb1JrANpgyT51TZzv8z3b2Vw3olSmZNiXLA7EEW8E5bb8B4CW/e6 uUE8AySQ==; Received: from localhost ([::1] helo=xic) by orbyte.nwl.cc with esmtp (Exim 4.94.2) (envelope-from ) id 1nUXhg-0000Oz-Md; Wed, 16 Mar 2022 18:44:56 +0100 From: Phil Sutter To: Pablo Neira Ayuso Cc: Florian Westphal , netfilter-devel@vger.kernel.org Subject: [iptables PATCH 3/3] libxtables: Boost rule target checks by announcing chain names Date: Wed, 16 Mar 2022 18:44:43 +0100 Message-Id: <20220316174443.1930-4-phil@nwl.cc> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220316174443.1930-1-phil@nwl.cc> References: <20220316174443.1930-1-phil@nwl.cc> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org When restoring a ruleset, feed libxtables with chain names from respective lines to avoid an extension search. While the user's intention is clear, this effectively disables the sanity check for clashes with target extensions. But: * The check yielded only a warning and the clashing chain was finally accepted. * Users crafting iptables dumps for feeding into iptables-restore likely know what they're doing. Signed-off-by: Phil Sutter --- include/xtables.h | 3 +++ iptables/iptables-restore.c | 1 + iptables/xtables-restore.c | 1 + libxtables/xtables.c | 6 ++++++ 4 files changed, 11 insertions(+) diff --git a/include/xtables.h b/include/xtables.h index ca674c2663eb4..816a157d5577d 100644 --- a/include/xtables.h +++ b/include/xtables.h @@ -645,6 +645,9 @@ const char *xt_xlate_get(struct xt_xlate *xl); #define xt_xlate_rule_get xt_xlate_get const char *xt_xlate_set_get(struct xt_xlate *xl); +/* informed target lookups */ +void xtables_announce_chain(const char *name); + #ifdef XTABLES_INTERNAL /* Shipped modules rely on this... */ diff --git a/iptables/iptables-restore.c b/iptables/iptables-restore.c index 1917fb2315665..4cf0d3dadead9 100644 --- a/iptables/iptables-restore.c +++ b/iptables/iptables-restore.c @@ -308,6 +308,7 @@ ip46tables_restore_main(const struct iptables_restore_cb *cb, cb->ops->strerror(errno)); } + xtables_announce_chain(chain); ret = 1; } else if (in_table) { diff --git a/iptables/xtables-restore.c b/iptables/xtables-restore.c index c94770a0175eb..8ee0bb91f7d44 100644 --- a/iptables/xtables-restore.c +++ b/iptables/xtables-restore.c @@ -155,6 +155,7 @@ static void xtables_restore_parse_line(struct nft_handle *h, "%s: line %u chain name invalid\n", xt_params->program_name, line); + xtables_announce_chain(chain); assert_valid_chain_name(chain); policy = strtok(NULL, " \t\n"); diff --git a/libxtables/xtables.c b/libxtables/xtables.c index 49790046a79d8..60e7c6e90b448 100644 --- a/libxtables/xtables.c +++ b/libxtables/xtables.c @@ -321,6 +321,12 @@ static void notargets_hlist_insert(const char *name) hlist_add_head(&cur->node, ¬argets[djb_hash(name) % NOTARGET_HSIZE]); } +void xtables_announce_chain(const char *name) +{ + if (!notargets_hlist_lookup(name)) + notargets_hlist_insert(name); +} + void xtables_init(void) { /* xtables cannot be used with setuid in a safe way. */ -- 2.34.1