Skip to contentSkip to conversation

netfilter: nf_tables_netdev: set nft_pktinfo field for non-IP traffic

PATCH In review Pablo Neira Ayuso 1 participant 2 messages Aug 17, 2016

Subsystems (2)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 netfilter: nf_tables_netdev: set nft_pktinfo field for non-IP traffic

For non-IP traffic seen from the netdev family, set nft_pktinfo fields other the value of these fields is garbage.

This patch sets transport protocol number to IPPROTO_RAW since 0 means IPPROTO_IP, then zero transport and fragment offsets.

---
 include/net/netfilter/nf_tables.h | 10 ++++++++++
 net/netfilter/nf_tables_netdev.c  |  2 +-
 2 files changed, 11 insertions(+), 1 deletion(-)
include/net/netfilter/nf_tables.h +10 -0
index f2f1339..688a78b 100644
@@ -36,6 +36,16 @@ static inline void nft_set_pktinfo(struct nft_pktinfo *pkt,
 	pkt->pf = pkt->xt.family = state->pf;
 }
 
+static inline void nft_set_pktinfo_unspec(struct nft_pktinfo *pkt,
+					  struct sk_buff *skb,
+					  const struct nf_hook_state *state)
+{
+	nft_set_pktinfo(pkt, skb, state);
+	pkt->tprot = IPPROTO_RAW;
+	pkt->xt.thoff = 0;
+	pkt->xt.fragoff = 0;
+}
+
 /**
  * 	struct nft_verdict - nf_tables verdict
  *
net/netfilter/nf_tables_netdev.c +1 -1
index 5eefe4a..2556986 100644
@@ -102,7 +102,7 @@ nft_do_chain_netdev(void *priv, struct sk_buff *skb,
 		nft_netdev_set_pktinfo_ipv6(&pkt, skb, state);
 		break;
 	default:
-		nft_set_pktinfo(&pkt, skb, state);
+		nft_set_pktinfo_unspec(&pkt, skb, state);
 		break;
 	}
 
Signature · 1 line
2.1.4
author maintainer
#1 lore raw
Quoted 2 lines · Pablo Neira Ayuso

For non-IP traffic seen from the netdev family, set nft_pktinfo fields other the value of these fields is garbage.

Will send a v2. It seems we can leave unset field in bridge too for non-IP traffic.

This should be a problem since nft doesn't generate bytecode using expression that require this fields.

But given that we assume the nftables VM can be used rawly by anyone, entirely bypassing libraries and nft, it is good to have this sanitized.