Skip to content

Commit 71df14b

Browse files
committed
netfilter: nf_tables: missing sanitization in data from userspace
Do not assume userspace always sends us NFT_DATA_VALUE for bitwise and cmp expressions. Although NFT_DATA_VERDICT does not make any sense, it is still possible to handcraft a netlink message using this incorrect data type. Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent fa80360 commit 71df14b

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

net/netfilter/nft_bitwise.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,26 @@ static int nft_bitwise_init(const struct nft_ctx *ctx,
8383
tb[NFTA_BITWISE_MASK]);
8484
if (err < 0)
8585
return err;
86-
if (d1.len != priv->len)
87-
return -EINVAL;
86+
if (d1.len != priv->len) {
87+
err = -EINVAL;
88+
goto err1;
89+
}
8890

8991
err = nft_data_init(NULL, &priv->xor, sizeof(priv->xor), &d2,
9092
tb[NFTA_BITWISE_XOR]);
9193
if (err < 0)
92-
return err;
93-
if (d2.len != priv->len)
94-
return -EINVAL;
94+
goto err1;
95+
if (d2.len != priv->len) {
96+
err = -EINVAL;
97+
goto err2;
98+
}
9599

96100
return 0;
101+
err2:
102+
nft_data_uninit(&priv->xor, d2.type);
103+
err1:
104+
nft_data_uninit(&priv->mask, d1.type);
105+
return err;
97106
}
98107

99108
static int nft_bitwise_dump(struct sk_buff *skb, const struct nft_expr *expr)

net/netfilter/nft_cmp.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,18 @@ nft_cmp_select_ops(const struct nft_ctx *ctx, const struct nlattr * const tb[])
201201
if (err < 0)
202202
return ERR_PTR(err);
203203

204+
if (desc.type != NFT_DATA_VALUE) {
205+
err = -EINVAL;
206+
goto err1;
207+
}
208+
204209
if (desc.len <= sizeof(u32) && op == NFT_CMP_EQ)
205210
return &nft_cmp_fast_ops;
206-
else
207-
return &nft_cmp_ops;
211+
212+
return &nft_cmp_ops;
213+
err1:
214+
nft_data_uninit(&data, desc.type);
215+
return ERR_PTR(-EINVAL);
208216
}
209217

210218
struct nft_expr_type nft_cmp_type __read_mostly = {

0 commit comments

Comments
 (0)