diff options
author | Dan Carpenter <dan.carpenter@oracle.com> | 2019-04-06 01:26:52 -0400 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2019-04-15 01:31:50 -0400 |
commit | 33d1c018179d0a30c39cc5f1682b77867282694b (patch) | |
tree | 72c0d98f9a56f6ec1aa8d47d3ca311baa018b4f4 | |
parent | 3c79107631db1f7fd32cf3f7368e4672004a3010 (diff) |
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: fe19c04ca137 ("netfilter: nf_tables: remove nhooks field from struct nft_af_info")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r-- | net/netfilter/nf_tables_api.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c index ef7772e976cc..1606eaa5ae0d 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c | |||
@@ -1545,7 +1545,7 @@ static int nft_chain_parse_hook(struct net *net, | |||
1545 | if (IS_ERR(type)) | 1545 | if (IS_ERR(type)) |
1546 | return PTR_ERR(type); | 1546 | return PTR_ERR(type); |
1547 | } | 1547 | } |
1548 | if (!(type->hook_mask & (1 << hook->num))) | 1548 | if (hook->num > NF_MAX_HOOKS || !(type->hook_mask & (1 << hook->num))) |
1549 | return -EOPNOTSUPP; | 1549 | return -EOPNOTSUPP; |
1550 | 1550 | ||
1551 | if (type->type == NFT_CHAIN_T_NAT && | 1551 | if (type->type == NFT_CHAIN_T_NAT && |