netfilter: nft_compat: check match/targetinfo attr size
Subsystems (2)
Florian Westphal
maintainerPATCH 1/1 netfilter: nft_compat: check match/targetinfo attr size
We copy accoring to ->target|matchsize, so check that the netlink attribute (which can include padding and might be larger) contains enough data.
--- net/netfilter/nft_compat.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/netfilter/nft_compat.c +6 -0
@@ -660,6 +660,9 @@ nft_match_select_ops(const struct nft_ctx *ctx,if (IS_ERR (match))return ERR_PTR (-ENOENT ); +if (match->matchsize >nla_len (tb[NFTA_MATCH_INFO ])) +return ERR_PTR (-EINVAL ); +/* This is the first time we use this match, allocate operations */ nft_match =kzalloc (sizeof (struct nft_xt ),GFP_KERNEL );if (nft_match ==NULL )
@@ -740,6 +743,9 @@ nft_target_select_ops(const struct nft_ctx *ctx,if (IS_ERR (target))return ERR_PTR (-ENOENT ); +if (target->targetsize >nla_len (tb[NFTA_TARGET_INFO ])) +return ERR_PTR (-EINVAL ); +/* This is the first time we use this target, allocate operations */ nft_target =kzalloc (sizeof (struct nft_xt ),GFP_KERNEL );if (nft_target ==NULL )
Signature · 1 line
2.4.10
Pablo Neira Ayuso
maintainerQuoted 5 lines · Florian Westphal
We copy accoring to ->target|matchsize, so check that the netlink attribute (which can include padding and might be larger) contains enough data.
Reported-by Julia Lawall <[email protected]>Signed-off-by Florian Westphal <[email protected]>
I think xt_check_match() and xt_check_target() already validate this for us.
Florian Westphal
maintainerQuoted 9 lines · Pablo Neira Ayuso
Quoted 5 lines · Florian Westphal
We copy accoring to ->target|matchsize, so check that the netlink attribute (which can include padding and might be larger) contains enough data.
Reported-by Julia Lawall <[email protected]>Signed-off-by Florian Westphal <[email protected]>I think
xt_check_match()andxt_check_target()already validate this for us.
But AFAICS we copy before this:
nft_target_init:
size = XT_ALIGN(nla_len(tb[NFTA_TARGET_INFO]));
...target_compat_from_user(target, nla_data(tb[NFTA_TARGET_INFO]), info);
-> memcpy(out, in, t->targetsize);
xt_check_target(&par, size, proto, inv); // checks size vs. targetsize
'target' is sized based on target->targetsize innft_target_select_ops().
So if tb[NFTA_TARGET_INFO] is != t->targetsize we might copy more data than whats in 'in', no?
Pablo Neira Ayuso
maintainerQuoted 20 lines · Florian Westphal
Quoted 9 lines · Pablo Neira Ayuso
Quoted 5 lines · Florian Westphal
We copy accoring to ->target|matchsize, so check that the netlink attribute (which can include padding and might be larger) contains enough data.
Reported-by Julia Lawall <[email protected]>Signed-off-by Florian Westphal <[email protected]>I think
xt_check_match()andxt_check_target()already validate this for us.But AFAICS we copy before this:
nft_target_init:size = XT_ALIGN(nla_len(tb[NFTA_TARGET_INFO]));
...target_compat_from_user(target, nla_data(tb[NFTA_TARGET_INFO]), info); -> memcpy(out, in, t->targetsize);
Quoted 7 lines
xt_check_target(&par, size, proto, inv); // checks size vs. targetsize'target' is sized based on
target->targetsizeinnft_target_select_ops().So if tb[NFTA_TARGET_INFO] is !=
t->targetsizewe might copy more data than whats in 'in', no?
Right, if the user passes less information, then we would be copying more than what we have.
I'm going to place this in the nf-next, thanks Florian.