Skip to content

Commit 33d1c01

Browse files
Dan Carpenterummakynes
authored andcommitted
netfilter: nf_tables: prevent shift wrap in nft_chain_parse_hook()
I believe that "hook->num" can be up to UINT_MAX. Shifting more than 31 bits would is undefined in C but in practice it would lead to shift wrapping. That would lead to an array overflow in nf_tables_addchain(): ops->hook = hook.type->hooks[ops->hooknum]; Fixes: fe19c04 ("netfilter: nf_tables: remove nhooks field from struct nft_af_info") Signed-off-by: Dan Carpenter <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 3c79107 commit 33d1c01

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

net/netfilter/nf_tables_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1545,7 +1545,7 @@ static int nft_chain_parse_hook(struct net *net,
15451545
if (IS_ERR(type))
15461546
return PTR_ERR(type);
15471547
}
1548-
if (!(type->hook_mask & (1 << hook->num)))
1548+
if (hook->num > NF_MAX_HOOKS || !(type->hook_mask & (1 << hook->num)))
15491549
return -EOPNOTSUPP;
15501550

15511551
if (type->type == NFT_CHAIN_T_NAT &&

0 commit comments

Comments
 (0)