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: 9276065 X-Patchwork-Delegate: rjw@sisk.pl 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 141B26022E for ; Thu, 11 Aug 2016 21:50:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F11A2285FD for ; Thu, 11 Aug 2016 21:50:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E146B287B9; Thu, 11 Aug 2016 21:50:11 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 C3B41285FD for ; Thu, 11 Aug 2016 21:50:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752054AbcHKVuI (ORCPT ); Thu, 11 Aug 2016 17:50:08 -0400 Received: from mail-pf0-f181.google.com ([209.85.192.181]:34262 "EHLO mail-pf0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751900AbcHKVuH (ORCPT ); Thu, 11 Aug 2016 17:50:07 -0400 Received: by mail-pf0-f181.google.com with SMTP id p64so2342287pfb.1 for ; Thu, 11 Aug 2016 14:50:07 -0700 (PDT) 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=drBbfQ2bVLjlgeZxgEYcOXH6+yCRHiCEksr/oA6+jwpbT2htcpEtnRmUYX51wnankz tfWvbXtRl95fPKbDOvkiybtMfsSJ4XVToXUfoH/7YcYWgehFqCSLaOgL5wmaP0Gj0B34 +uCM8l5iQlyw0ccdDyj6IuGacx2oG8R8j8h0z4COIVMiXxobKcJhszO9YOuVvaNFSqAE MYzuWbeepLa0m2Nf0SpFVBZJhrfK9r1bTgDAmMDBVKSxw4zfYzGEsvy65aFCXA8eVZb7 JbKWMuzKxKjoKNL2+QAMJPq8I+rGuqtGNKvUdYGo5IkuFqYkSZvT8u3tiZLPNqxiNeb5 Palg== X-Gm-Message-State: AEkoouutBzaXtOXAOpti7L/+rd5/0x5h1/uluZg8o0/pB3S/D9T+9L0exU9iOL287X/UJMyT X-Received: by 10.98.28.142 with SMTP id c136mr21106058pfc.131.1470952207053; Thu, 11 Aug 2016 14:50:07 -0700 (PDT) Received: from skynet.sea.corp.google.com ([100.119.232.34]) by smtp.gmail.com with ESMTPSA id t7sm7543334paz.21.2016.08.11.14.50.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 11 Aug 2016 14:50:06 -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 Subject: [PATCH v1] x86/power/64: Restore processor state before using per-cpu variables 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 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 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;