From patchwork Thu Mar 23 00:27:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9640295 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 13E6C601E9 for ; Thu, 23 Mar 2017 00:27:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0315C25D9E for ; Thu, 23 Mar 2017 00:27:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E980F26E5D; Thu, 23 Mar 2017 00:27:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 74C4A25D9E for ; Thu, 23 Mar 2017 00:27:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755140AbdCWA1G (ORCPT ); Wed, 22 Mar 2017 20:27:06 -0400 Received: from mail-pg0-f42.google.com ([74.125.83.42]:33662 "EHLO mail-pg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755078AbdCWA1F (ORCPT ); Wed, 22 Mar 2017 20:27:05 -0400 Received: by mail-pg0-f42.google.com with SMTP id w20so11850781pgc.0 for ; Wed, 22 Mar 2017 17:27:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=i3HZanVR6mKpwCSgmjYqYnf31QkOVk1X4vcU9dWeoKA=; b=f31KBKBFzJyvKAMt4WluQW0Vi1gL3Wk68H5NV1h5mlyjnMPDmr9S1ED3mK05b8qlYU JfugAsYVChDGG1Wxmz0keRYfAPDMWRdBpcuUwshwnohmPGxC8XG1+Wd26kmR5/eeDnFN yDgPJ4mlcrGJqtU0Q3KMNTqJXCCqLPVZzXPnI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=i3HZanVR6mKpwCSgmjYqYnf31QkOVk1X4vcU9dWeoKA=; b=mPl/OtA6yJJ2qUsNGWqBfQMAcO3r6LhfC9/w964V61fWW95yZ0xktFn5luu2ZTRTjh 8vbpwTzljjK5ACr8tCZoGaNR8itAiaoM3Nn/yDXZ3GShzIUxUwdRnILogb6+4T+n+vhQ +Lf8ZuLZOsYKrsFfjGpGFuP41gw9EUJ+PBCGYa1BMzaBudqVfuFGeYIFm5YFDPfYq2tM sQafG5f95Y5VloLmt872vfeyx+feHvNGUvyktbul0EE9SNnP02eo+eeHH0cKBimCWMQN DQf3FffZSYxcPgBGlEZ5IdboFzyUkwX6c0lLrznWNmQx2m1AljFakdY6+Gw1JUxzXrgj 9cKw== X-Gm-Message-State: AFeK/H3VbEaGjk0bHcLQEGqsOgn7BJlGG/Ufy9Wmw/OV0dBhiqTaGTYfkn29e1ozj2SfxIno X-Received: by 10.84.149.168 with SMTP id m37mr57701166pla.97.1490228824503; Wed, 22 Mar 2017 17:27:04 -0700 (PDT) Received: from www.outflux.net ([2002:ada4:7085:0:41a4:42:cf8f:74fb]) by smtp.gmail.com with ESMTPSA id c16sm6072080pfl.7.2017.03.22.17.27.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Mar 2017 17:27:03 -0700 (PDT) Date: Wed, 22 Mar 2017 17:27:01 -0700 From: Kees Cook To: "Rafael J. Wysocki" Cc: Pavel Machek , Evgenii Shatokhin , linux-doc@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, "H. Peter Anvin" , Thomas Gleixner Subject: [PATCH] hibernation: on 32-bit x86, disabled in favor of KASLR Message-ID: <20170323002701.GA90470@beast> MIME-Version: 1.0 Content-Disposition: inline Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is a modified revert of commit 65fe935dd238 ("x86/KASLR, x86/power: Remove x86 hibernation restrictions"), since it appears that 32-bit hibernation still can't support KASLR. 64-bit is fine. Since people have been running with KASLR by default on 32-bit since v4.8, this disables hibernation (with a warning). Booting with "nokaslr" will disable KASLR and enable hibernation. Reported-by: Evgenii Shatokhin Signed-off-by: Kees Cook Cc: stable@vger.kernel.org # v4.8+ Tested-by: Evgenii Shatokhin --- Documentation/admin-guide/kernel-parameters.txt | 5 +++++ arch/x86/boot/compressed/kaslr.c | 3 +++ kernel/power/hibernate.c | 18 +++++++++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 2ba45caabada..6f899c7f587d 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -1725,6 +1725,11 @@ kernel and module base offset ASLR (Address Space Layout Randomization). + On 32-bit x86 with CONFIG_HIBERNATION, hibernation + is disabled if KASLR is enabled. If "nokaslr" is + specified, KASLR will be diabled and hibernation + will be enabled. + keepinitrd [HW,ARM] kernelcore= [KNL,X86,IA-64,PPC] diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c index 8b7c9e75edcb..b694af45f1e0 100644 --- a/arch/x86/boot/compressed/kaslr.c +++ b/arch/x86/boot/compressed/kaslr.c @@ -572,6 +572,9 @@ void choose_random_location(unsigned long input, return; } + if (IS_ENABLED(CONFIG_X86_32) && IS_ENABLED(CONFIG_HIBERNATION)) + warn("KASLR active: hibernation disabled on 32-bit x86."); + boot_params->hdr.loadflags |= KASLR_FLAG; /* Prepare to add new identity pagetables on demand. */ diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c index a8b978c35a6a..1d8f1fe1b7f4 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c @@ -37,9 +37,14 @@ #include "power.h" -static int nocompress; +#if defined(CONFIG_X86_32) && defined(CONFIG_RANDOMIZE_BASE) +static int noresume = 1; +static int nohibernate = 1; +#else static int noresume; static int nohibernate; +#endif +static int nocompress; static int resume_wait; static unsigned int resume_delay; static char resume_file[256] = CONFIG_PM_STD_PARTITION; @@ -1194,3 +1199,14 @@ __setup("hibernate=", hibernate_setup); __setup("resumewait", resumewait_setup); __setup("resumedelay=", resumedelay_setup); __setup("nohibernate", nohibernate_setup); + +/* Allow hibernation to be disabled in favor of KASLR on 32-bit x86. */ +#if defined(CONFIG_X86_32) && defined(CONFIG_RANDOMIZE_BASE) +static int __init nokaslr_hibernate_setup(char *str) +{ + noresume = 0; + nohibernate = 0; + return 1; +} +__setup("nokaslr", nokaslr_hibernate_setup); +#endif