From patchwork Fri Aug 12 17:52:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 9277557 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 8CB6660780 for ; Fri, 12 Aug 2016 17:53:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81C1328A7E for ; Fri, 12 Aug 2016 17:53:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 75E4728ACA; Fri, 12 Aug 2016 17:53:28 +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 97AA928A7E for ; Fri, 12 Aug 2016 17:53:27 +0000 (UTC) Received: (qmail 24073 invoked by uid 550); 12 Aug 2016 17:53:26 -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 24042 invoked from network); 12 Aug 2016 17:53:23 -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=to3/N3O5b1Zo/r6r1UF7fYgxxxBB8jJpXF8D8X+EWc4=; b=I5Zyjsone8WgIVtCv6Ch5zeILO9U+LQZuNrzdcPKymiT8Ez2N62OWmRR++sR8FmEMD ao7KBI9mAO112GYSyQDxMC9ga2+3Q2gyKrNmgQBLVTYy24nFZpakOXYVt2XpMj4X/7b5 lAjvmmvyvfI4vVRLdLUoqbbbUKdujhVm9m63YSaPtAfjIv0xzWk6CsDk/1hy6NVlN4f6 CoqEAptzTOVEjte3VErfd/f6BaPWT/H+BF9e7V3e1MSHyw5u9+LBqC4Sy6aubLj33LQ+ ieotSkfKDwUnjRUy5P6P3z5Au/RtmqfY4QYi3r5CZR0MVn8z7tU0lRKoS0cHt4H13Ajv UqTw== 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=to3/N3O5b1Zo/r6r1UF7fYgxxxBB8jJpXF8D8X+EWc4=; b=HyWOjgTIBO0J4qqR/kb668RhnHpmF+dyuUp7Gre8o12wB042+V7bPWQV+VzWEEn2Fl Y8Svsn5QpVWtc05LgRnzOjV64d2eLoFMmADFp1eWkuN3bmLW8ZLvYmMBQiOpgX0ZPij1 aXvAJQqlYJ5PPj/HeQqGpbumY9hQF7xtIcC+7aDReVZsfHoo6wOAqur1PY5NZh4bg2da qtUQXlva0lnD44JolDsPOOF0I83/6CDD3+opAngcHE7T1HhP9r02d+qK6Tmd4m+yrEKu 26P3cnMl+VGFDxzb/z7LtNk5R6hEjaiaZEIcoBxNxHaEkzczmRlwFh2UcxUYQGIhdXdF r73Q== X-Gm-Message-State: AEkoouuza1Hn/qydAML/JVC8IS6XKgMM1WQs9cJN74tWyAjxP3VYOZLxP+8+S2uqMzJ835nB X-Received: by 10.98.111.133 with SMTP id k127mr29066734pfc.90.1471024391779; Fri, 12 Aug 2016 10:53:11 -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: Fri, 12 Aug 2016 10:52:44 -0700 Message-Id: <1471024364-46217-1-git-send-email-thgarnie@google.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 Subject: [kernel-hardening] [PATCH v2] 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. Reported-by: Jiri Kosina Tested-by: Jiri Kosina Acked-by: Pavel Machek Reported-and-tested-by: Borislav Petkov Signed-off-by: Thomas Garnier --- Based on next-20160808 Thanks to Rafael, Jiri & Borislav in tracking down this bug and help testing this fix. --- 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;