Skip to content

Commit d694b75

Browse files
committed
netfilter: nft_compat: restrict match/target protocol to u16
xt_check_{match,target} expects u16, but NFTA_RULE_COMPAT_PROTO is u32. NLA_POLICY_MAX(NLA_BE32, 65535) cannot be used because .max in nla_policy is s16, see 3e48be0 ("netlink: add attribute range validation to policy"). Fixes: 0ca743a ("netfilter: nf_tables: add compatibility layer for x_tables") Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 292781c commit d694b75

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

net/netfilter/nft_compat.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ static const struct nla_policy nft_rule_compat_policy[NFTA_RULE_COMPAT_MAX + 1]
200200
static int nft_parse_compat(const struct nlattr *attr, u16 *proto, bool *inv)
201201
{
202202
struct nlattr *tb[NFTA_RULE_COMPAT_MAX+1];
203+
u32 l4proto;
203204
u32 flags;
204205
int err;
205206

@@ -218,7 +219,12 @@ static int nft_parse_compat(const struct nlattr *attr, u16 *proto, bool *inv)
218219
if (flags & NFT_RULE_COMPAT_F_INV)
219220
*inv = true;
220221

221-
*proto = ntohl(nla_get_be32(tb[NFTA_RULE_COMPAT_PROTO]));
222+
l4proto = ntohl(nla_get_be32(tb[NFTA_RULE_COMPAT_PROTO]));
223+
if (l4proto > U16_MAX)
224+
return -EINVAL;
225+
226+
*proto = l4proto;
227+
222228
return 0;
223229
}
224230

0 commit comments

Comments
 (0)