Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2076789ybp; Thu, 10 Oct 2019 01:46:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqwElchZzvBV0sMt/hDhPWPB3zrTDZ67j+Wb8ClPRCYw4ctGijVoJ3fAZzRxh8usm73ZVj6K X-Received: by 2002:a17:906:4908:: with SMTP id b8mr6901422ejq.83.1570697171345; Thu, 10 Oct 2019 01:46:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570697171; cv=none; d=google.com; s=arc-20160816; b=kcsTh5geXQeQy/ydbhWXkwJ0xkLAJk1wLJU0JrVMcdkXCgCSOv0x9qp3UoH62BbP5e 7ASqcCr90ojuOKzzohsWeGmEIxKfJwpQL2iHtC106iohqumQ/vDV+XQLFuQ6K7FrCf+I wAwnwPRy1cpcZ8gQkErl8ICj50xsrmiOLT+PnmiTafJHJn+5aqZwTe6egnkxNZ9ceDuH e2g/RMflhcSuKBGmHKhC51fBGmlk6mhSUl4ITaT3D+njXlYFNi1zgdtKl0YjJ2I0Z442 4nd2U40G2FSM7HUxIX7vQzoYwKNml4JomHKKXqgOvo0cwCTkz4u1exGemqeMbnK72N48 fYnA== 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=FBo5Mday7g0Kvl+3jlw4j+8zMXryoAL8pnx62Rd2FFM=; b=Vlno+OvR4ZR37NLyqXhtWHGYmnPqiCfR/k6NXKtxzY75/jNyY3QSxmJMq4AynX9GmA lQ3fq5g1AZFLizWnXs8BJp0UQ0unpxX206dXw2plTDYXqmZsFv6MjqpLZKlp5oAoF3xu iQaH0DoQmeTH2aXSEqu/ATNrbTurJjxoC7uF9oi+XlLJ49D/yEe/6YN3Fsd5r3XuYlam d1diE42o6MzPifUk2suoqM9Gn/F4bNx1zvKj5/nKYaRgswyUWA/vfbHOVUY/Fy5oJBsA uZRPNc7/Wq+tYxerMSMiE8oEJbpNEnI7s/7WMpgP9QTUpBwbb4s1uAGjptCPyUtPs4io 78rQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dEQXK27X; 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 96si3224965edq.24.2019.10.10.01.45.48; Thu, 10 Oct 2019 01:46:11 -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=dEQXK27X; 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 S2388479AbfJJImH (ORCPT + 99 others); Thu, 10 Oct 2019 04:42:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:46630 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387736AbfJJImG (ORCPT ); Thu, 10 Oct 2019 04:42:06 -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 38C002190F; Thu, 10 Oct 2019 08:42:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570696925; bh=VS50HS4GAI4UbJUyzF+xJ0UN7GNEKsohNTeuNnlWgOw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dEQXK27X63OZwjOz7m3oKNc2NFMfkQF967QV7sMw1yJ/ET4M3f6aQ9+VA6F6OnxOL dT5PDeB61kCH8aNchSxuibJ9l5edf8NSPqd/nf0+9ZivZ1aIMGK8gMwmNAU9KC5qDW QQe2PvgkJdz0vryEwSWOt31jPJqTPcJQNxmgKtnI= 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.3 103/148] netfilter: nf_tables: allow lookups in dynamic sets Date: Thu, 10 Oct 2019 10:36:04 +0200 Message-Id: <20191010083617.454672527@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191010083609.660878383@linuxfoundation.org> References: <20191010083609.660878383@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 From: Florian Westphal [ Upstream commit acab713177377d9e0889c46bac7ff0cfb9a90c4d ] This un-breaks lookups in sets that have the 'dynamic' flag set. Given this active example configuration: table filter { set set1 { type ipv4_addr size 64 flags dynamic,timeout timeout 1m } chain input { type filter hook input priority 0; policy accept; } } ... this works: nft add rule ip filter input add @set1 { ip saddr } -> whenever rule is triggered, the source ip address is inserted into the set (if it did not exist). This won't work: nft add rule ip filter input ip saddr @set1 counter Error: Could not process rule: Operation not supported In other words, we can add entries to the set, but then can't make matching decision based on that set. That is just wrong -- all set backends support lookups (else they would not be very useful). The failure comes from an explicit rejection in nft_lookup.c. Looking at the history, it seems like NFT_SET_EVAL used to mean 'set contains expressions' (aka. "is a meter"), for instance something like nft add rule ip filter input meter example { ip saddr limit rate 10/second } or nft add rule ip filter input meter example { ip saddr counter } The actual meaning of NFT_SET_EVAL however, is 'set can be updated from the packet path'. 'meters' and packet-path insertions into sets, such as 'add @set { ip saddr }' use exactly the same kernel code (nft_dynset.c) and thus require a set backend that provides the ->update() function. The only set that provides this also is the only one that has the NFT_SET_EVAL feature flag. Removing the wrong check makes the above example work. While at it, also fix the flag check during set instantiation to allow supported combinations only. Fixes: 8aeff920dcc9b3f ("netfilter: nf_tables: add stateful object reference to set elements") Signed-off-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/nf_tables_api.c | 7 +++++-- net/netfilter/nft_lookup.c | 3 --- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c index d47469f824a10..3b81323fa0171 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -3562,8 +3562,11 @@ static int nf_tables_newset(struct net *net, struct sock *nlsk, NFT_SET_OBJECT)) return -EINVAL; /* Only one of these operations is supported */ - if ((flags & (NFT_SET_MAP | NFT_SET_EVAL | NFT_SET_OBJECT)) == - (NFT_SET_MAP | NFT_SET_EVAL | NFT_SET_OBJECT)) + if ((flags & (NFT_SET_MAP | NFT_SET_OBJECT)) == + (NFT_SET_MAP | NFT_SET_OBJECT)) + return -EOPNOTSUPP; + if ((flags & (NFT_SET_EVAL | NFT_SET_OBJECT)) == + (NFT_SET_EVAL | NFT_SET_OBJECT)) return -EOPNOTSUPP; } diff --git a/net/netfilter/nft_lookup.c b/net/netfilter/nft_lookup.c index c0560bf3c31bd..660bad688e2bc 100644 --- a/net/netfilter/nft_lookup.c +++ b/net/netfilter/nft_lookup.c @@ -73,9 +73,6 @@ static int nft_lookup_init(const struct nft_ctx *ctx, if (IS_ERR(set)) return PTR_ERR(set); - if (set->flags & NFT_SET_EVAL) - return -EOPNOTSUPP; - priv->sreg = nft_parse_register(tb[NFTA_LOOKUP_SREG]); err = nft_validate_register_load(priv->sreg, set->klen); if (err < 0) -- 2.20.1