From patchwork Thu Aug 11 21:49:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 9276069 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 162D96022E for ; Thu, 11 Aug 2016 21:50:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0AA53287AD for ; Thu, 11 Aug 2016 21:50:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F32E5287BB; Thu, 11 Aug 2016 21:50:24 +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=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id E3101287AD for ; Thu, 11 Aug 2016 21:50:23 +0000 (UTC) Received: (qmail 1727 invoked by uid 550); 11 Aug 2016 21:50:21 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: kernel-hardening@lists.openwall.com Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 1687 invoked from network); 11 Aug 2016 21:50:19 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=eon7mTOUVrtfhAHWk4cTFgk6nr0HCtbDkzby/3lsDFY=; b=d/yOn3TokwDkeaGKN+gK9cdnkuntQNmHZ8PiiaoleJGCHMCyRmB33qzcHeZxMMuFez m6BlZBmmLrl5bPcd0wyMbbuQd2WLJ3hFjAeSNMAwcVEaf6YGDARAIFyfAD+4AsVEtylB UqMgo8VODE4utfDp3CqA4SsQmdrljiCSdtq6GgadsY5ONTzpqvzY0nd+if7CVSunwOmq 5hE6g71VNs7yPkYFB78BI0hMpDxOBPUuNw8l0+kowjsksxn5nQoDmKJJsw7mXr+Qs3Sx h/PrwYK3LI15bO/blw2KcvaFQENq0h73+tr+EH9oWdfV1Z9X/grKLpfr7FXMD67LQS78 +MCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=eon7mTOUVrtfhAHWk4cTFgk6nr0HCtbDkzby/3lsDFY=; b=j/mhaaU59QJoZRv+Q56pvPuMxKbjUwnGw/ruxDNzOrGfJDUWXfrWNx2SMe467xCmHO Y44A5dqtAq6JbnPUyzURD/LKBYjDHRG0aHQSdRT3Th95NU62J2gS3v85BY5iLwD8wRG+ JoLsRONBQ+jl7AfX0l3b+A13ae3Wt7wGVaBB8T442XOCv1PKjyYBnfTw1Olb/pqv2wG8 bvuUkEzrnNOp8JdX+QY20M3zjeVTiP6TyYOyZiiteyD7DimKpseu+zLttWNPnmeNGQpS Ys911xq3LToYfnOxov15YwBVbXyBhRYmPYHQVwrs43n3BwAL8qe/LNMSSkK6nR3yGVH/ a4hg== X-Gm-Message-State: AEkoouvlshjgFMPWMXYsqhJQAOg/i4m48gSwel/DSuZkgMR/IFWQ4xNK1ZgTIjoj2gig3/fU X-Received: by 10.98.28.142 with SMTP id c136mr21106058pfc.131.1470952207053; Thu, 11 Aug 2016 14:50:07 -0700 (PDT) From: Thomas Garnier To: "Rafael J . Wysocki" , Len Brown , Pavel Machek Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, keescook@chromium.org, kernel-hardening@lists.openwall.com, jikos@kernel.org, bpetkov@suse.de, yinghai@kernel.org, Thomas Garnier Date: Thu, 11 Aug 2016 14:49:29 -0700 Message-Id: <1470952169-39061-1-git-send-email-thgarnie@google.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 Subject: [kernel-hardening] [PATCH v1] x86/power/64: Restore processor state before using per-cpu variables X-Virus-Scanned: ClamAV using ClamSMTP Restore the processor state before calling any other function to ensure per-cpu variables can be used with KASLR memory randomization. Tracing functions use per-cpu variables (gs based) and one was called just before restoring the processor state fully. It resulted in a double fault when both the tracing & the exception handler functions tried to use a per-cpu variable. Signed-off-by: Thomas Garnier Acked-by: Pavel Machek --- Based on next-20160808 Thanks to Rafael, Jiri & Borislav in tracking down this bug. --- kernel/power/hibernate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c index a881c6a..33c79b6 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c @@ -300,12 +300,12 @@ static int create_image(int platform_mode) save_processor_state(); trace_suspend_resume(TPS("machine_suspend"), PM_EVENT_HIBERNATE, true); error = swsusp_arch_suspend(); + /* Restore control flow magically appears here */ + restore_processor_state(); trace_suspend_resume(TPS("machine_suspend"), PM_EVENT_HIBERNATE, false); if (error) printk(KERN_ERR "PM: Error %d creating hibernation image\n", error); - /* Restore control flow magically appears here */ - restore_processor_state(); if (!in_suspend) events_check_enabled = false;