Skip to content

Commit

Permalink
crypto: algif_skcipher - set error code when kcalloc fails
Browse files Browse the repository at this point in the history
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 <bianpan2016@163.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
  • Loading branch information
Pan Bian authored and Herbert Xu committed Dec 1, 2016
1 parent 37d8468 commit e2c1b82
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion crypto/algif_skcipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down

0 comments on commit e2c1b82

Please sign in to comment.