Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4824719yba; Tue, 30 Apr 2019 05:06:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqzwJuvZU12msD14uKsk7WBbz8ciSHNd5HBknK2bhHRImHY8ZdJ6r1XALvFmiyt7LfmGsUj1 X-Received: by 2002:a63:10c:: with SMTP id 12mr67937829pgb.276.1556626014101; Tue, 30 Apr 2019 05:06:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556626014; cv=none; d=google.com; s=arc-20160816; b=q0EwsEYfYSbDpSJj8o8oK0WIqDJZCPtZkYhh92rnMtUtaUIzeSLIKy9LedG1yXolLn sdLKiISA2+CdUXB2u8+c8qhrXx81JUNPVIPWp2I/pGB+pNHNOZxSltmdIWs4ULNAPWRk K0+nlhCJ89lrLZMzDf2wmRGqbU2mQsTq670j49vUMqz7y0aYuSSogKRqM3Jh5WBmuqLl egwv4c7yqkdgzZRvQ80RS3OM8tdKTmioFpbha8MEQ+zZGlou8jhJpqfli774XrDgtHM+ GwpD+uMSWut7ML7TZbryAoE8AXKYFND8W1Z2+vunNpvwDhPnaxl6bwI/0bMMG/iRZHWa E0kA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=sz212AZaaQ6sC6YYfPfcPPicypP1vbGrmgCfpkGFbyg=; b=lZB7QYbmL/UWTjkIFBfXNwroZGb+BVtCOtIRgHZpyr6xlttgc6ETwUTQz2ggYWh2yL 0xsvsy05h1da1IZIotAJSleQIguIYJ/vPLEIknzW4oWoRX1lCrRCbmKJ8KD5FaWmfvpg ShFOlCtny9B93hvKGQ1XO9ttjrUvXbMxwM2xDwTo79h6cF3Xr3x7PO8vjPkMQnWabqcg W9S5iH4RHXJTZTrVESLvqu+cS/1LSZ+r0vnrp6+k6LzhXCnD7mXk9IQgi2DGpJDKOaP/ crT5KtquOu/NWqz4EfB+yuxE8S40oqzDG45B2EWjcxRT6T/jMfJwZZ1uiCeh+UKYGRpN 2WfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=keIzluzZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r10si34058593pgp.30.2019.04.30.05.06.37; Tue, 30 Apr 2019 05:06:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=keIzluzZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728100AbfD3MCt (ORCPT + 99 others); Tue, 30 Apr 2019 08:02:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:54478 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730016AbfD3Lnv (ORCPT ); Tue, 30 Apr 2019 07:43:51 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B8C1E21707; Tue, 30 Apr 2019 11:43:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556624630; bh=YGRx5VxwEXCkogZbYt4NHvidQoiAzq1HlPlq2VdV9Ms=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=keIzluzZH1LxGHpQIttzGIxOAXDMb+5itWXgqDL0gKSFPLtYzL/Ddxj5DTXQ3C8+6 u7SkATDq6VhpAMb7lrOTWfYTgqZZ2yufByjKN2UMJm9bugLDyJ4lOT0Tf0nLaa7boy 9qbjsUn0j5yifEsqKOR1HBwhl2+VMZiH5Qrew+eM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Florian Westphal , Pablo Neira Ayuso Subject: [PATCH 4.19 005/100] netfilter: nf_tables: warn when expr implements only one of activate/deactivate Date: Tue, 30 Apr 2019 13:37:34 +0200 Message-Id: <20190430113608.892225940@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190430113608.616903219@linuxfoundation.org> References: <20190430113608.616903219@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ->destroy is only allowed to free data, or do other cleanups that do not have side effects on other state, such as visibility to other netlink requests. Such things need to be done in ->deactivate. As a transaction can fail, we need to make sure we can undo such operations, therefore ->activate() has to be provided too. So print a warning and refuse registration if expr->ops provides only one of the two operations. v2: fix nft_expr_check_ops to not repeat same check twice (Jones Desougi) Signed-off-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nf_tables_api.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c index 667f6eccbec7..dd2b28a09bd4 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -207,6 +207,18 @@ static int nft_delchain(struct nft_ctx *ctx) return err; } +/* either expr ops provide both activate/deactivate, or neither */ +static bool nft_expr_check_ops(const struct nft_expr_ops *ops) +{ + if (!ops) + return true; + + if (WARN_ON_ONCE((!ops->activate ^ !ops->deactivate))) + return false; + + return true; +} + static void nft_rule_expr_activate(const struct nft_ctx *ctx, struct nft_rule *rule) { @@ -1914,6 +1926,9 @@ static int nf_tables_delchain(struct net *net, struct sock *nlsk, */ int nft_register_expr(struct nft_expr_type *type) { + if (!nft_expr_check_ops(type->ops)) + return -EINVAL; + nfnl_lock(NFNL_SUBSYS_NFTABLES); if (type->family == NFPROTO_UNSPEC) list_add_tail_rcu(&type->list, &nf_tables_expressions); @@ -2061,6 +2076,10 @@ static int nf_tables_expr_parse(const struct nft_ctx *ctx, err = PTR_ERR(ops); goto err1; } + if (!nft_expr_check_ops(ops)) { + err = -EINVAL; + goto err1; + } } else ops = type->ops; -- 2.19.1