From patchwork Tue Aug 11 06:16:31 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: 6988891 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 31447C05AC for ; Tue, 11 Aug 2015 06:21:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 413B02063B for ; Tue, 11 Aug 2015 06:21:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5303120604 for ; Tue, 11 Aug 2015 06:21:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755397AbbHKGS7 (ORCPT ); Tue, 11 Aug 2015 02:18:59 -0400 Received: from mail-pd0-f182.google.com ([209.85.192.182]:34228 "EHLO mail-pd0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755154AbbHKGS4 (ORCPT ); Tue, 11 Aug 2015 02:18:56 -0400 Received: by pdbfa8 with SMTP id fa8so39770097pdb.1; Mon, 10 Aug 2015 23:18:56 -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=hM+jbLLGjRay9XpkfVz9rQEyVrD2jL+0f5n5z6+B8aE=; b=S8Igh7F90beKEIa3hHV4esbBq738hgCK0Wmst9LrFf+V1Ced/WU+tEWucgIJpQJuvI mMJbwWKfl6Ndhj/j7lFZU1koqGqiy8urIAaZIz1tMKNzgwjpqYO4L/IwUzAr5MiQVenT /YFlQ5YlEeU4XXHhaIE28/ab340S4lLQAmVCg35A19t1e3sOMsX9RyAH5mP5uYG6Fywl dO41wxzf3L8OH8sY25HX2dSNPGW0VGh2bZnLqrMY/Gdb+TNn9LQ8mBzI5SJbOLkoo1bM Mil2+JAY/nmGAjC/SnKUelJNKL/PqPvbdSGfHffvbjmGLKKorfdMv1g6RFsf32Qazb8d HL8g== X-Received: by 10.70.43.198 with SMTP id y6mr8079094pdl.4.1439273936304; Mon, 10 Aug 2015 23:18:56 -0700 (PDT) Received: from linux-rxt1.site ([130.57.30.250]) by smtp.gmail.com with ESMTPSA id qe3sm1082667pbc.73.2015.08.10.23.18.48 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Aug 2015 23:18:55 -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 11/16] PM / hibernate: Avoid including hibernation key to hibernate image Date: Tue, 11 Aug 2015 14:16:31 +0800 Message-Id: <1439273796-25359-12-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 The HMAC key should only resides in kernel memory space but not leak to outside. To avoid including hibernation key in hibernate snapshot image, this patch adds the checking block in the code for asking saveable pages to make sure the key page should not marked as saveable. Reviewed-by: Jiri Kosina Tested-by: Jiri Kosina Signed-off-by: Lee, Chun-Yi --- arch/x86/power/hibernate_keys.c | 15 +++++++++++++++ kernel/power/power.h | 3 +++ kernel/power/snapshot.c | 6 ++++++ 3 files changed, 24 insertions(+) diff --git a/arch/x86/power/hibernate_keys.c b/arch/x86/power/hibernate_keys.c index 357dc0e..f44823e 100644 --- a/arch/x86/power/hibernate_keys.c +++ b/arch/x86/power/hibernate_keys.c @@ -47,6 +47,21 @@ int get_hibernation_key(u8 **hkey) return hibernation_keys->hkey_status; } + +bool swsusp_page_is_keys(struct page *page) +{ + bool ret = false; + + if (!hibernation_keys || hibernation_keys->hkey_status) + return ret; + + ret = (page_to_pfn(page) == page_to_pfn(virt_to_page(hibernation_keys))); + if (ret) + pr_info("PM: Avoid snapshot the page of hibernation key.\n"); + + return ret; +} + static int __init init_hibernation_keys(void) { struct hibernation_keys *keys; diff --git a/kernel/power/power.h b/kernel/power/power.h index ccc1e72..6d1d406 100644 --- a/kernel/power/power.h +++ b/kernel/power/power.h @@ -19,6 +19,9 @@ struct swsusp_info { #ifdef CONFIG_HIBERNATE_VERIFICATION /* arch/x86/power/hibernate_keys.c */ extern int get_hibernation_key(u8 **hkey); +extern bool swsusp_page_is_keys(struct page *page); +#else +static inline bool swsusp_page_is_keys(struct page *page) { return false; } #endif /* kernel/power/snapshot.c */ diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c index b8c7e2e..5522028 100644 --- a/kernel/power/snapshot.c +++ b/kernel/power/snapshot.c @@ -1093,6 +1093,9 @@ static struct page *saveable_highmem_page(struct zone *zone, unsigned long pfn) BUG_ON(!PageHighMem(page)); + if (swsusp_page_is_keys(page)) + return NULL; + if (swsusp_page_is_forbidden(page) || swsusp_page_is_free(page) || PageReserved(page)) return NULL; @@ -1155,6 +1158,9 @@ static struct page *saveable_page(struct zone *zone, unsigned long pfn) BUG_ON(PageHighMem(page)); + if (swsusp_page_is_keys(page)) + return NULL; + if (swsusp_page_is_forbidden(page) || swsusp_page_is_free(page)) return NULL;