From: Pan Bian Date: Thu, 1 Dec 2016 02:04:43 +0000 (+0800) Subject: crypto: algif_skcipher - set error code when kcalloc fails X-Git-Tag: v4.10-rc2~6^2~15 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e2c1b82330bcd77ffeb6dc5a18a4c6ce8d3e1fd3;p=platform%2Fkernel%2Flinux-exynos.git crypto: algif_skcipher - set error code when kcalloc fails Fix bug https://bugzilla.kernel.org/show_bug.cgi?id=188521. In function skcipher_recvmsg_async(), variable err takes the return value, and its value should be negative on failures. Because variable err may be reassigned and checked before calling kcalloc(), its value may be 0 (indicates no error) even if kcalloc() fails. This patch fixes the bug by explicitly assigning -ENOMEM to err when kcalloc() returns a NULL pointer. Signed-off-by: Pan Bian Signed-off-by: Herbert Xu --- diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c index 28556fc..bfb0a1a 100644 --- a/crypto/algif_skcipher.c +++ b/crypto/algif_skcipher.c @@ -566,8 +566,10 @@ static int skcipher_recvmsg_async(struct socket *sock, struct msghdr *msg, * need to expand */ tmp = kcalloc(tx_nents * 2, sizeof(*tmp), GFP_KERNEL); - if (!tmp) + if (!tmp) { + err = -ENOMEM; goto free; + } sg_init_table(tmp, tx_nents * 2); for (x = 0; x < tx_nents; x++)