From patchwork Sun Sep 15 00:56:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chun-Yi Lee X-Patchwork-Id: 2894121 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 26B799F1F1 for ; Sun, 15 Sep 2013 00:59:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3EC75202F7 for ; Sun, 15 Sep 2013 00:59:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 37897202E8 for ; Sun, 15 Sep 2013 00:59:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932750Ab3IOA6q (ORCPT ); Sat, 14 Sep 2013 20:58:46 -0400 Received: from mail-bk0-f48.google.com ([209.85.214.48]:52549 "EHLO mail-bk0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932743Ab3IOA6o (ORCPT ); Sat, 14 Sep 2013 20:58:44 -0400 Received: by mail-bk0-f48.google.com with SMTP id my13so980100bkb.7 for ; Sat, 14 Sep 2013 17:58:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bQhMaIkG0b2ArBpVFAHhh2TWkTnwc+VbOzSLKnfhwlo=; b=JFofONJPeKBqB+U3lu0Pri4S4bq0QCRHfUSiHQA+FWZhINzeW2GM5c1L6rJMwPMuQN 6NfBZOfbavILzZR6SWDa/QGpktu/0elnN/wjycyI77xO5E7iC/nfZ8f2NqAV85abPLTT JdsKBp6jMJ3EejVt42ia0EHUH7S+ueb1k80h5wVeymBxa1xjTwwTndzpU49Q/phCzTb0 rCHID1JoO4MsZuP14FAwqXCCAuNaM8JijfMtyzCrcup5wTsSyTzKKhDUwgnxdDwAEnjq HgGLqBYZ4KSQrJEtdTZgtMKrHp1AP0mRxuPGK1nQ4cqpQcIublXRwwVSA/nBPcwmnP8V 3n0A== X-Received: by 10.205.35.15 with SMTP id su15mr17902320bkb.21.1379206721025; Sat, 14 Sep 2013 17:58:41 -0700 (PDT) Received: from localhost.localdomain ([124.11.22.254]) by mx.google.com with ESMTPSA id zl3sm4941613bkb.4.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sat, 14 Sep 2013 17:58:40 -0700 (PDT) From: "Lee, Chun-Yi" To: linux-kernel@vger.kernel.org Cc: linux-security-module@vger.kernel.org, linux-efi@vger.kernel.org, linux-pm@vger.kernel.org, linux-crypto@vger.kernel.org, opensuse-kernel@opensuse.org, David Howells , "Rafael J. Wysocki" , Matthew Garrett , Len Brown , Pavel Machek , Josh Boyer , Vojtech Pavlik , Matt Fleming , James Bottomley , Greg KH , JKosina@suse.com, Rusty Russell , Herbert Xu , "David S. Miller" , "H. Peter Anvin" , Michal Marek , Gary Lin , Vivek Goyal , "Lee, Chun-Yi" Subject: [PATCH V4 13/15] Hibernate: introduced SNAPSHOT_SIG_HASH config for select hash algorithm Date: Sun, 15 Sep 2013 08:56:59 +0800 Message-Id: <1379206621-18639-14-git-send-email-jlee@suse.com> X-Mailer: git-send-email 1.6.0.2 In-Reply-To: <1379206621-18639-1-git-send-email-jlee@suse.com> References: <1379206621-18639-1-git-send-email-jlee@suse.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, KHOP_BIG_TO_CC, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Signed-off-by: Lee, Chun-Yi --- kernel/power/Kconfig | 46 ++++++++++++++++++++++++++++++++++++++++++++++ kernel/power/snapshot.c | 25 ++++++++++++++++++++----- 2 files changed, 66 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. + +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 804feb6..896f11d 100644 --- a/kernel/power/snapshot.c +++ b/kernel/power/snapshot.c @@ -1041,7 +1041,22 @@ static inline void copy_data_page(unsigned long dst_pfn, unsigned long src_pfn) #endif /* CONFIG_HIGHMEM */ #ifdef CONFIG_SNAPSHOT_VERIFICATION -#define SNAPSHOT_HASH "sha256" +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; +} #endif /* @@ -1074,7 +1089,7 @@ swsusp_generate_signature(struct memory_bitmap *copy_bm, unsigned int nr_pages) int ret, i; ret = -ENOMEM; - 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); @@ -1127,7 +1142,7 @@ swsusp_generate_signature(struct memory_bitmap *copy_bm, unsigned int nr_pages) 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); @@ -2491,7 +2506,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; @@ -2544,7 +2559,7 @@ int snapshot_image_verify(void) if (ret) goto forward_ret; - 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);