Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1642958ybg; Thu, 4 Jun 2020 15:22:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6LbyzsmUyO3CO/9W0Zdz7E/08z6oz0mX2ZeE+qwlJQqtSIs0OMj7RcN0V3rX5J8BSHieM X-Received: by 2002:a17:906:1947:: with SMTP id b7mr5629696eje.320.1591309328712; Thu, 04 Jun 2020 15:22:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591309328; cv=none; d=google.com; s=arc-20160816; b=zrl5Fa1Sm3Ce6ZUfBl/7Bplf+NjnTPLrGXy4zGMMYVLRfw+x9JkD2V5lEhMSP+Pu8+ WgxvZxpH6gRZCe01NMlHHkRN226JlsxP8jeKQCH5wr5T030SUUX/8mDLoqFnjraTn4Vw Ldm77Xc8ObR3kGALzTXrHp0g10GR8HbHlEWYHrtX/kD6Lt4L4roR0hL1yygPFiZBH3cg ZjelEidAJSgBBxmIHw1xKTU3P6cmm6Ref9sDRNN9RteDP+uwNQ6G2XXEYn2iG9CbyqEG 5y6trtuxe5vepPPcdBKMiMytGoeu9RJMKJZtHws1yBBx0SUF+aHoKmy9/9BggaBqBhDG qulg== 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=ZIRXhR4auj5+SLQ7LtgQ61NpxJugv/PsvX/WpFw/ob0=; b=XEKdVwQICHG97Ltak5RKjzlqEQ1n9yfB7lws+4IgPWUSw+dyiGMvTE8MJKFuWBYiLo 4A63/xvP7ytTD7F/gk9xrPV/6/IZyfZuCa+NrKudG/B4KC2hPsd1lgn43eVTDTRxmIK5 oZlI941VNeAIZv1MD7ZZKP7Ne4mCAwl9lor3ibsFNtRjMecHw/hlWdfNJ7QRwcDeQvSd Lt2xXAGRgOgNfmH5O8tdC27oAQBeGYwjHohHOSOpCWYCq1bqTInz34TtY+oOUVhgS/+4 SbkufSqIIZaAe/QAN4xqYwYVSXpAMTJg6zphgEvwDyI8mcdjA7pr71GvxhBBcBG0SDzd 0/eA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ZrnH4OEF; 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 a7si2363149ejy.133.2020.06.04.15.21.31; Thu, 04 Jun 2020 15:22:08 -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=ZrnH4OEF; 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 S1728910AbgFDOES (ORCPT + 99 others); Thu, 4 Jun 2020 10:04:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728496AbgFDOER (ORCPT ); Thu, 4 Jun 2020 10:04:17 -0400 Received: from mail-io1-xd43.google.com (mail-io1-xd43.google.com [IPv6:2607:f8b0:4864:20::d43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 701C6C08C5C0 for ; Thu, 4 Jun 2020 07:04:17 -0700 (PDT) Received: by mail-io1-xd43.google.com with SMTP id d7so6449561ioq.5 for ; Thu, 04 Jun 2020 07:04:17 -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=ZIRXhR4auj5+SLQ7LtgQ61NpxJugv/PsvX/WpFw/ob0=; b=ZrnH4OEFeXvjY7mP/ObdOSwchqQN16o0HIcF6buLn9exAq9bBI/5MsABF7cQbgEJho OR/BDqs5KPZUFVf3ojhsB8cr5bdM3rAar4fGTU30I8iAdq8h7lUSUC9wpY0wFmp3X+hD BUZnifFx3qH4R9ikjcSytq8HT2gd8DfEFplDfjy1mYzicOgupjRK5IDpJOg4u26AEFEK xNf8ESO6GTNAf1SWahl8RzqZbiQbEBzeqt/LO4Rl9EGpkJSbJdFSOf1hefgk29CndNug yJIIza3Or1Cv+XcdvtkXnTsFZaDgOkh5lvumqRZYmg98QekkA9MLxid2OLViWu/RarC7 6jgg== 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=ZIRXhR4auj5+SLQ7LtgQ61NpxJugv/PsvX/WpFw/ob0=; b=PO3tPqXxVwoY9HL4u2OvPWL4ccQ2/hW6DHb2zvCzza5X3YtlEfiqyWZKBhf0vQCvx9 l8+yEsppLjHPkdMB5h+nvwgb14/ljbzusYEVoF2jHKDAm9jbBeoctevpscWwxkLXpatN gkiE3MfJYy4Onre/1fJb2U6WNmkJsS2jWDAdR5k86SrW2P5sKXj3cqHO1hOyg0giSTDL f9l4uJtxUME8h0sXlEnup/rc94pZWV17NQhoxYeuMiJ7T83eeKhCIcc4kZEPuOb8iu1A 7BgWKDXX2pu9311Ja861gUD74ch8xPcnZoHlWaw79YWXmjOPvdnTerbtq5YBR54u3KP0 nukQ== X-Gm-Message-State: AOAM531EyTtXIu0B/WswHC/GtqUYBADQ0GEjsTqDN5sQtu2U+hALQw+f Ipy/XcWT57rFZVjN8xgUQWwr0dVkAw== X-Received: by 2002:a6b:d104:: with SMTP id l4mr4236706iob.65.1591279456378; Thu, 04 Jun 2020 07:04:16 -0700 (PDT) Received: from localhost.localdomain (174-084-153-250.res.spectrum.com. [174.84.153.250]) by smtp.gmail.com with ESMTPSA id l3sm2342439iow.55.2020.06.04.07.04.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 07:04:15 -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 , Peter Zijlstra , Brian Gerst Subject: [PATCH] x86/stackprotector: Pre-initialize canary for secondary CPUs Date: Thu, 4 Jun 2020 10:03:59 -0400 Message-Id: <20200604140359.560797-1-brgerst@gmail.com> X-Mailer: git-send-email 2.25.4 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 --- arch/x86/include/asm/stackprotector.h | 12 ++++++++++++ arch/x86/kernel/smpboot.c | 12 +----------- arch/x86/xen/smp_pv.c | 2 -- 3 files changed, 13 insertions(+), 13 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 2467f3dd35d3..dad7f9ca6478 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -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 ae4d0f283df3..e9f5d6ec30a6 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: cc7a4a02564c6cc8dc981fb0a37313830ee8c2d4 -- 2.25.4