Commit 1321a6af authored by Florian Westphal's avatar Florian Westphal Committed by Pablo Neira Ayuso

netfilter: nft_xfrm: use state family, not hook one

Eyal says:
  doesn't the use of nft_pf(pkt) in this context limit the matching of
  encapsulated packets to the same family?

  IIUC when an e.g. IPv6-in-IPv4 packet is matched, the nft_pf(pkt) will
  be the decapsulated packet family - IPv6 - whereas the state may be
  IPv4. So this check would not allow matching the 'underlay' address in
  such cases.

  I know this was a limitation in xt_policy. but is this intentional in
  this matcher? or is it possible to use state->props.family when
  validating the match instead of nft_pf(pkt)?

Userspace already tells us which address family it expects to match, so
we can just use the real state family rather than the hook family.
so change it as suggested above.
Reported-by: default avatarEyal Birger <eyal.birger@gmail.com>
Suggested-by: default avatarEyal Birger <eyal.birger@gmail.com>
Fixes: 6c472602 ("netfilter: nf_tables: add xfrm expression")
Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent a218dc82
...@@ -118,12 +118,13 @@ static bool xfrm_state_addr_ok(enum nft_xfrm_keys k, u8 family, u8 mode) ...@@ -118,12 +118,13 @@ static bool xfrm_state_addr_ok(enum nft_xfrm_keys k, u8 family, u8 mode)
static void nft_xfrm_state_get_key(const struct nft_xfrm *priv, static void nft_xfrm_state_get_key(const struct nft_xfrm *priv,
struct nft_regs *regs, struct nft_regs *regs,
const struct xfrm_state *state, const struct xfrm_state *state)
u8 family)
{ {
u32 *dest = &regs->data[priv->dreg]; u32 *dest = &regs->data[priv->dreg];
if (!xfrm_state_addr_ok(priv->key, family, state->props.mode)) { if (!xfrm_state_addr_ok(priv->key,
state->props.family,
state->props.mode)) {
regs->verdict.code = NFT_BREAK; regs->verdict.code = NFT_BREAK;
return; return;
} }
...@@ -169,7 +170,7 @@ static void nft_xfrm_get_eval_in(const struct nft_xfrm *priv, ...@@ -169,7 +170,7 @@ static void nft_xfrm_get_eval_in(const struct nft_xfrm *priv,
} }
state = sp->xvec[priv->spnum]; state = sp->xvec[priv->spnum];
nft_xfrm_state_get_key(priv, regs, state, nft_pf(pkt)); nft_xfrm_state_get_key(priv, regs, state);
} }
static void nft_xfrm_get_eval_out(const struct nft_xfrm *priv, static void nft_xfrm_get_eval_out(const struct nft_xfrm *priv,
...@@ -184,7 +185,7 @@ static void nft_xfrm_get_eval_out(const struct nft_xfrm *priv, ...@@ -184,7 +185,7 @@ static void nft_xfrm_get_eval_out(const struct nft_xfrm *priv,
if (i < priv->spnum) if (i < priv->spnum)
continue; continue;
nft_xfrm_state_get_key(priv, regs, dst->xfrm, nft_pf(pkt)); nft_xfrm_state_get_key(priv, regs, dst->xfrm);
return; return;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment