Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3420735rdg; Tue, 17 Oct 2023 14:23:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGKxidAkQfj5tbayirCWVz2CoTC9kL8vkkqHbqmVbrOdIZJWVru3M1uuEUY0GaKD395uJ9Y X-Received: by 2002:a17:903:2443:b0:1c3:83e2:d0a9 with SMTP id l3-20020a170903244300b001c383e2d0a9mr4311826pls.58.1697577834616; Tue, 17 Oct 2023 14:23:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697577834; cv=none; d=google.com; s=arc-20160816; b=OJxBnsDWbkJE/WqMDo7yrnXSKWXxJL637rOkJ7PjMgWomdqAaSLmI/Vzu+IEyx7WAC UVmpB9RHVccVf7QMChJIUeecIm5EYqjVJuMDPicRruJo9JwewL434izvF9v7d7L0PuVO lhF501J/ty080HG3G3tIIR8CMoUe7nBHTPYuwX063z4XfCe4X+J/lCzU+Ozp/sjGlyTh Y6RTqWBGTERvIq6buzfxaJ/DHcrDnetPlPR8tkTqjTDJg+kl5yxp7wuBRBKxYKWvfg32 7T6rkRedSxKWPB5hHBznl6aDWhd9tiq3gBUUe6SYwPYPLo1RMFXf/eqq9BLSQBOv2Cva AEsQ== 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 :dkim-signature:dkim-signature:message-id; bh=n70P7VXoQvos+tvoARg8YdC357P9bzhzxWof3PMYpTE=; fh=8iy+GLBXZdpcs/hIddJ7mbUapYjefwP9Gb111pAzFms=; b=NBQsWwyG8md2ZNaSYL/KZb1WgmKSiKJpQPXhATktAx3xVUuYk5G5ps1OAA5sSn2zOB Z/VTdrGeL+++cNIytyojZ71R/Jtdl77O5L+SVtxwLXaTbDoWxF7afYiXNYooAH4vfrWo De+zRYUP1XWi5CmCNllXWr+yAVq53yBWZOL5c7hN9MJsi3+wxuzAiTOz5/aquMtkWDud QA9RnDjvm9cFnWeUcH+Xy69QR2NnWRMrK/fKQE4FMFagx308uqt54taD56Z6sFc2A1D3 jnWT/O28o8V1lEfgkCFAtbi8oiGEJi7ij8JOIVBmdc2ZDmiqVxGrG8hEyFXU1RgX2Dsk o8/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="SMiNeiQ/"; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id l8-20020a170902f68800b001ca86a9caa9si2687797plg.582.2023.10.17.14.23.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 14:23:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="SMiNeiQ/"; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 74CA480F5F20; Tue, 17 Oct 2023 14:23:49 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231868AbjJQVX2 (ORCPT + 99 others); Tue, 17 Oct 2023 17:23:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbjJQVX1 (ORCPT ); Tue, 17 Oct 2023 17:23:27 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F120BC6 for ; Tue, 17 Oct 2023 14:23:25 -0700 (PDT) Message-ID: <20231017211721.990580849@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1697577804; 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=n70P7VXoQvos+tvoARg8YdC357P9bzhzxWof3PMYpTE=; b=SMiNeiQ/s5oDUwUUum5Ddfk05cPTUzZ9hQ0/GGHgxHg7XNiRULFTZZLx/UV1T/mkXRg3+a l6Bt4nphPW74/KaLOmlzYQvOS7yxpwjCegmYO1qalPNi4z664GPqqWz8rTdRYrtsk3MxmE BYVpYCAiL0CSri49W/gtolPX/uCsPkpRL8uSFddlp9/rXjePhfv/g6cM0elfbIo3e1o9r2 imh7keXzYplj9O7BUU8G+tr8FSc5afnMDi+EJ3o05IyVgqK1ScRHmzF5zYGFDXFqbTo8yP jdmY03p5K8VMRlgM7wwSo9zHjXpU1qo55yKI0nzmMSh/Sp8FiRAgthJwzqo+9Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1697577804; 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=n70P7VXoQvos+tvoARg8YdC357P9bzhzxWof3PMYpTE=; b=DjuZ02UuiZWrwZnoPFeH+9FGXmbZYNkaFE2Sak5Pub59YwvW8sTdMA1ZK2Ij+vmtekXVo+ 2a45mX6csMbvd7AQ== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Borislav Petkov Subject: [patch V5 01/39] x86/boot/32: Disable stackprotector and tracing for mk_early_pgtbl_32() References: <20231017200758.877560658@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Tue, 17 Oct 2023 23:23:24 +0200 (CEST) X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 17 Oct 2023 14:23:49 -0700 (PDT) From: Thomas Gleixner Stackprotector cannot work before paging is enabled. The read from the per CPU variable __stack_chk_guard is always accessing the virtual address either directly on UP or via FS on SMP. In physical address mode this results in an access to memory above 3GB. So this works by chance as the hardware returns the same value when there is no RAM at this physical address. When there is RAM populated above 3G then the read is by chance the same as nothing changes that memory during the very early boot stage. Stop relying on pure luck and disable the stack protector for the only C function which is called during early boot before paging is enabled. Remove function tracing from the whole source file as there is no way to trace this at all, but in case of CONFIG_DYNAMIC_FTRACE=n mk_early_pgtbl_32() would access global function tracer variables in physical address mode which again might work by chance. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/Makefile | 1 + arch/x86/kernel/head32.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) --- --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -16,6 +16,7 @@ CFLAGS_REMOVE_kvmclock.o = -pg CFLAGS_REMOVE_ftrace.o = -pg CFLAGS_REMOVE_early_printk.o = -pg CFLAGS_REMOVE_head64.o = -pg +CFLAGS_REMOVE_head32.o = -pg CFLAGS_REMOVE_sev.o = -pg CFLAGS_REMOVE_rethook.o = -pg endif --- a/arch/x86/kernel/head32.c +++ b/arch/x86/kernel/head32.c @@ -70,7 +70,8 @@ asmlinkage __visible void __init __noret * always zero at this stage. */ void __init mk_early_pgtbl_32(void); -void __init mk_early_pgtbl_32(void) + +void __init __no_stack_protector mk_early_pgtbl_32(void) { #ifdef __pa #undef __pa