From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06145C433E0 for ; Wed, 17 Jun 2020 22:56:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D37F021548 for ; Wed, 17 Jun 2020 22:56:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AqPy4fhj" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726950AbgFQW4d (ORCPT ); Wed, 17 Jun 2020 18:56:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726840AbgFQW4d (ORCPT ); Wed, 17 Jun 2020 18:56:33 -0400 Received: from mail-il1-x142.google.com (mail-il1-x142.google.com [IPv6:2607:f8b0:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7E1EC06174E for ; Wed, 17 Jun 2020 15:56:31 -0700 (PDT) Received: by mail-il1-x142.google.com with SMTP id z2so3995143ilq.0 for ; Wed, 17 Jun 2020 15:56:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=yv49H7uS1jQIlHtyWd5igfCbIiLW1NAeICkJXu9JDUc=; b=AqPy4fhjZbTaSYGqujOcDPRyiVqGk9qiiBNmIVkOJXQe2xRN+nvQEwLDLR6z1vw1Z4 ugzTAjfOSDvt6wotmz0VNnWdOFOVxRnaKXApHWrWWjz3M+g9QAflMfRIcuoGQGqoQVwv JjwLAcaufFkiT6OPE/Z1iI2k245GY4iG6c7f5e/+bB8n3/+lHzed0iPWBqj/4YAtDwIu jaKt+OZduUaWwUaW+ioBkezC6vLxKK37gIbEYNSmly08wNunXVMvHof+raVL0lSRkQ2h +OFQyghLsIzrTTBZ+cTd805ZX3SRE/Ju9jqIyTzPpjg73bpFYLI2JVb3POCVRjntRb6j HKgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=yv49H7uS1jQIlHtyWd5igfCbIiLW1NAeICkJXu9JDUc=; b=O4lDeaWXi1T1SIUEp/Lj7WK2niUNCCWT5fmk22qzh6VaJ6BouR7K6JpTGx5lv1sDih 0h1Q5HL1F4gCbN3ffvW5/AH5gy3On5ng24xNJ/O+0BXrsu98YCmz7D3ZZMpwYA7myONj xVi4gbrt0nRmXIpFf7CXU+oZjty+U6FNJYz3ltRcm0FPPG5ApbfimEnHstfyRqCU894G BVl0qU/SsIXy+jNz9Uc7rfkcUutsCcgDqb9HiEFyEBddZ6Lj+vhVSIjoaoG+J8x1ru2j yI0SGaIinCVabVL14X3qhIITgtltjKmbWeSVgm8RweVsTFvxrzJLl3mWMSrVLDp+wulp y7+g== X-Gm-Message-State: AOAM533uUJqjEz3nxFr7vSqWUEYHfMmCcxM0bmT+1p6Gyr6l+lyL3IAH +WM37PBDTmX+O5rzCi/S6e8vEIVBMw== X-Google-Smtp-Source: ABdhPJyDsY6SC7aAEyEkelkI5tBlBanFy1+zAcaEf/TR3a2+TDopRpL8D2ttMFQo8I+GVddyQAPBMg== X-Received: by 2002:a05:6e02:128a:: with SMTP id y10mr1360552ilq.134.1592434591013; Wed, 17 Jun 2020 15:56:31 -0700 (PDT) Received: from localhost.localdomain (174-084-153-250.res.spectrum.com. [174.84.153.250]) by smtp.gmail.com with ESMTPSA id t28sm596749ilb.49.2020.06.17.15.56.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jun 2020 15:56:30 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , Andy Lutomirski , Brian Gerst Subject: [PATCH V2] x86/stackprotector: Pre-initialize canary for secondary CPUs Date: Wed, 17 Jun 2020 18:56:24 -0400 Message-Id: <20200617225624.799335-1-brgerst@gmail.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The idle tasks created for each secondary CPU already have a random stack canary generated by fork(). Copy the canary to the percpu variable before starting the secondary CPU which removes the need to call boot_init_stack_canary(). Signed-off-by: Brian Gerst --- V2: Fixed stack protector disabled case arch/x86/include/asm/stackprotector.h | 12 ++++++++++++ arch/x86/kernel/smpboot.c | 14 ++------------ arch/x86/xen/smp_pv.c | 2 -- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h index 9804a7957f4e..7fb482f0f25b 100644 --- a/arch/x86/include/asm/stackprotector.h +++ b/arch/x86/include/asm/stackprotector.h @@ -90,6 +90,15 @@ static __always_inline void boot_init_stack_canary(void) #endif } +static inline void cpu_init_stack_canary(int cpu, struct task_struct *idle) +{ +#ifdef CONFIG_X86_64 + per_cpu(fixed_percpu_data.stack_canary, cpu) = idle->stack_canary; +#else + per_cpu(stack_canary.canary, cpu) = idle->stack_canary; +#endif +} + static inline void setup_stack_canary_segment(int cpu) { #ifdef CONFIG_X86_32 @@ -119,6 +128,9 @@ static inline void load_stack_canary_segment(void) static inline void setup_stack_canary_segment(int cpu) { } +static inline void cpu_init_stack_canary(int cpu, struct task_struct *idle) +{ } + static inline void load_stack_canary_segment(void) { #ifdef CONFIG_X86_32 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index ffbd9a3d78d8..a11bd53c6911 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -51,7 +51,6 @@ #include #include #include -#include #include #include #include @@ -80,6 +79,7 @@ #include #include #include +#include /* representing HT siblings of each logical CPU */ DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_sibling_map); @@ -259,21 +259,10 @@ static void notrace start_secondary(void *unused) /* enable local interrupts */ local_irq_enable(); - /* to prevent fake stack check failure in clock setup */ - boot_init_stack_canary(); - x86_cpuinit.setup_percpu_clockev(); wmb(); cpu_startup_entry(CPUHP_AP_ONLINE_IDLE); - - /* - * Prevent tail call to cpu_startup_entry() because the stack protector - * guard has been changed a couple of function calls up, in - * boot_init_stack_canary() and must not be checked before tail calling - * another function. - */ - prevent_tail_call_optimization(); } /** @@ -1011,6 +1000,7 @@ int common_cpu_up(unsigned int cpu, struct task_struct *idle) alternatives_enable_smp(); per_cpu(current_task, cpu) = idle; + cpu_init_stack_canary(cpu, idle); /* Initialize the interrupt stack(s) */ ret = irq_init_percpu_irqstack(cpu); diff --git a/arch/x86/xen/smp_pv.c b/arch/x86/xen/smp_pv.c index 171aff1b11f2..9ea598dcc132 100644 --- a/arch/x86/xen/smp_pv.c +++ b/arch/x86/xen/smp_pv.c @@ -92,9 +92,7 @@ static void cpu_bringup(void) asmlinkage __visible void cpu_bringup_and_idle(void) { cpu_bringup(); - boot_init_stack_canary(); cpu_startup_entry(CPUHP_AP_ONLINE_IDLE); - prevent_tail_call_optimization(); } void xen_smp_intr_free_pv(unsigned int cpu) base-commit: 83cdaef93988a6bc6875623781de571b2694fe02 -- 2.26.2