Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3648298imw; Mon, 18 Jul 2022 11:55:49 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sGPt5oht1eB9mBMm8COBh5B6DmYggIs3vnWEscySx3yqFa4aFBMiyyJ1F2Y3u2ddjrYNPF X-Received: by 2002:a17:907:7ea6:b0:72b:4afb:e8b with SMTP id qb38-20020a1709077ea600b0072b4afb0e8bmr27362042ejc.205.1658170549134; Mon, 18 Jul 2022 11:55:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658170549; cv=none; d=google.com; s=arc-20160816; b=B/4jso+nHmEOhHNTiLJcbAvUTwZdcoj9/OV3QWi6olJrM9VT7arO0A935v5KjXZSHF sNbAVpoAKna7VO2UHM4vHAoNGr8ayfaEtfHyxe6QmHPEnLMKmXpP6x/Q6Pio7yoRLsio bcXaC5pEuq3tL6SdhYeC1zGHNftRD2ALXc1IW8nUnYAwLPUohiRXVoC38XSLvBcordH7 rsuS0JGL4DtoZBm2+g3mNo++yrFK4ZgV6LOzKWGkD6kth3+U4XgBgGu4m28tCoduK+Xa fuISKtByIhMuoqgnafZ+Ak3EBO/p3mnXcmD9p4nOweQHnrJwvfQgEbwtEMCKhPLugLZL iBvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :2message-id:dkim-signature:dkim-signature:message-id; bh=vwqP5WUQAW1xn/6amUsV88j6aSa5liouTB2QQnE3Fc8=; b=lnLG1VtHMz9v2r8VLE0d2MSqpB3ql3FKLlYbIG122olJbFJuiTQl5gPbQsGEnaFZIv UVuhw02TxJlLCCs88Pt/wMyfTcdrap+g4Gk3s2Tt8Rd/6ytU94AN3QcbNojaD9LwOIWr PaYBJ6xM85qyESWcsBP/FfsGtYEvdnfArnonRdDYNohF4LLVqejJ/q/nlsgxQ0UopYIn aiUYvtGmIcz9eSy8oVeKuMTSsWy+ZiVQKPKlHgLJMRNkbeEMqJkhRew1Mi5lf2QC53j1 om5STytlOkgPjR/GI60x2oiC/6LkHXBELu/I5HcBIqE6Ie4bDyWwR5lOIgBAhul/Xuy1 GVjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=IvWSNBdD; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o20-20020a170906975400b0072f2cf8fd19si5296910ejy.854.2022.07.18.11.55.23; Mon, 18 Jul 2022 11:55:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=IvWSNBdD; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233962AbiGRRwU (ORCPT + 99 others); Mon, 18 Jul 2022 13:52:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233607AbiGRRwO (ORCPT ); Mon, 18 Jul 2022 13:52:14 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 222482D1D0 for ; Mon, 18 Jul 2022 10:52:14 -0700 (PDT) Message-ID: <20220718173924.009884744@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1658166732; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=vwqP5WUQAW1xn/6amUsV88j6aSa5liouTB2QQnE3Fc8=; b=IvWSNBdDb5mdn80M75hd8rLfVq9C/fwAm2s4aT1ecYap8AuceJ6PdhqUM6+d0QBqRP0b6a zbRFvXizHpm8vDoBdCttiFsR/MpcXN1xJSsbjx7st821GETEzz90+4JSGOx5HcmBmcPy/V +YWhE93cZJalQ3qe6jo25VyA0hIx2tB6KoQ3s+Bd3OzIxSZZI2XeUEdNsJfKrAdPLFxyBS jvQWHMGLZWCGcChM4VBFBRV8tel275c4y6BOM680vmLOegcBx+WqMOI+r66ekBZu0QViNN bj8vF0K9NsQB5UqLQ18BUUm0mCjs4aCgwnCDodGeol/7QmW6UuRE0zd5Xmpd1A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1658166732; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=vwqP5WUQAW1xn/6amUsV88j6aSa5liouTB2QQnE3Fc8=; b=1vt93dIYdDTRge1q76xZK2RqhjiYa+tqAkLTZDgal9z1PELjA+lSR7fErTZFfl5phoLG56 55hT+xg/tTPUXdCw== 2Message-ID: <20220718173814.731702240@linutronix.de> From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Linus Torvalds , Tim Chen , Josh Poimboeuf , Andrew Cooper , Pawan Gupta , Johannes Wikner , Alyssa Milburn , Jann Horn , "H.J. Lu" , Joao Moreira , Joseph Nuzman , Steven Rostedt , Juergen Gross , "Peter Zijlstra (Intel)" , Masami Hiramatsu , Alexei Starovoitov , Daniel Borkmann Subject: [patch 3/3] x86/cpu: Re-enable stackprotector References: <20220716230952.787452088@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Mon, 18 Jul 2022 19:52:12 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit 5416c2663517 ("x86: make sure load_percpu_segment has no stackprotector") disabled the stackprotector for cpu/common.c because of load_percpu_segment(). Back then the boot stack canary was initialized very early in start_kernel(). Switching the per CPU area by loading the GDT caused the stackprotector to fail with paravirt enabled kernels as the GSBASE was not updated yet. In hindsight a wrong change because it would have been sufficient to ensure that the canary is the same in both per CPU areas. Commit d55535232c3d ("random: move rand_initialize() earlier") moved the stack canary initialization to a later point in the init sequence. As a consequence the per CPU stack canary is 0 when switching the per CPU areas, so there is no requirement anymore to exclude this file. Add a comment to load_percpu_segment(). Signed-off-by: Thomas Gleixner --- arch/x86/kernel/cpu/Makefile | 3 --- arch/x86/kernel/cpu/common.c | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) --- a/arch/x86/kernel/cpu/Makefile +++ b/arch/x86/kernel/cpu/Makefile @@ -16,9 +16,6 @@ KCOV_INSTRUMENT_perf_event.o := n # As above, instrumenting secondary CPU boot code causes boot hangs. KCSAN_SANITIZE_common.o := n -# Make sure load_percpu_segment has no stackprotector -CFLAGS_common.o := -fno-stack-protector - obj-y := cacheinfo.o scattered.o topology.o obj-y += common.o obj-y += rdrand.o --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -751,6 +751,9 @@ void __init switch_to_direct_gdt(int cpu * wrmsrl() happens the early mapping is still valid. That means * the GSBASE update will lose any prior per CPU data which was * not copied over in setup_per_cpu_areas(). + * + * This works even with stackprotector enabled because the + * per CPU stack canary is 0 in both per CPU areas. */ if (IS_ENABLED(CONFIG_X86_64)) wrmsrl(MSR_GS_BASE, cpu_kernelmode_gs_base(cpu));