Skip to content

Commit 4da449a

Browse files
Laura Garcia Liebanaummakynes
authored andcommitted
netfilter: nft_exthdr: Add size check on u8 nft_exthdr attributes
Fix the direct assignment of offset and length attributes included in nft_exthdr structure from u32 data to u8. Signed-off-by: Laura Garcia Liebana <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent aa0c2c6 commit 4da449a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

net/netfilter/nft_exthdr.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,23 @@ static int nft_exthdr_init(const struct nft_ctx *ctx,
5959
const struct nlattr * const tb[])
6060
{
6161
struct nft_exthdr *priv = nft_expr_priv(expr);
62+
u32 offset, len;
6263

6364
if (tb[NFTA_EXTHDR_DREG] == NULL ||
6465
tb[NFTA_EXTHDR_TYPE] == NULL ||
6566
tb[NFTA_EXTHDR_OFFSET] == NULL ||
6667
tb[NFTA_EXTHDR_LEN] == NULL)
6768
return -EINVAL;
6869

70+
offset = ntohl(nla_get_be32(tb[NFTA_EXTHDR_OFFSET]));
71+
len = ntohl(nla_get_be32(tb[NFTA_EXTHDR_LEN]));
72+
73+
if (offset > U8_MAX || len > U8_MAX)
74+
return -ERANGE;
75+
6976
priv->type = nla_get_u8(tb[NFTA_EXTHDR_TYPE]);
70-
priv->offset = ntohl(nla_get_be32(tb[NFTA_EXTHDR_OFFSET]));
71-
priv->len = ntohl(nla_get_be32(tb[NFTA_EXTHDR_LEN]));
77+
priv->offset = offset;
78+
priv->len = len;
7279
priv->dreg = nft_parse_register(tb[NFTA_EXTHDR_DREG]);
7380

7481
return nft_validate_register_store(ctx, priv->dreg, NULL,

0 commit comments

Comments
 (0)