From: Steffen Klassert Date: Fri, 5 May 2017 05:40:42 +0000 (+0200) Subject: af_key: Fix slab-out-of-bounds in pfkey_compile_policy. X-Git-Tag: v4.14-rc1~841^2~23^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d90c902449a7561f1b1d58ba5a0d11728ce8b0b2;p=platform%2Fkernel%2Flinux-rpi.git af_key: Fix slab-out-of-bounds in pfkey_compile_policy. The sadb_x_sec_len is stored in the unit 'byte divided by eight'. So we have to multiply this value by eight before we can do size checks. Otherwise we may get a slab-out-of-bounds when we memcpy the user sec_ctx. Fixes: df71837d502 ("[LSM-IPSec]: Security association restriction.") Reported-by: Andrey Konovalov Tested-by: Andrey Konovalov Signed-off-by: Steffen Klassert --- diff --git a/net/key/af_key.c b/net/key/af_key.c index c1950bb..512dc43 100644 --- a/net/key/af_key.c +++ b/net/key/af_key.c @@ -3285,7 +3285,7 @@ static struct xfrm_policy *pfkey_compile_policy(struct sock *sk, int opt, p += pol->sadb_x_policy_len*8; sec_ctx = (struct sadb_x_sec_ctx *)p; if (len < pol->sadb_x_policy_len*8 + - sec_ctx->sadb_x_sec_len) { + sec_ctx->sadb_x_sec_len*8) { *dir = -EINVAL; goto out; }