lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20061009085812.GA6020@localhost>
Date:	Mon, 9 Oct 2006 17:58:12 +0900
From:	akinobu.mita@...il.com (Akinobu Mita)
To:	linux-kernel@...r.kernel.org
Cc:	Herbert Xu <herbert@...dor.apana.org.au>,
	"David S. Miller" <davem@...emloft.net>
Subject: [PATCH 1/2] crypto: fix crypto_alloc_{tfm,base}() return value

crypto_alloc_tfm() and crypto_alloc_base() are suppose to return error code
as pointer on failures. But there are some cases where they return NULL
(for example, crypto_alloc_tfm() returns NULL on kzalloc() failure)

This patch fixes that wrong return value, and also fixes tcrypt so that it can
detect error code correctly.

Cc: Herbert Xu <herbert@...dor.apana.org.au>
Cc: "David S. Miller" <davem@...emloft.net>
Signed-off-by: Akinobu Mita <akinobu.mita@...il.com>

 crypto/api.c    |   47 ++++++++++++++++++++++++++++-------------------
 crypto/tcrypt.c |    5 +++--
 2 files changed, 31 insertions(+), 21 deletions(-)

Index: work-fault-inject/crypto/tcrypt.c
===================================================================
--- work-fault-inject.orig/crypto/tcrypt.c	2006-10-09 15:06:37.000000000 +0900
+++ work-fault-inject/crypto/tcrypt.c	2006-10-09 15:09:00.000000000 +0900
@@ -766,8 +766,9 @@ static void test_deflate(void)
 	tv = (void *)tvmem;
 
 	tfm = crypto_alloc_tfm("deflate", 0);
-	if (tfm == NULL) {
-		printk("failed to load transform for deflate\n");
+	if (IS_ERR(tfm)) {
+		printk("failed to load transform for deflate: %ld\n",
+				PTR_ERR(tfm));
 		return;
 	}
 
Index: work-fault-inject/crypto/api.c
===================================================================
--- work-fault-inject.orig/crypto/api.c	2006-10-09 15:06:37.000000000 +0900
+++ work-fault-inject/crypto/api.c	2006-10-09 15:09:00.000000000 +0900
@@ -331,7 +331,7 @@ struct crypto_tfm *__crypto_alloc_tfm(st
 	tfm_size = sizeof(*tfm) + crypto_ctxsize(alg, flags);
 	tfm = kzalloc(tfm_size, GFP_KERNEL);
 	if (tfm == NULL)
-		goto out;
+		goto out_err;
 
 	tfm->__crt_alg = alg;
 
@@ -355,6 +355,7 @@ cra_init_failed:
 	crypto_exit_ops(tfm);
 out_free_tfm:
 	kfree(tfm);
+out_err:
 	tfm = ERR_PTR(err);
 out:
 	return tfm;
@@ -363,27 +364,35 @@ EXPORT_SYMBOL_GPL(__crypto_alloc_tfm);
 
 struct crypto_tfm *crypto_alloc_tfm(const char *name, u32 flags)
 {
-	struct crypto_tfm *tfm = NULL;
+	struct crypto_tfm *tfm;
 	int err;
 
-	do {
+	for (;;) {
 		struct crypto_alg *alg;
 
 		alg = crypto_alg_mod_lookup(name, 0, CRYPTO_ALG_ASYNC);
-		err = PTR_ERR(alg);
-		if (IS_ERR(alg))
-			continue;
+		if (IS_ERR(alg)) {
+			err = PTR_ERR(alg);
+			goto err;
+		}
 
 		tfm = __crypto_alloc_tfm(alg, flags);
-		err = 0;
-		if (IS_ERR(tfm)) {
-			crypto_mod_put(alg);
-			err = PTR_ERR(tfm);
-			tfm = NULL;
+		if (!IS_ERR(tfm))
+			return tfm;
+
+		crypto_mod_put(alg);
+		err = PTR_ERR(tfm);
+
+err:
+		if (err != -EAGAIN)
+			break;
+		if (signal_pending(current)) {
+			err = -EINTR;
+			break;
 		}
-	} while (err == -EAGAIN && !signal_pending(current));
+	}
 
-	return tfm;
+	return ERR_PTR(err);
 }
 
 /*
@@ -414,14 +423,14 @@ struct crypto_tfm *crypto_alloc_base(con
 		struct crypto_alg *alg;
 
 		alg = crypto_alg_mod_lookup(alg_name, type, mask);
-		err = PTR_ERR(alg);
-		tfm = ERR_PTR(err);
-		if (IS_ERR(alg))
+		if (IS_ERR(alg)) {
+			err = PTR_ERR(alg);
 			goto err;
+		}
 
 		tfm = __crypto_alloc_tfm(alg, 0);
 		if (!IS_ERR(tfm))
-			break;
+			return tfm;
 
 		crypto_mod_put(alg);
 		err = PTR_ERR(tfm);
@@ -433,9 +442,9 @@ err:
 			err = -EINTR;
 			break;
 		}
-	};
+	}
 
-	return tfm;
+	return ERR_PTR(err);
 }
 EXPORT_SYMBOL_GPL(crypto_alloc_base);
  
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ