Netfilter fixes for net
Subsystems (4)
Pablo Neira Ayuso
maintainercover Netfilter fixes for net
Hi,
The following patchset contains Netfilter fixes for net:
1) Add NFT_CHAIN_POLICY_UNSET to replace hardcoded -1 to specify that the chain policy is unset. The chain policy field is actually defined as an 8-bit unsigned integer.
2) Remove always true condition reported by smatch in chain policy check.
3) Fix element lookup on dynamic sets, from Florian Westphal.
4) Use __u8 in ebtables uapi header, from Masahiro Yamada.
5) Bogus EBUSY when removing flowtable after chain flush, from Laura Garcia Liebana.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
Thanks.
----------------------------------------------------------------
The following changes since commit 864668bfc374dfbf4851ec828b9049e08f9057b1:
selftests: Add test cases for ip nexthop flush proto XX (2019-09-19 18:35:55 -0700)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git HEAD
for you to fetch changes up to 9b05b6e11d5e93a3a517cadc12b9836e0470c255:
netfilter: nf_tables: bogus EBUSY when deleting flowtable after flush (2019-09-25 11:01:19 +0200)
----------------------------------------------------------------
Florian Westphal (1):
netfilter: nf_tables: allow lookups in dynamic sets
Laura Garcia Liebana (1):
netfilter: nf_tables: bogus EBUSY when deleting flowtable after flush
Masahiro Yamada (1):
netfilter: ebtables: use __u8 instead of uint8_t in uapi header
Pablo Neira Ayuso (2):
netfilter: nf_tables: add NFT_CHAIN_POLICY_UNSET and use it
netfilter: nf_tables_offload: fix always true policy is unset check
include/net/netfilter/nf_tables.h | 6 ++++++ include/uapi/linux/netfilter_bridge/ebtables.h | 6 +++--- net/netfilter/nf_tables_api.c | 25 ++++++++++++++++++++++--- net/netfilter/nf_tables_offload.c | 2 +- net/netfilter/nft_flow_offload.c | 19 +++++++++++++++++++ net/netfilter/nft_lookup.c | 3 --- usr/include/Makefile | 1 - 7 files changed, 51 insertions(+), 11 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 3/5 netfilter: nf_tables: allow lookups in dynamic sets
From: Florian Westphal <[email protected]>
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.
--- net/netfilter/nf_tables_api.c | 7 +++++-- net/netfilter/nft_lookup.c | 3 --- 2 files changed, 5 insertions(+), 5 deletions(-)
net/netfilter/nf_tables_api.c +5 -2
@@ -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 ; }
net/netfilter/nft_lookup.c +0 -3
@@ -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 )
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 5/5 netfilter: nf_tables: bogus EBUSY when deleting flowtable after flush
In reply to Pablo Neira AyusoFrom: Laura Garcia Liebana <[email protected]>
The deletion of a flowtable after a flush in the same transaction results in EBUSY. This patch adds an activation and deactivation of flowtables in order to update the _use_ counter.
--- include/net/netfilter/nf_tables.h | 4 ++++ net/netfilter/nf_tables_api.c | 16 ++++++++++++++++ net/netfilter/nft_flow_offload.c | 19 +++++++++++++++++++ 3 files changed, 39 insertions(+)
include/net/netfilter/nf_tables.h +4 -0
@@ -1183,6 +1183,10 @@ struct nft_flowtable *nft_flowtable_lookup(const struct nft_table *table,const struct nlattr *nla, u8 genmask); +void nf_tables_deactivate_flowtable (const struct nft_ctx *ctx, +struct nft_flowtable *flowtable, +enum nft_trans_phase phase); +void nft_register_flowtable_type (struct nf_flowtable_type *type);void nft_unregister_flowtable_type (struct nf_flowtable_type *type);
net/netfilter/nf_tables_api.c +16 -0
@@ -5598,6 +5598,22 @@ struct nft_flowtable *nft_flowtable_lookup(const struct nft_table *table, }EXPORT_SYMBOL_GPL (nft_flowtable_lookup); +void nf_tables_deactivate_flowtable (const struct nft_ctx *ctx, +struct nft_flowtable *flowtable, +enum nft_trans_phase phase) +{ +switch (phase) { +case NFT_TRANS_PREPARE : +case NFT_TRANS_ABORT : +case NFT_TRANS_RELEASE : + flowtable->use--; +/* fall through */ +default : +return ; + } +} +EXPORT_SYMBOL_GPL (nf_tables_deactivate_flowtable); +static struct nft_flowtable *nft_flowtable_lookup_byhandle (const struct nft_table *table,const struct nlattr *nla,u8 genmask)
net/netfilter/nft_flow_offload.c +19 -0
@@ -177,6 +177,23 @@ static int nft_flow_offload_init(const struct nft_ctx *ctx,return nf_ct_netns_get (ctx->net, ctx->family); } +static void nft_flow_offload_deactivate (const struct nft_ctx *ctx, +const struct nft_expr *expr, +enum nft_trans_phase phase) +{ +struct nft_flow_offload *priv =nft_expr_priv (expr); + +nf_tables_deactivate_flowtable (ctx, priv->flowtable, phase); +} + +static void nft_flow_offload_activate (const struct nft_ctx *ctx, +const struct nft_expr *expr) +{ +struct nft_flow_offload *priv =nft_expr_priv (expr); + + priv->flowtable->use++; +} +static void nft_flow_offload_destroy (const struct nft_ctx *ctx,const struct nft_expr *expr) {
@@ -205,6 +222,8 @@ static const struct nft_expr_ops nft_flow_offload_ops = { .size = NFT_EXPR_SIZE(sizeof(struct nft_flow_offload)), .eval = nft_flow_offload_eval, .init = nft_flow_offload_init, + .activate = nft_flow_offload_activate, + .deactivate = nft_flow_offload_deactivate, .destroy = nft_flow_offload_destroy, .validate = nft_flow_offload_validate, .dump = nft_flow_offload_dump,
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 4/5 netfilter: ebtables: use __u8 instead of uint8_t in uapi header
In reply to Pablo Neira AyusoFrom: Masahiro Yamada <[email protected]>
When CONFIG_UAPI_HEADER_TEST=y, exported headers are compile-tested to make sure they can be included from user-space.
Currently, linux/netfilter_bridge/ebtables.h is excluded from the test coverage. To make it join the compile-test, we need to fix the build errors attached below.
For a case like this, we decided to use __u{8,16,32,64} variable types in this discussion:
https://lkml.org/lkml/2019/6/5/18
Build log:
CC usr/include/linux/netfilter_bridge/ebtables.h.s
In file included from <command-line>:32:0:./usr/include/linux/netfilter_bridge/ebtables.h:126:4: error: unknown type name ‘uint8_t’
uint8_t revision;
^~~~~~~
./usr/include/linux/netfilter_bridge/ebtables.h:139:4: error: unknown type name ‘uint8_t’
uint8_t revision;
^~~~~~~
./usr/include/linux/netfilter_bridge/ebtables.h:152:4: error: unknown type name ‘uint8_t’
uint8_t revision;
^~~~~~~--- include/uapi/linux/netfilter_bridge/ebtables.h | 6 +++--- usr/include/Makefile | 1 - 2 files changed, 3 insertions(+), 4 deletions(-)
include/uapi/linux/netfilter_bridge/ebtables.h +3 -3
@@ -123,7 +123,7 @@ struct ebt_entry_match {union {struct {char name[EBT_EXTENSION_MAXNAMELEN ]; -uint8_t revision; +__u8 revision; };struct xt_match *match; } u;
@@ -136,7 +136,7 @@ struct ebt_entry_watcher {union {struct {char name[EBT_EXTENSION_MAXNAMELEN ]; -uint8_t revision; +__u8 revision; };struct xt_target *watcher; } u;
@@ -149,7 +149,7 @@ struct ebt_entry_target {union {struct {char name[EBT_EXTENSION_MAXNAMELEN ]; -uint8_t revision; +__u8 revision; };struct xt_target *target; } u;
usr/include/Makefile +0 -1
@@ -38,7 +38,6 @@ header-test- += linux/ivtv.h header-test- += linux/jffs2.h header-test- += linux/kexec.h header-test- += linux/matroxfb.h -header-test- += linux/netfilter_bridge/ebtables.h header-test- += linux/netfilter_ipv4/ipt_LOG.h header-test- += linux/netfilter_ipv6/ip6t_LOG.h header-test- += linux/nfc.h
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 2/5 netfilter: nf_tables_offload: fix always true policy is unset check
In reply to Pablo Neira AyusoNew smatch warnings:net/netfilter/nf_tables_offload.c:316 nft_flow_offload_chain() warn: always true condition '(policy != -1) => (0-255 != (-1))'
--- net/netfilter/nf_tables_offload.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_tables_offload.c +1 -1
@@ -313,7 +313,7 @@ static int nft_flow_offload_chain(struct nft_chain *chain, policy = ppolicy ? *ppolicy : basechain->policy;/* Only default policy to accept is supported for now. */ -if (cmd ==FLOW_BLOCK_BIND && policy !=-1 && policy !=NF_ACCEPT ) +if (cmd ==FLOW_BLOCK_BIND && policy ==NF_DROP )return -EOPNOTSUPP ;if (dev->netdev_ops->ndo_setup_tc)
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 1/5 netfilter: nf_tables: add NFT_CHAIN_POLICY_UNSET and use it
In reply to Pablo Neira AyusoDefault policy is defined as a unsigned 8-bit field, do not use a negative value to leave it unset, use this new NFT_CHAIN_POLICY_UNSET instead.
--- include/net/netfilter/nf_tables.h | 2 ++ net/netfilter/nf_tables_api.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
include/net/netfilter/nf_tables.h +2 -0
@@ -889,6 +889,8 @@ enum nft_chain_flags { NFT_CHAIN_HW_OFFLOAD = 0x2, }; +#define NFT_CHAIN_POLICY_UNSET U8_MAX +/** * struct nft_chain - nf_tables chain *
net/netfilter/nf_tables_api.c +1 -1
@@ -1715,7 +1715,7 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask, goto err2; } -nft_trans_chain_policy (trans) =-1 ; +nft_trans_chain_policy (trans) =NFT_CHAIN_POLICY_UNSET ;if (nft_is_base_chain (chain))nft_trans_chain_policy (trans) = policy;
Signature · 1 line
2.11.0
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Wed, 25 Sep 2019 22:29:58 +0200
Quoted 11 lines
The following patchset contains Netfilter fixes for net:
1) Add
NFT_CHAIN_POLICY_UNSETto replace hardcoded -1 to specify that the chain policy is unset. The chain policy field is actually defined as an 8-bit unsigned integer.2) Remove always true condition reported by smatch in chain policy check.
3) Fix element lookup on dynamic sets, from Florian Westphal.
Quoted 8 lines
4) Use
__u8in ebtables uapi header, from Masahiro Yamada.5) Bogus EBUSY when removing flowtable after chain flush, from Laura Garcia Liebana.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
Pulled, thanks Pablo.