Commit 1cf11e7c authored by Florian Westphal's avatar Florian Westphal Committed by Greg Kroah-Hartman

netfilter: nft_compat: ebtables 'nat' table is normal chain type

[ Upstream commit e4844c9c ]

Unlike ip(6)tables, the ebtables nat table has no special properties.
This bug causes 'ebtables -A' to fail when using a target such as
'snat' (ebt_snat target sets ".table = "nat"').  Targets that have
no table restrictions work fine.
Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 2f6bf791
...@@ -54,9 +54,11 @@ static bool nft_xt_put(struct nft_xt *xt) ...@@ -54,9 +54,11 @@ static bool nft_xt_put(struct nft_xt *xt)
return false; return false;
} }
static int nft_compat_chain_validate_dependency(const char *tablename, static int nft_compat_chain_validate_dependency(const struct nft_ctx *ctx,
const struct nft_chain *chain) const char *tablename)
{ {
enum nft_chain_types type = NFT_CHAIN_T_DEFAULT;
const struct nft_chain *chain = ctx->chain;
const struct nft_base_chain *basechain; const struct nft_base_chain *basechain;
if (!tablename || if (!tablename ||
...@@ -64,9 +66,12 @@ static int nft_compat_chain_validate_dependency(const char *tablename, ...@@ -64,9 +66,12 @@ static int nft_compat_chain_validate_dependency(const char *tablename,
return 0; return 0;
basechain = nft_base_chain(chain); basechain = nft_base_chain(chain);
if (strcmp(tablename, "nat") == 0 && if (strcmp(tablename, "nat") == 0) {
basechain->type->type != NFT_CHAIN_T_NAT) if (ctx->family != NFPROTO_BRIDGE)
type = NFT_CHAIN_T_NAT;
if (basechain->type->type != type)
return -EINVAL; return -EINVAL;
}
return 0; return 0;
} }
...@@ -323,8 +328,7 @@ static int nft_target_validate(const struct nft_ctx *ctx, ...@@ -323,8 +328,7 @@ static int nft_target_validate(const struct nft_ctx *ctx,
if (target->hooks && !(hook_mask & target->hooks)) if (target->hooks && !(hook_mask & target->hooks))
return -EINVAL; return -EINVAL;
ret = nft_compat_chain_validate_dependency(target->table, ret = nft_compat_chain_validate_dependency(ctx, target->table);
ctx->chain);
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
...@@ -570,8 +574,7 @@ static int nft_match_validate(const struct nft_ctx *ctx, ...@@ -570,8 +574,7 @@ static int nft_match_validate(const struct nft_ctx *ctx,
if (match->hooks && !(hook_mask & match->hooks)) if (match->hooks && !(hook_mask & match->hooks))
return -EINVAL; return -EINVAL;
ret = nft_compat_chain_validate_dependency(match->table, ret = nft_compat_chain_validate_dependency(ctx, match->table);
ctx->chain);
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
......
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