xfrm: fix uctx len check in verify_sec_ctx_len
authorXin Long <lucien.xin@gmail.com>
Sun, 9 Feb 2020 13:15:29 +0000 (21:15 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 2 Apr 2020 14:34:32 +0000 (16:34 +0200)
commitc91b46394b340ed790d6aed76f0044c1c7838de0
tree937ea324e8dbf9aa2f72caa778c1a98250b709fe
parent1046035d3b8b461194ce693d7f8e33e99f4f4abe
xfrm: fix uctx len check in verify_sec_ctx_len

commit 171d449a028573b2f0acdc7f31ecbb045391b320 upstream.

It's not sufficient to do 'uctx->len != (sizeof(struct xfrm_user_sec_ctx) +
uctx->ctx_len)' check only, as uctx->len may be greater than nla_len(rt),
in which case it will cause slab-out-of-bounds when accessing uctx->ctx_str
later.

This patch is to fix it by return -EINVAL when uctx->len > nla_len(rt).

Fixes: df71837d5024 ("[LSM-IPSec]: Security association restriction.")
Signed-off-by: Xin Long <lucien.xin@gmail.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/xfrm/xfrm_user.c