linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] Fix crypto/vmx/p8_ghash memory corruption
@ 2016-09-28 16:42 Marcelo Cerri
  2016-09-28 16:42 ` [PATCH 1/3] crypto: ghash-generic - move common definitions to a new header file Marcelo Cerri
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Marcelo Cerri @ 2016-09-28 16:42 UTC (permalink / raw)
  To: linux-crypto, Herbert Xu
  Cc: David S. Miller, Paulo Flabiano Smorigo, Leonidas S. Barbosa,
	linuxppc-dev, linux-kernel, Benjamin Herrenschmidt,
	Paul Mackerras, Michael Ellerman, George Wilson, Marcelo Cerri

This series fixes the memory corruption found by Jan Stancek in 4.8-rc7. The
problem however also affects previous versions of the driver.

Marcelo Cerri (3):
  crypto: ghash-generic - move common definitions to a new header file
  crypto: vmx - Fix memory corruption caused by p8_ghash
  crypto: vmx - Ensure ghash-generic is enabled

 crypto/ghash-generic.c     | 13 +------------
 drivers/crypto/vmx/Kconfig |  2 +-
 drivers/crypto/vmx/ghash.c | 31 ++++++++++++++++---------------
 include/crypto/ghash.h     | 23 +++++++++++++++++++++++
 4 files changed, 41 insertions(+), 28 deletions(-)
 create mode 100644 include/crypto/ghash.h

-- 
2.7.4

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

* [PATCH 1/3] crypto: ghash-generic - move common definitions to a new header file
  2016-09-28 16:42 [PATCH 0/3] Fix crypto/vmx/p8_ghash memory corruption Marcelo Cerri
@ 2016-09-28 16:42 ` Marcelo Cerri
  2016-09-28 16:42 ` [PATCH 2/3] crypto: vmx - Fix memory corruption caused by p8_ghash Marcelo Cerri
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Marcelo Cerri @ 2016-09-28 16:42 UTC (permalink / raw)
  To: linux-crypto, Herbert Xu
  Cc: David S. Miller, Paulo Flabiano Smorigo, Leonidas S. Barbosa,
	linuxppc-dev, linux-kernel, Benjamin Herrenschmidt,
	Paul Mackerras, Michael Ellerman, George Wilson, Marcelo Cerri

Move common values and types used by ghash-generic to a new header file
so drivers can directly use ghash-generic as a fallback implementation.

Signed-off-by: Marcelo Cerri <marcelo.cerri@canonical.com>
---
 crypto/ghash-generic.c | 13 +------------
 include/crypto/ghash.h | 23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+), 12 deletions(-)
 create mode 100644 include/crypto/ghash.h

diff --git a/crypto/ghash-generic.c b/crypto/ghash-generic.c
index bac7099..12ad3e3 100644
--- a/crypto/ghash-generic.c
+++ b/crypto/ghash-generic.c
@@ -14,24 +14,13 @@
 
 #include <crypto/algapi.h>
 #include <crypto/gf128mul.h>
+#include <crypto/ghash.h>
 #include <crypto/internal/hash.h>
 #include <linux/crypto.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 
-#define GHASH_BLOCK_SIZE	16
-#define GHASH_DIGEST_SIZE	16
-
-struct ghash_ctx {
-	struct gf128mul_4k *gf128;
-};
-
-struct ghash_desc_ctx {
-	u8 buffer[GHASH_BLOCK_SIZE];
-	u32 bytes;
-};
-
 static int ghash_init(struct shash_desc *desc)
 {
 	struct ghash_desc_ctx *dctx = shash_desc_ctx(desc);
diff --git a/include/crypto/ghash.h b/include/crypto/ghash.h
new file mode 100644
index 0000000..2a61c9b
--- /dev/null
+++ b/include/crypto/ghash.h
@@ -0,0 +1,23 @@
+/*
+ * Common values for GHASH algorithms
+ */
+
+#ifndef __CRYPTO_GHASH_H__
+#define __CRYPTO_GHASH_H__
+
+#include <linux/types.h>
+#include <crypto/gf128mul.h>
+
+#define GHASH_BLOCK_SIZE	16
+#define GHASH_DIGEST_SIZE	16
+
+struct ghash_ctx {
+	struct gf128mul_4k *gf128;
+};
+
+struct ghash_desc_ctx {
+	u8 buffer[GHASH_BLOCK_SIZE];
+	u32 bytes;
+};
+
+#endif
-- 
2.7.4

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

* [PATCH 2/3] crypto: vmx - Fix memory corruption caused by p8_ghash
  2016-09-28 16:42 [PATCH 0/3] Fix crypto/vmx/p8_ghash memory corruption Marcelo Cerri
  2016-09-28 16:42 ` [PATCH 1/3] crypto: ghash-generic - move common definitions to a new header file Marcelo Cerri
@ 2016-09-28 16:42 ` Marcelo Cerri
  2016-09-28 16:42 ` [PATCH 3/3] crypto: vmx - Ensure ghash-generic is enabled Marcelo Cerri
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Marcelo Cerri @ 2016-09-28 16:42 UTC (permalink / raw)
  To: linux-crypto, Herbert Xu
  Cc: David S. Miller, Paulo Flabiano Smorigo, Leonidas S. Barbosa,
	linuxppc-dev, linux-kernel, Benjamin Herrenschmidt,
	Paul Mackerras, Michael Ellerman, George Wilson, Marcelo Cerri

This patch changes the p8_ghash driver to use ghash-generic as a fixed
fallback implementation. This allows the correct value of descsize to be
defined directly in its shash_alg structure and avoids problems with
incorrect buffer sizes when its state is exported or imported.

Reported-by: Jan Stancek <jstancek@redhat.com>
Signed-off-by: Marcelo Cerri <marcelo.cerri@canonical.com>
---
 drivers/crypto/vmx/ghash.c | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/drivers/crypto/vmx/ghash.c b/drivers/crypto/vmx/ghash.c
index 6c999cb0..27a94a1 100644
--- a/drivers/crypto/vmx/ghash.c
+++ b/drivers/crypto/vmx/ghash.c
@@ -26,16 +26,13 @@
 #include <linux/hardirq.h>
 #include <asm/switch_to.h>
 #include <crypto/aes.h>
+#include <crypto/ghash.h>
 #include <crypto/scatterwalk.h>
 #include <crypto/internal/hash.h>
 #include <crypto/b128ops.h>
 
 #define IN_INTERRUPT in_interrupt()
 
-#define GHASH_BLOCK_SIZE (16)
-#define GHASH_DIGEST_SIZE (16)
-#define GHASH_KEY_LEN (16)
-
 void gcm_init_p8(u128 htable[16], const u64 Xi[2]);
 void gcm_gmult_p8(u64 Xi[2], const u128 htable[16]);
 void gcm_ghash_p8(u64 Xi[2], const u128 htable[16],
@@ -55,16 +52,11 @@ struct p8_ghash_desc_ctx {
 
 static int p8_ghash_init_tfm(struct crypto_tfm *tfm)
 {
-	const char *alg;
+	const char *alg = "ghash-generic";
 	struct crypto_shash *fallback;
 	struct crypto_shash *shash_tfm = __crypto_shash_cast(tfm);
 	struct p8_ghash_ctx *ctx = crypto_tfm_ctx(tfm);
 
-	if (!(alg = crypto_tfm_alg_name(tfm))) {
-		printk(KERN_ERR "Failed to get algorithm name.\n");
-		return -ENOENT;
-	}
-
 	fallback = crypto_alloc_shash(alg, 0, CRYPTO_ALG_NEED_FALLBACK);
 	if (IS_ERR(fallback)) {
 		printk(KERN_ERR
@@ -78,10 +70,18 @@ static int p8_ghash_init_tfm(struct crypto_tfm *tfm)
 	crypto_shash_set_flags(fallback,
 			       crypto_shash_get_flags((struct crypto_shash
 						       *) tfm));
-	ctx->fallback = fallback;
 
-	shash_tfm->descsize = sizeof(struct p8_ghash_desc_ctx)
-	    + crypto_shash_descsize(fallback);
+	/* Check if the descsize defined in the algorithm is still enough. */
+	if (shash_tfm->descsize < sizeof(struct p8_ghash_desc_ctx)
+	    + crypto_shash_descsize(fallback)) {
+		printk(KERN_ERR
+		       "Desc size of the fallback implementation (%s) does not match the expected value: %lu vs %u\n",
+		       alg,
+		       shash_tfm->descsize - sizeof(struct p8_ghash_desc_ctx),
+		       crypto_shash_descsize(fallback));
+		return -EINVAL;
+	}
+	ctx->fallback = fallback;
 
 	return 0;
 }
@@ -113,7 +113,7 @@ static int p8_ghash_setkey(struct crypto_shash *tfm, const u8 *key,
 {
 	struct p8_ghash_ctx *ctx = crypto_tfm_ctx(crypto_shash_tfm(tfm));
 
-	if (keylen != GHASH_KEY_LEN)
+	if (keylen != GHASH_BLOCK_SIZE)
 		return -EINVAL;
 
 	preempt_disable();
@@ -211,7 +211,8 @@ struct shash_alg p8_ghash_alg = {
 	.update = p8_ghash_update,
 	.final = p8_ghash_final,
 	.setkey = p8_ghash_setkey,
-	.descsize = sizeof(struct p8_ghash_desc_ctx),
+	.descsize = sizeof(struct p8_ghash_desc_ctx)
+		+ sizeof(struct ghash_desc_ctx),
 	.base = {
 		 .cra_name = "ghash",
 		 .cra_driver_name = "p8_ghash",
-- 
2.7.4

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

* [PATCH 3/3] crypto: vmx - Ensure ghash-generic is enabled
  2016-09-28 16:42 [PATCH 0/3] Fix crypto/vmx/p8_ghash memory corruption Marcelo Cerri
  2016-09-28 16:42 ` [PATCH 1/3] crypto: ghash-generic - move common definitions to a new header file Marcelo Cerri
  2016-09-28 16:42 ` [PATCH 2/3] crypto: vmx - Fix memory corruption caused by p8_ghash Marcelo Cerri
@ 2016-09-28 16:42 ` Marcelo Cerri
  2016-09-28 20:59 ` [PATCH 0/3] Fix crypto/vmx/p8_ghash memory corruption Anton Blanchard
  2016-10-02 14:40 ` Herbert Xu
  4 siblings, 0 replies; 8+ messages in thread
From: Marcelo Cerri @ 2016-09-28 16:42 UTC (permalink / raw)
  To: linux-crypto, Herbert Xu
  Cc: David S. Miller, Paulo Flabiano Smorigo, Leonidas S. Barbosa,
	linuxppc-dev, linux-kernel, Benjamin Herrenschmidt,
	Paul Mackerras, Michael Ellerman, George Wilson, Marcelo Cerri

Add CRYPTO_GHASH as a dependency for vmx_crypto since p8_ghash uses it
as the fallback implementation.

Signed-off-by: Marcelo Cerri <marcelo.cerri@canonical.com>
---
 drivers/crypto/vmx/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/vmx/Kconfig b/drivers/crypto/vmx/Kconfig
index a83ead1..c21b09a 100644
--- a/drivers/crypto/vmx/Kconfig
+++ b/drivers/crypto/vmx/Kconfig
@@ -1,6 +1,6 @@
 config CRYPTO_DEV_VMX_ENCRYPT
 	tristate "Encryption acceleration support on P8 CPU"
-	depends on CRYPTO_DEV_VMX
+	depends on CRYPTO_DEV_VMX || CRYPTO_GHASH
 	default m
 	help
 	  Support for VMX cryptographic acceleration instructions on Power8 CPU.
-- 
2.7.4

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

* Re: [PATCH 0/3] Fix crypto/vmx/p8_ghash memory corruption
  2016-09-28 16:42 [PATCH 0/3] Fix crypto/vmx/p8_ghash memory corruption Marcelo Cerri
                   ` (2 preceding siblings ...)
  2016-09-28 16:42 ` [PATCH 3/3] crypto: vmx - Ensure ghash-generic is enabled Marcelo Cerri
@ 2016-09-28 20:59 ` Anton Blanchard
  2016-10-02 14:40   ` Herbert Xu
  2016-10-02 14:40 ` Herbert Xu
  4 siblings, 1 reply; 8+ messages in thread
From: Anton Blanchard @ 2016-09-28 20:59 UTC (permalink / raw)
  To: Marcelo Cerri
  Cc: linux-crypto, Herbert Xu, Leonidas S. Barbosa, linux-kernel,
	Paul Mackerras, Paulo Flabiano Smorigo, George Wilson,
	linuxppc-dev, David S. Miller

Hi Marcelo

> This series fixes the memory corruption found by Jan Stancek in
> 4.8-rc7. The problem however also affects previous versions of the
> driver.

If it affects previous versions, please add the lines in the sign off to
get it into the stable kernels.

Anton

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

* Re: [PATCH 0/3] Fix crypto/vmx/p8_ghash memory corruption
  2016-09-28 16:42 [PATCH 0/3] Fix crypto/vmx/p8_ghash memory corruption Marcelo Cerri
                   ` (3 preceding siblings ...)
  2016-09-28 20:59 ` [PATCH 0/3] Fix crypto/vmx/p8_ghash memory corruption Anton Blanchard
@ 2016-10-02 14:40 ` Herbert Xu
  4 siblings, 0 replies; 8+ messages in thread
From: Herbert Xu @ 2016-10-02 14:40 UTC (permalink / raw)
  To: Marcelo Cerri
  Cc: linux-crypto, David S. Miller, Paulo Flabiano Smorigo,
	Leonidas S. Barbosa, linuxppc-dev, linux-kernel,
	Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
	George Wilson

On Wed, Sep 28, 2016 at 01:42:08PM -0300, Marcelo Cerri wrote:
> This series fixes the memory corruption found by Jan Stancek in 4.8-rc7. The
> problem however also affects previous versions of the driver.
> 
> Marcelo Cerri (3):
>   crypto: ghash-generic - move common definitions to a new header file
>   crypto: vmx - Fix memory corruption caused by p8_ghash
>   crypto: vmx - Ensure ghash-generic is enabled

Patch 1/2 applied to crypto.  I have changed patch 3 to use select
instead of depend and have applied it to cryptodev.

Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: [PATCH 0/3] Fix crypto/vmx/p8_ghash memory corruption
  2016-09-28 20:59 ` [PATCH 0/3] Fix crypto/vmx/p8_ghash memory corruption Anton Blanchard
@ 2016-10-02 14:40   ` Herbert Xu
  2016-10-03 12:08     ` Marcelo Cerri
  0 siblings, 1 reply; 8+ messages in thread
From: Herbert Xu @ 2016-10-02 14:40 UTC (permalink / raw)
  To: Anton Blanchard
  Cc: Marcelo Cerri, linux-crypto, Leonidas S. Barbosa, linux-kernel,
	Paul Mackerras, Paulo Flabiano Smorigo, George Wilson,
	linuxppc-dev, David S. Miller

On Thu, Sep 29, 2016 at 06:59:08AM +1000, Anton Blanchard wrote:
> Hi Marcelo
> 
> > This series fixes the memory corruption found by Jan Stancek in
> > 4.8-rc7. The problem however also affects previous versions of the
> > driver.
> 
> If it affects previous versions, please add the lines in the sign off to
> get it into the stable kernels.

I have added them to patches 1 and 2.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: [PATCH 0/3] Fix crypto/vmx/p8_ghash memory corruption
  2016-10-02 14:40   ` Herbert Xu
@ 2016-10-03 12:08     ` Marcelo Cerri
  0 siblings, 0 replies; 8+ messages in thread
From: Marcelo Cerri @ 2016-10-03 12:08 UTC (permalink / raw)
  To: Herbert Xu
  Cc: Anton Blanchard, linux-crypto, Leonidas S. Barbosa, linux-kernel,
	Paul Mackerras, Paulo Flabiano Smorigo, George Wilson,
	linuxppc-dev, David S. Miller

[-- Attachment #1: Type: text/plain, Size: 694 bytes --]

Thank you.

-- 
Regards,
Marcelo

On Sun, Oct 02, 2016 at 10:40:47PM +0800, Herbert Xu wrote:
> On Thu, Sep 29, 2016 at 06:59:08AM +1000, Anton Blanchard wrote:
> > Hi Marcelo
> > 
> > > This series fixes the memory corruption found by Jan Stancek in
> > > 4.8-rc7. The problem however also affects previous versions of the
> > > driver.
> > 
> > If it affects previous versions, please add the lines in the sign off to
> > get it into the stable kernels.
> 
> I have added them to patches 1 and 2.  Thanks.
> -- 
> Email: Herbert Xu <herbert@gondor.apana.org.au>
> Home Page: http://gondor.apana.org.au/~herbert/
> PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

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

end of thread, other threads:[~2016-10-03 12:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-28 16:42 [PATCH 0/3] Fix crypto/vmx/p8_ghash memory corruption Marcelo Cerri
2016-09-28 16:42 ` [PATCH 1/3] crypto: ghash-generic - move common definitions to a new header file Marcelo Cerri
2016-09-28 16:42 ` [PATCH 2/3] crypto: vmx - Fix memory corruption caused by p8_ghash Marcelo Cerri
2016-09-28 16:42 ` [PATCH 3/3] crypto: vmx - Ensure ghash-generic is enabled Marcelo Cerri
2016-09-28 20:59 ` [PATCH 0/3] Fix crypto/vmx/p8_ghash memory corruption Anton Blanchard
2016-10-02 14:40   ` Herbert Xu
2016-10-03 12:08     ` Marcelo Cerri
2016-10-02 14:40 ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).