diff mbox

[17/18] Hibernate: introduced SNAPSHOT_SIG_HASH config for select hash algorithm

Message ID 1377169317-5959-18-git-send-email-jlee@suse.com (mailing list archive)
State RFC, archived
Headers show

Commit Message

Chun-Yi Lee Aug. 22, 2013, 11:01 a.m. UTC
This patch introduced SNAPSHOT_SIG_HASH config for user to select which
hash algorithm will be used during signature generation of snapshot.

v2:
Add define check of oCONFIG_SNAPSHOT_VERIFICATION in snapshot.c before
declare pkey_hash().

Reviewed-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Lee, Chun-Yi <jlee@suse.com>
---
 kernel/power/Kconfig    |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 kernel/power/snapshot.c |   27 ++++++++++++++++++++++-----
 2 files changed, 68 insertions(+), 5 deletions(-)

Comments

Pavel Machek Aug. 25, 2013, 4:43 p.m. UTC | #1
On Thu 2013-08-22 19:01:56, Lee, Chun-Yi wrote:
> This patch introduced SNAPSHOT_SIG_HASH config for user to select which
> hash algorithm will be used during signature generation of snapshot.
> 
> v2:
> Add define check of oCONFIG_SNAPSHOT_VERIFICATION in snapshot.c before
> declare pkey_hash().
> 
> Reviewed-by: Jiri Kosina <jkosina@suse.cz>
> Signed-off-by: Lee, Chun-Yi <jlee@suse.com>
> ---
>  kernel/power/Kconfig    |   46 ++++++++++++++++++++++++++++++++++++++++++++++
>  kernel/power/snapshot.c |   27 ++++++++++++++++++++++-----
>  2 files changed, 68 insertions(+), 5 deletions(-)
> 
> diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
> index b592d88..79b34fa 100644
> --- a/kernel/power/Kconfig
> +++ b/kernel/power/Kconfig
> @@ -78,6 +78,52 @@ config SNAPSHOT_VERIFICATION
>  	  dependent on UEFI environment. EFI bootloader should generate the
>  	  key-pair.
>  
> +choice
> +	prompt "Which hash algorithm should snapshot be signed with?"
> +        depends on SNAPSHOT_VERIFICATION
> +        help
> +          This determines which sort of hashing algorithm will be used during
> +          signature generation of snapshot. This algorithm _must_ be built into
> +	  the kernel directly so that signature verification can take place.
> +	  It is not possible to load a signed snapshot containing the algorithm
> +	  to check the signature on that module.

Like if 1000 ifdefs you already added to the code are not enough, you
make some new ones?
									Pavel
joeyli Aug. 27, 2013, 10:22 a.m. UTC | #2
? ??2013-08-25 ? 18:43 +0200?Pavel Machek ???
> On Thu 2013-08-22 19:01:56, Lee, Chun-Yi wrote:
> > This patch introduced SNAPSHOT_SIG_HASH config for user to select which
> > hash algorithm will be used during signature generation of snapshot.
> > 
> > v2:
> > Add define check of oCONFIG_SNAPSHOT_VERIFICATION in snapshot.c before
> > declare pkey_hash().
> > 
> > Reviewed-by: Jiri Kosina <jkosina@suse.cz>
> > Signed-off-by: Lee, Chun-Yi <jlee@suse.com>
> > ---
> >  kernel/power/Kconfig    |   46 ++++++++++++++++++++++++++++++++++++++++++++++
> >  kernel/power/snapshot.c |   27 ++++++++++++++++++++++-----
> >  2 files changed, 68 insertions(+), 5 deletions(-)
> > 
> > diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
> > index b592d88..79b34fa 100644
> > --- a/kernel/power/Kconfig
> > +++ b/kernel/power/Kconfig
> > @@ -78,6 +78,52 @@ config SNAPSHOT_VERIFICATION
> >  	  dependent on UEFI environment. EFI bootloader should generate the
> >  	  key-pair.
> >  
> > +choice
> > +	prompt "Which hash algorithm should snapshot be signed with?"
> > +        depends on SNAPSHOT_VERIFICATION
> > +        help
> > +          This determines which sort of hashing algorithm will be used during
> > +          signature generation of snapshot. This algorithm _must_ be built into
> > +	  the kernel directly so that signature verification can take place.
> > +	  It is not possible to load a signed snapshot containing the algorithm
> > +	  to check the signature on that module.
> 
> Like if 1000 ifdefs you already added to the code are not enough, you
> make some new ones?
> 									Pavel
> 

This SNAPSHOT_SIG_HASH kernel config is to select which SHA algorithms
used for generate digest of snapshot. The configuration will captured by
a const char* in code:

+static const char *snapshot_hash = CONFIG_SNAPSHOT_SIG_HASH;
+
+static int pkey_hash(void)

So, there doesn't have any ifdef block derived from this new config.


Thanks a lot!
Joey Lee

--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Pavel Machek Aug. 27, 2013, 11:30 a.m. UTC | #3
On Tue 2013-08-27 18:22:17, joeyli wrote:
> ? ??2013-08-25 ? 18:43 +0200?Pavel Machek ???
> > On Thu 2013-08-22 19:01:56, Lee, Chun-Yi wrote:
> > > This patch introduced SNAPSHOT_SIG_HASH config for user to select which
> > > hash algorithm will be used during signature generation of snapshot.
> > > 
> > > v2:
> > > Add define check of oCONFIG_SNAPSHOT_VERIFICATION in snapshot.c before
> > > declare pkey_hash().
> > > 
> > > Reviewed-by: Jiri Kosina <jkosina@suse.cz>
> > > Signed-off-by: Lee, Chun-Yi <jlee@suse.com>
> > > ---
> > >  kernel/power/Kconfig    |   46 ++++++++++++++++++++++++++++++++++++++++++++++
> > >  kernel/power/snapshot.c |   27 ++++++++++++++++++++++-----
> > >  2 files changed, 68 insertions(+), 5 deletions(-)
> > > 
> > > diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
> > > index b592d88..79b34fa 100644
> > > --- a/kernel/power/Kconfig
> > > +++ b/kernel/power/Kconfig
> > > @@ -78,6 +78,52 @@ config SNAPSHOT_VERIFICATION
> > >  	  dependent on UEFI environment. EFI bootloader should generate the
> > >  	  key-pair.
> > >  
> > > +choice
> > > +	prompt "Which hash algorithm should snapshot be signed with?"
> > > +        depends on SNAPSHOT_VERIFICATION
> > > +        help
> > > +          This determines which sort of hashing algorithm will be used during
> > > +          signature generation of snapshot. This algorithm _must_ be built into
> > > +	  the kernel directly so that signature verification can take place.
> > > +	  It is not possible to load a signed snapshot containing the algorithm
> > > +	  to check the signature on that module.
> > 
> > Like if 1000 ifdefs you already added to the code are not enough, you
> > make some new ones?
> > 									Pavel
> > 
> 
> This SNAPSHOT_SIG_HASH kernel config is to select which SHA algorithms
> used for generate digest of snapshot. The configuration will captured by
> a const char* in code:
> 
> +static const char *snapshot_hash = CONFIG_SNAPSHOT_SIG_HASH;
> +
> +static int pkey_hash(void)
> 
> So, there doesn't have any ifdef block derived from this new config.

I'd say select one hash function, and use it. There's no need to make
it configurable.
									Pavel
joeyli Aug. 27, 2013, 12:54 p.m. UTC | #4
? ??2013-08-27 ? 13:30 +0200?Pavel Machek ???
> On Tue 2013-08-27 18:22:17, joeyli wrote:
> > ? ??2013-08-25 ? 18:43 +0200?Pavel Machek ???
> > > On Thu 2013-08-22 19:01:56, Lee, Chun-Yi wrote:
> > > > This patch introduced SNAPSHOT_SIG_HASH config for user to select which
> > > > hash algorithm will be used during signature generation of snapshot.
> > > > 
> > > > v2:
> > > > Add define check of oCONFIG_SNAPSHOT_VERIFICATION in snapshot.c before
> > > > declare pkey_hash().
> > > > 
> > > > Reviewed-by: Jiri Kosina <jkosina@suse.cz>
> > > > Signed-off-by: Lee, Chun-Yi <jlee@suse.com>
> > > > ---
> > > >  kernel/power/Kconfig    |   46 ++++++++++++++++++++++++++++++++++++++++++++++
> > > >  kernel/power/snapshot.c |   27 ++++++++++++++++++++++-----
> > > >  2 files changed, 68 insertions(+), 5 deletions(-)
> > > > 
> > > > diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
> > > > index b592d88..79b34fa 100644
> > > > --- a/kernel/power/Kconfig
> > > > +++ b/kernel/power/Kconfig
> > > > @@ -78,6 +78,52 @@ config SNAPSHOT_VERIFICATION
> > > >  	  dependent on UEFI environment. EFI bootloader should generate the
> > > >  	  key-pair.
> > > >  
> > > > +choice
> > > > +	prompt "Which hash algorithm should snapshot be signed with?"
> > > > +        depends on SNAPSHOT_VERIFICATION
> > > > +        help
> > > > +          This determines which sort of hashing algorithm will be used during
> > > > +          signature generation of snapshot. This algorithm _must_ be built into
> > > > +	  the kernel directly so that signature verification can take place.
> > > > +	  It is not possible to load a signed snapshot containing the algorithm
> > > > +	  to check the signature on that module.
> > > 
> > > Like if 1000 ifdefs you already added to the code are not enough, you
> > > make some new ones?
> > > 									Pavel
> > > 
> > 
> > This SNAPSHOT_SIG_HASH kernel config is to select which SHA algorithms
> > used for generate digest of snapshot. The configuration will captured by
> > a const char* in code:
> > 
> > +static const char *snapshot_hash = CONFIG_SNAPSHOT_SIG_HASH;
> > +
> > +static int pkey_hash(void)
> > 
> > So, there doesn't have any ifdef block derived from this new config.
> 
> I'd say select one hash function, and use it. There's no need to make
> it configurable.
> 									Pavel

There have better performance when SHA algorithm output shorter hash
result. On the other hand, longer hash result provide better security.

And, on 64-bits system, the SHA512 has better performance then SHA256.

Due to user have different use case and different hardware, why not give
them this option to make decision?


Thanks a lot!
Joey LEe

--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
index b592d88..79b34fa 100644
--- a/kernel/power/Kconfig
+++ b/kernel/power/Kconfig
@@ -78,6 +78,52 @@  config SNAPSHOT_VERIFICATION
 	  dependent on UEFI environment. EFI bootloader should generate the
 	  key-pair.
 
+choice
+	prompt "Which hash algorithm should snapshot be signed with?"
+        depends on SNAPSHOT_VERIFICATION
+        help
+          This determines which sort of hashing algorithm will be used during
+          signature generation of snapshot. This algorithm _must_ be built into
+	  the kernel directly so that signature verification can take place.
+	  It is not possible to load a signed snapshot containing the algorithm
+	  to check the signature on that module.
+
+config SNAPSHOT_SIG_SHA1
+        bool "Sign modules with SHA-1"
+        select CRYPTO_SHA1
+	select CRYPTO_SHA1_SSSE3 if X86_64
+
+config SNAPSHOT_SIG_SHA224
+        bool "Sign modules with SHA-224"
+        select CRYPTO_SHA256
+	select CRYPTO_SHA256_SSSE3 if X86_64
+
+config SNAPSHOT_SIG_SHA256
+        bool "Sign modules with SHA-256"
+        select CRYPTO_SHA256
+	select CRYPTO_SHA256_SSSE3 if X86_64
+
+config SNAPSHOT_SIG_SHA384
+        bool "Sign modules with SHA-384"
+        select CRYPTO_SHA512
+	select CRYPTO_SHA512_SSSE3 if X86_64
+
+config SNAPSHOT_SIG_SHA512
+        bool "Sign modules with SHA-512"
+        select CRYPTO_SHA512
+	select CRYPTO_SHA512_SSSE3 if X86_64
+
+endchoice
+
+config SNAPSHOT_SIG_HASH
+        string
+        depends on SNAPSHOT_VERIFICATION
+        default "sha1" if SNAPSHOT_SIG_SHA1
+        default "sha224" if SNAPSHOT_SIG_SHA224
+        default "sha256" if SNAPSHOT_SIG_SHA256
+        default "sha384" if SNAPSHOT_SIG_SHA384
+        default "sha512" if SNAPSHOT_SIG_SHA512
+
 config PM_STD_PARTITION
 	string "Default resume partition"
 	depends on HIBERNATION
diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c
index b9c6a8a..f02e351 100644
--- a/kernel/power/snapshot.c
+++ b/kernel/power/snapshot.c
@@ -1042,12 +1042,29 @@  static inline void copy_data_page(unsigned long dst_pfn, unsigned long src_pfn)
 }
 #endif /* CONFIG_HIGHMEM */
 
-#define SNAPSHOT_HASH "sha256"
+#ifdef CONFIG_SNAPSHOT_VERIFICATION
+static const char *snapshot_hash = CONFIG_SNAPSHOT_SIG_HASH;
+
+static int pkey_hash(void)
+{
+	int i, ret;
+
+	ret = -1;
+	for (i = 0; i < PKEY_HASH__LAST; i++) {
+		if (!strcmp(pkey_hash_algo[i], snapshot_hash)) {
+			ret = i;
+			break;
+		}
+	}
+
+	return ret;
+}
 
 /*
  * Signature of snapshot for check.
  */
 static u8 signature[SIG_LENG];
+#endif
 
 static int
 copy_data_pages(struct memory_bitmap *copy_bm, struct memory_bitmap *orig_bm)
@@ -1068,7 +1085,7 @@  copy_data_pages(struct memory_bitmap *copy_bm, struct memory_bitmap *orig_bm)
 
 	ret = -ENOMEM;
 	if (!capable(CAP_COMPROMISE_KERNEL)) {
-		tfm = crypto_alloc_shash(SNAPSHOT_HASH, 0, 0);
+		tfm = crypto_alloc_shash(snapshot_hash, 0, 0);
 		if (IS_ERR(tfm)) {
 			pr_err("IS_ERR(tfm): %ld", PTR_ERR(tfm));
 			return PTR_ERR(tfm);
@@ -1145,7 +1162,7 @@  copy_data_pages(struct memory_bitmap *copy_bm, struct memory_bitmap *orig_bm)
 		goto error_key;
 	}
 
-	pks = generate_signature(s4_sign_key, digest, PKEY_HASH_SHA256, false);
+	pks = generate_signature(s4_sign_key, digest, pkey_hash(), false);
 	if (IS_ERR(pks)) {
 		pr_err("Generate signature fail: %lx", PTR_ERR(pks));
 		ret = PTR_ERR(pks);
@@ -2499,7 +2516,7 @@  int snapshot_verify_signature(u8 *digest, size_t digest_size)
 		pr_err("PM: Allocate public key signature fail!");
 		return -ENOMEM;
 	}
-	pks->pkey_hash_algo = PKEY_HASH_SHA256;
+	pks->pkey_hash_algo = pkey_hash();
 	pks->digest = digest;
 	pks->digest_size = digest_size;
 
@@ -2547,7 +2564,7 @@  int snapshot_image_verify(void)
 	if (!h_buf)
 		return 0;
 
-	tfm = crypto_alloc_shash(SNAPSHOT_HASH, 0, 0);
+	tfm = crypto_alloc_shash(snapshot_hash, 0, 0);
 	if (IS_ERR(tfm)) {
 		pr_err("IS_ERR(tfm): %ld", PTR_ERR(tfm));
 		return PTR_ERR(tfm);