Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp853410ybt; Wed, 17 Jun 2020 16:01:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZ0uR8vT+CBy+HyCyRn3I/Q/0feJl81rupzNH4ukjAJQnCJ3T6PeWQ0E1vbhvrcLQB5rjr X-Received: by 2002:a17:906:4989:: with SMTP id p9mr1362452eju.417.1592434903367; Wed, 17 Jun 2020 16:01:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592434903; cv=none; d=google.com; s=arc-20160816; b=bfJAicYyCu+eBNlfi1sRLFR7gNpCX7ypEqSZfNbdNKLuJERRDG0GJJAPAnv5rc8yLh 8jvm2gMUc0oWBBCsrmsqNN7RIvGxavJyKyogaftUScFtvma2YNLpYQa7yLw/EQigwZpd IKFn92GBElYNI11l+UBWEkOh2VqQZ6/p0wBhDaE6F0C8jDp/PtG2BWwZN6DEpFz1Ehwv MV2XbibLhmgjaB2HsluiMsI/gmpYV2LUyvB4Wfhs6Wy/jsJo8+Z07iUfh/0HAHQegBgF HfMaVqEPmIWgbSLU4uO5B5r2X0HuNHJiIN5TDQe1aplDcAzAwEBIZ539T9cvvau3yBxo qhBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=yv49H7uS1jQIlHtyWd5igfCbIiLW1NAeICkJXu9JDUc=; b=0HD1bv6biWA64e7+bNxjO/ay3qHu4Mc9BSXiUYeQZHGwunFR5vXpr+Ar+6IuZEh21k 4O46K09xTFg0TvNWnLbNrPX5tChHYBb4muY8346DZ6WJnNDbKMg+adj9KbWvGEZmEIye LK+IyV6BcUuEUXAjlBZtcBfLN+gNfk+zykA+08emWt9A9YIqwc3h9hRuLKS9zowbX8j5 JIxA2OGoteDGhtJZHAbqAcnPBcEY8Q0UTq1q68VQaddZ4yehgneHJTwTpSEoqYhfBiyC ffimZIUw/NCR6nJUzyAd7343O6q38gdEDbb2u9TIBlS1Kq4FIVBf/3xEHSRnbOGhRMAZ L5zQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=AqPy4fhj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g21si752920edj.35.2020.06.17.16.01.20; Wed, 17 Jun 2020 16:01:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=AqPy4fhj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726930AbgFQW4d (ORCPT + 99 others); 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-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