* [nf PATCH] net: nf_tables: Make nft_meta expression more robust
@ 2019-07-18 3:37 Phil Sutter
2019-07-18 18:10 ` Pablo Neira Ayuso
0 siblings, 1 reply; 3+ messages in thread
From: Phil Sutter @ 2019-07-18 3:37 UTC (permalink / raw)
To: Pablo Neira Ayuso; +Cc: Florian Westphal, netfilter-devel
nft_meta_get_eval()'s tendency to bail out setting NFT_BREAK verdict in
situations where required data is missing breaks inverted checks
like e.g.:
| meta iifname != eth0 accept
This rule will never match if there is no input interface (or it is not
known) which is not intuitive and, what's worse, breaks consistency of
iptables-nft with iptables-legacy.
Fix this by falling back to placing a value in dreg which never matches
(avoiding accidental matches):
{I,O}IF:
Use invalid ifindex value zero.
{I,O}IFNAME, {I,O}IFKIND:
Use an empty string which is neither a valid interface name nor
kind.
{I,O}IFTYPE:
Use ARPHRD_VOID (0xFFFF).
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
net/netfilter/nft_meta.c | 45 +++++++++++++++++-----------------------
1 file changed, 19 insertions(+), 26 deletions(-)
diff --git a/net/netfilter/nft_meta.c b/net/netfilter/nft_meta.c
index 76866f77e3435..ee3b54692cc7e 100644
--- a/net/netfilter/nft_meta.c
+++ b/net/netfilter/nft_meta.c
@@ -11,6 +11,7 @@
#include <linux/netlink.h>
#include <linux/netfilter.h>
#include <linux/netfilter/nf_tables.h>
+#include <linux/if_arp.h>
#include <linux/in.h>
#include <linux/ip.h>
#include <linux/ipv6.h>
@@ -60,34 +61,22 @@ void nft_meta_get_eval(const struct nft_expr *expr,
*dest = skb->mark;
break;
case NFT_META_IIF:
- if (in == NULL)
- goto err;
- *dest = in->ifindex;
+ *dest = in ? in->ifindex : 0;
break;
case NFT_META_OIF:
- if (out == NULL)
- goto err;
- *dest = out->ifindex;
+ *dest = out ? out->ifindex : 0;
break;
case NFT_META_IIFNAME:
- if (in == NULL)
- goto err;
- strncpy((char *)dest, in->name, IFNAMSIZ);
+ strncpy((char *)dest, in ? in->name : "", IFNAMSIZ);
break;
case NFT_META_OIFNAME:
- if (out == NULL)
- goto err;
- strncpy((char *)dest, out->name, IFNAMSIZ);
+ strncpy((char *)dest, out ? out->name : "", IFNAMSIZ);
break;
case NFT_META_IIFTYPE:
- if (in == NULL)
- goto err;
- nft_reg_store16(dest, in->type);
+ nft_reg_store16(dest, in ? in->type : ARPHRD_VOID);
break;
case NFT_META_OIFTYPE:
- if (out == NULL)
- goto err;
- nft_reg_store16(dest, out->type);
+ nft_reg_store16(dest, out ? out->type : ARPHRD_VOID);
break;
case NFT_META_SKUID:
sk = skb_to_full_sk(skb);
@@ -216,16 +205,20 @@ void nft_meta_get_eval(const struct nft_expr *expr,
nft_reg_store8(dest, secpath_exists(skb));
break;
#endif
- case NFT_META_IIFKIND:
- if (in == NULL || in->rtnl_link_ops == NULL)
- goto err;
- strncpy((char *)dest, in->rtnl_link_ops->kind, IFNAMSIZ);
+ case NFT_META_IIFKIND: {
+ const struct rtnl_link_ops *rl_ops =
+ in ? in->rtnl_link_ops : NULL;
+
+ strncpy((char *)dest, rl_ops ? rl_ops->kind : "", IFNAMSIZ);
break;
- case NFT_META_OIFKIND:
- if (out == NULL || out->rtnl_link_ops == NULL)
- goto err;
- strncpy((char *)dest, out->rtnl_link_ops->kind, IFNAMSIZ);
+ }
+ case NFT_META_OIFKIND: {
+ const struct rtnl_link_ops *rl_ops =
+ out ? out->rtnl_link_ops : NULL;
+
+ strncpy((char *)dest, rl_ops ? rl_ops->kind : "", IFNAMSIZ);
break;
+ }
default:
WARN_ON(1);
goto err;
--
2.22.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [nf PATCH] net: nf_tables: Make nft_meta expression more robust
2019-07-18 3:37 [nf PATCH] net: nf_tables: Make nft_meta expression more robust Phil Sutter
@ 2019-07-18 18:10 ` Pablo Neira Ayuso
2019-07-18 18:12 ` Pablo Neira Ayuso
0 siblings, 1 reply; 3+ messages in thread
From: Pablo Neira Ayuso @ 2019-07-18 18:10 UTC (permalink / raw)
To: Phil Sutter; +Cc: Florian Westphal, netfilter-devel
On Thu, Jul 18, 2019 at 05:37:29AM +0200, Phil Sutter wrote:
> nft_meta_get_eval()'s tendency to bail out setting NFT_BREAK verdict in
> situations where required data is missing breaks inverted checks
> like e.g.:
>
> | meta iifname != eth0 accept
>
> This rule will never match if there is no input interface (or it is not
> known) which is not intuitive and, what's worse, breaks consistency of
> iptables-nft with iptables-legacy.
>
> Fix this by falling back to placing a value in dreg which never matches
> (avoiding accidental matches):
>
> {I,O}IF:
> Use invalid ifindex value zero.
>
> {I,O}IFNAME, {I,O}IFKIND:
> Use an empty string which is neither a valid interface name nor
> kind.
>
> {I,O}IFTYPE:
> Use ARPHRD_VOID (0xFFFF).
>
> Signed-off-by: Phil Sutter <phil@nwl.cc>
> ---
> net/netfilter/nft_meta.c | 45 +++++++++++++++++-----------------------
Missing update for:
net/bridge/netfilter/nft_meta_bridge.c
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [nf PATCH] net: nf_tables: Make nft_meta expression more robust
2019-07-18 18:10 ` Pablo Neira Ayuso
@ 2019-07-18 18:12 ` Pablo Neira Ayuso
0 siblings, 0 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2019-07-18 18:12 UTC (permalink / raw)
To: Phil Sutter; +Cc: Florian Westphal, netfilter-devel
On Thu, Jul 18, 2019 at 08:10:34PM +0200, Pablo Neira Ayuso wrote:
> On Thu, Jul 18, 2019 at 05:37:29AM +0200, Phil Sutter wrote:
> > nft_meta_get_eval()'s tendency to bail out setting NFT_BREAK verdict in
> > situations where required data is missing breaks inverted checks
> > like e.g.:
> >
> > | meta iifname != eth0 accept
> >
> > This rule will never match if there is no input interface (or it is not
> > known) which is not intuitive and, what's worse, breaks consistency of
> > iptables-nft with iptables-legacy.
> >
> > Fix this by falling back to placing a value in dreg which never matches
> > (avoiding accidental matches):
> >
> > {I,O}IF:
> > Use invalid ifindex value zero.
> >
> > {I,O}IFNAME, {I,O}IFKIND:
> > Use an empty string which is neither a valid interface name nor
> > kind.
> >
> > {I,O}IFTYPE:
> > Use ARPHRD_VOID (0xFFFF).
> >
> > Signed-off-by: Phil Sutter <phil@nwl.cc>
> > ---
> > net/netfilter/nft_meta.c | 45 +++++++++++++++++-----------------------
>
> Missing update for:
>
> net/bridge/netfilter/nft_meta_bridge.c
While you update this, would you also disentangle the default: case?
default:
goto out;
...
out:
return nft_meta_get_eval(expr, regs, pkt);
not good to use goto like that.
I'd suggest:
default:
nft_meta_get_eval(expr, regs, pkt);
return;
Thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-07-18 18:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-18 3:37 [nf PATCH] net: nf_tables: Make nft_meta expression more robust Phil Sutter
2019-07-18 18:10 ` Pablo Neira Ayuso
2019-07-18 18:12 ` Pablo Neira Ayuso
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.