From patchwork Tue Aug 11 06:16:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chun-Yi Lee X-Patchwork-Id: 6988861 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.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8D36D9F373 for ; Tue, 11 Aug 2015 06:21:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7EA362063B for ; Tue, 11 Aug 2015 06:21:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5BCAE20604 for ; Tue, 11 Aug 2015 06:21:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755187AbbHKGUz (ORCPT ); Tue, 11 Aug 2015 02:20:55 -0400 Received: from mail-pa0-f41.google.com ([209.85.220.41]:34178 "EHLO mail-pa0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934074AbbHKGTP (ORCPT ); Tue, 11 Aug 2015 02:19:15 -0400 Received: by pawu10 with SMTP id u10so157035386paw.1; Mon, 10 Aug 2015 23:19:13 -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=unwpmKPTdL/8n6wmG96BlqT9aADP1IhvSs3P5GPezu0=; b=TEJTgIt8hAx6zXxO5HhZn+t2IWNS84bOFkqGsq9u1RoNzGaT4r2mV3dplVzg+qf/Fj tdAyCy9Vhzfz6VCbpJ39r1iHKMsfs1oYbA7OtBWyz1gB2Pc29dg09WAvPTF8ZvRFZVFZ gqLZZtyMkIQfKOVzZzw1nzaYLTI8iFoOBMuKULKq0IXuq3UUn3CzmSoh8DQIaN5seW1y aCxtkOCpjaMq/KhQ3JqNiJbBSqWl3W2ZC11eVvoY0A6Pq9e6FvLD3CzLM8yThfRzaT18 0DpW+Ob0ayB8qi8XW/e50E/jkx0X/dkFl46Mn0MfWkk7H7lrj2gv+f7qJzxc7A46E9WE OOXg== X-Received: by 10.66.190.168 with SMTP id gr8mr53192387pac.22.1439273953623; Mon, 10 Aug 2015 23:19:13 -0700 (PDT) Received: from linux-rxt1.site ([130.57.30.250]) by smtp.gmail.com with ESMTPSA id qe3sm1082667pbc.73.2015.08.10.23.19.05 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Aug 2015 23:19:12 -0700 (PDT) From: "Lee, Chun-Yi" X-Google-Original-From: "Lee, Chun-Yi" To: linux-kernel@vger.kernel.org Cc: linux-efi@vger.kernel.org, linux-pm@vger.kernel.org, "Rafael J. Wysocki" , Matthew Garrett , Len Brown , Pavel Machek , Josh Boyer , Vojtech Pavlik , Matt Fleming , Jiri Kosina , "H. Peter Anvin" , Ingo Molnar , "Lee, Chun-Yi" Subject: [PATCH v2 13/16] PM / hibernate: Add configuration to enforce signature verification Date: Tue, 11 Aug 2015 14:16:33 +0800 Message-Id: <1439273796-25359-14-git-send-email-jlee@suse.com> X-Mailer: git-send-email 1.8.4.5 In-Reply-To: <1439273796-25359-1-git-send-email-jlee@suse.com> References: <1439273796-25359-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.0 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 Like kernel module signature checking, there's both a config option and a boot parameter which control whether we accept or fail with unsigned hibernate image and image that are signed with an unknown key. If hibernate signing is enabled, the kernel will be tainted if a snapshot image is restored that is unsigned or has a signature for which we don't have the key. When the enforce flag is enabled, then the hibernate restoring process will be failed and boot as normal. Reviewed-by: Jiri Kosina Tested-by: Jiri Kosina Signed-off-by: Lee, Chun-Yi --- Documentation/kernel-parameters.txt | 5 +++++ arch/x86/power/hibernate_keys.c | 19 +++++++++++++++++-- include/linux/kernel.h | 1 + include/linux/suspend.h | 3 +++ kernel/panic.c | 2 ++ kernel/power/Kconfig | 8 ++++++++ kernel/power/hibernate.c | 7 +++++++ kernel/power/snapshot.c | 6 +++++- 8 files changed, 48 insertions(+), 3 deletions(-) diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt index 1d6f045..86a6916 100644 --- a/Documentation/kernel-parameters.txt +++ b/Documentation/kernel-parameters.txt @@ -3318,6 +3318,11 @@ bytes respectively. Such letter suffixes can also be entirely omitted. noresume Don't check if there's a hibernation image present during boot. nocompress Don't compress/decompress hibernation images. + sigenforce When CONFIG_HIBERNATE_VERIFICATION is set, this + menas that snapshot image without (valid) + signature will fail to restore. Note that if + HIBERNATE_VERIFICATION_FORCE is set, that is + always true, so this option does nothing. no Disable hibernation and resume. retain_initrd [RAM] Keep initrd memory after extraction diff --git a/arch/x86/power/hibernate_keys.c b/arch/x86/power/hibernate_keys.c index 5e92101..51e808a 100644 --- a/arch/x86/power/hibernate_keys.c +++ b/arch/x86/power/hibernate_keys.c @@ -89,6 +89,7 @@ void fill_forward_info(void *forward_buff_page, int verify_ret) memset(forward_buff_page, 0, PAGE_SIZE); info = (struct forward_info *)forward_buff_page; info->sig_verify_ret = verify_ret; + info->sig_enforce = sigenforce; if (hibernation_keys && !hibernation_keys->hkey_status) { info->hibernation_keys = *hibernation_keys; @@ -106,10 +107,24 @@ void restore_sig_forward_info(void) return; } - if (forward_buff->sig_verify_ret) - pr_warn("PM: Signature verifying failed: %d\n", + sigenforce = forward_buff->sig_enforce; + if (sigenforce) + pr_info("PM: Enforce hibernate signature verifying\n"); + + if (forward_buff->sig_verify_ret) { + pr_warn("PM: Hibernate signature verifying failed: %d\n", forward_buff->sig_verify_ret); + /* taint kernel */ + if (!sigenforce) { + pr_warn("PM: System restored from unsafe snapshot - " + "tainting kernel\n"); + add_taint(TAINT_UNSAFE_HIBERNATE, LOCKDEP_STILL_OK); + pr_info("%s\n", print_tainted()); + } + } else + pr_info("PM: Signature verifying pass\n"); + if (hibernation_keys) { memset(hibernation_keys, 0, PAGE_SIZE); *hibernation_keys = forward_buff->hibernation_keys; diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 5582410..a620786 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -489,6 +489,7 @@ extern enum system_states { #define TAINT_UNSIGNED_MODULE 13 #define TAINT_SOFTLOCKUP 14 #define TAINT_LIVEPATCH 15 +#define TAINT_UNSAFE_HIBERNATE 16 extern const char hex_asc[]; #define hex_asc_lo(x) hex_asc[((x) & 0x0f)] diff --git a/include/linux/suspend.h b/include/linux/suspend.h index aa88b3b..d318b72 100644 --- a/include/linux/suspend.h +++ b/include/linux/suspend.h @@ -335,6 +335,9 @@ struct platform_hibernation_ops { #define HIBERNATION_HMAC "hmac(sha1)" #define HIBERNATION_DIGEST_SIZE 20 +/* kernel/power/hibernate.c */ +extern int sigenforce; + /* kernel/power/snapshot.c */ extern void __register_nosave_region(unsigned long b, unsigned long e, int km); static inline void __init register_nosave_region(unsigned long b, unsigned long e) diff --git a/kernel/panic.c b/kernel/panic.c index 04e91ff..a53da16 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -228,6 +228,7 @@ static const struct tnt tnts[] = { { TAINT_UNSIGNED_MODULE, 'E', ' ' }, { TAINT_SOFTLOCKUP, 'L', ' ' }, { TAINT_LIVEPATCH, 'K', ' ' }, + { TAINT_UNSAFE_HIBERNATE, 'H', ' ' }, }; /** @@ -249,6 +250,7 @@ static const struct tnt tnts[] = { * 'E' - Unsigned module has been loaded. * 'L' - A soft lockup has previously occurred. * 'K' - Kernel has been live patched. + * 'H' - System restored from unsafe hibernate snapshot image. * * The string is overwritten by the next call to print_tainted(). */ diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig index 8608b3b..f2a7e21 100644 --- a/kernel/power/Kconfig +++ b/kernel/power/Kconfig @@ -79,6 +79,14 @@ config HIBERNATE_VERIFICATION relies on UEFI secure boot environment, EFI stub generates HMAC key for hibernate verification. +config HIBERNATE_VERIFICATION_FORCE + bool "Require hibernate snapshot image to be validly signed" + depends on HIBERNATE_VERIFICATION + help + Reject hibernate resuming from unsigned snapshot image or signed + snapshot image for which we don't have a key. Without this, such + snapshot image will simply taint the kernel when resuming. + config ARCH_SAVE_PAGE_KEYS bool diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c index 640ca8a..2c2cc90 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c @@ -43,6 +43,11 @@ static char resume_file[256] = CONFIG_PM_STD_PARTITION; dev_t swsusp_resume_device; sector_t swsusp_resume_block; __visible int in_suspend __nosavedata; +#ifdef CONFIG_HIBERNATE_VERIFICATION_FORCE +int sigenforce = 1; +#else +int sigenforce; +#endif enum { HIBERNATION_INVALID, @@ -1119,6 +1124,8 @@ static int __init hibernate_setup(char *str) noresume = 1; else if (!strncmp(str, "nocompress", 10)) nocompress = 1; + else if (!strncmp(str, "sigenforce", 10)) + sigenforce = 1; else if (!strncmp(str, "no", 2)) { noresume = 1; nohibernate = 1; diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c index 3629249..486dd73 100644 --- a/kernel/power/snapshot.c +++ b/kernel/power/snapshot.c @@ -1469,7 +1469,11 @@ error_digest: forward_ret: if (ret) pr_warn("PM: Signature verifying failed: %d\n", ret); - snapshot_fill_sig_forward_info(ret); + /* forward check result when verifying pass or not enforce verifying */ + if (!ret || !sigenforce) { + snapshot_fill_sig_forward_info(ret); + ret = 0; + } return ret; }