History

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.

Laura Garcia Liebana committed 10 years ago

Commit 4da449a1 parent aa0c2c61 file · +9 −2Browse files

Unified · Split

net/netfilter/nft_exthdr.c+9−2
@@ -59,6 +59,7 @@ static int nft_exthdr_init(const struct nft_ctx *ctx, · 58 unmodified lines
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 ||
@@ -66,9 +67,15 @@ static int nft_exthdr_init(const struct nft_ctx *ctx, · 1 unmodified line
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,