All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Bluetooth: add a check for kmalloc() failure
@ 2017-05-02  9:29 ` Dan Carpenter
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2017-05-02  9:29 UTC (permalink / raw)
  To: Marcel Holtmann, Salvatore Benedetto
  Cc: Gustavo Padovan, Johan Hedberg, David S. Miller, linux-bluetooth,
	kernel-janitors

We should check to see if this kmalloc() fails.

Fixes: e7c404c96c74 ("Bluetooth: allocate data for kpp on heap")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/net/bluetooth/ecdh_helper.c b/net/bluetooth/ecdh_helper.c
index 80184476ff74..c8535845813d 100644
--- a/net/bluetooth/ecdh_helper.c
+++ b/net/bluetooth/ecdh_helper.c
@@ -59,11 +59,15 @@ bool compute_ecdh_secret(const u8 public_key[64], const u8 private_key[32],
 	struct ecdh p;
 	struct ecdh_completion result;
 	struct scatterlist src, dst;
-	u8 *tmp = kmalloc(64, GFP_KERNEL);
+	u8 *tmp;
 	u8 *buf;
 	unsigned int buf_len;
 	int err = -ENOMEM;
 
+	tmp = kmalloc(64, GFP_KERNEL);
+	if (!tmp)
+		goto out;
+
 	tfm = crypto_alloc_kpp("ecdh", CRYPTO_ALG_INTERNAL, 0);
 	if (IS_ERR(tfm)) {
 		pr_err("alg: kpp: Failed to load tfm for kpp: %ld\n",
@@ -130,6 +134,7 @@ bool compute_ecdh_secret(const u8 public_key[64], const u8 private_key[32],
 	crypto_free_kpp(tfm);
 free_tmp:
 	kfree(tmp);
+out:
 	return (err == 0);
 }
 

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-05-02 18:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-02  9:29 [PATCH] Bluetooth: add a check for kmalloc() failure Dan Carpenter
2017-05-02  9:29 ` Dan Carpenter
2017-05-02 17:58 ` Marcel Holtmann
2017-05-02 17:58   ` Marcel Holtmann
2017-05-02 18:34   ` Dan Carpenter
2017-05-02 18:34     ` Dan Carpenter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.