Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp1330541pxu; Thu, 8 Oct 2020 08:55:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyWPKNImDbeITCchr7G0yrvNbOGhTyHp7Qdao2f96IH5+G5THoOGqdnRPqUMJeZdAMKdofb X-Received: by 2002:a17:907:270f:: with SMTP id w15mr9162373ejk.505.1602172539783; Thu, 08 Oct 2020 08:55:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602172539; cv=none; d=google.com; s=arc-20160816; b=J3Btxvw0A5+q46GZE6A+nVWws1VrjEyIGMzTGCuXIRiaasB5ztz2u5OPxaOkV00N8E h/g6fZOpp1+SotS+wmFU5TvNCbM05p973G5qvNHC/1AqKxvKv0a9oaGs7U/JILFfzbp0 1FRzLZ4rB+sX0xu7wdokSzvuEUJ90xa1m7WCwKeTj+1et6hTnFadCprrJhR86i/jpvIi QE0Z7IjgWoZ6GNN1bi6bh9tM8teFfnQlcOEBat2ygkbVmvgdrgtKMyeHN96ZU6Pd3yhU ma19wrFterSgCt6ONmtF7GVgqRFMaj5COWggEUpI+g0rkFNWHkuIDmRJMKZaeEa9ra2v ZXPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:date:from:sender:dkim-signature; bh=ViQC4adlH6DM3wXlbVQ3zb3Oxu5Fu1Afsg8uzzNsK/Y=; b=d5J72Wa5YM/CtTp1iqGQan4nNE96mGYhZe5Z5rRgE3K8sWWxwuiy0U3ORMx52fa1rO Bsc49liuhBdgUskM3uWT7i8UF21h4fKUhgURNC24nK7bnTtpnyiC6E15geqmex4Pcnzf RHW50u5rPMz2qCOx6NhbeyWm/uxu7HuCln5Sjps8q+sAufqC/F8UBOgz4OeScMuGBvuh JNW3W+126u8BoWSiVT5UXTBQrB7ceiLUfk1cB0LlQuqx1BKnaQ/q0FQcZGlMnwyS03Hl 0TWj57AF9zHe4Z1yEuEWhGJbaMbAFH8DGSr8907lRhV6D/81faNKj4guCjU/lyUMYHia gB5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=POf30xef; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h7si4056975edt.471.2020.10.08.08.55.16; Thu, 08 Oct 2020 08:55:39 -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=POf30xef; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730725AbgJHOwQ (ORCPT + 99 others); Thu, 8 Oct 2020 10:52:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730721AbgJHOwP (ORCPT ); Thu, 8 Oct 2020 10:52:15 -0400 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E179C061755 for ; Thu, 8 Oct 2020 07:52:14 -0700 (PDT) Received: by mail-qk1-x743.google.com with SMTP id v123so7257810qkd.9 for ; Thu, 08 Oct 2020 07:52:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=ViQC4adlH6DM3wXlbVQ3zb3Oxu5Fu1Afsg8uzzNsK/Y=; b=POf30xef6TTw7lnoaxLDom81foreUnaPLzk1XnH/pPDXLSIIDekzinHxiapkVnN5LT ajc/+s8PZTUbXOVeqGx3pRaXQBd9QFkIx7FcMSuRtp+asDvuvTcoiHHBbLh7C6AP+sIJ /Qcb6khTjV+E9yfhR9+IJ79sM1xz3FLmyMygKw4Jc9M7Xt/qeXjUfUq8Cx0KYSDRvQ8B 1P4uMSL0ZxOOOPAB99loIVFsdymyCeeVd15jhazecjwEYzEwRe+8+p57yWEE1ZGo9TYo 7KbQqtr0IwkNSS9KGdhj/FafiH6HfPep/+yO4//JKzBhT489sN7GX3u7nN6MVlx+7vv8 mN4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:date:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=ViQC4adlH6DM3wXlbVQ3zb3Oxu5Fu1Afsg8uzzNsK/Y=; b=VmUKn6nrSaSCO56na8emBDU3+7qGxPzKvmmoBNsLbvHavU5mvWoywKktPdOiQlHFE1 8Ed2KuMQ99e4e47OAeegVOOgYYQigUKkvh/LybgI+xCj2OPgP8mKmkW7Q+bFVEj8Otg5 Gn73VqG5ev8eZ1qQ8kO8s6aqF5m6LY5shf6yXPBSoAsj4Vxzoq22+QS0dPuQYzXkNYEv PRiw0K/tbsTNDvYulnUUUGWWwcm0jIcc/RhDkyf0rB/kkElcbTRiLPb3DwXtP5szKxbY 2fa2CWU9XLZXrE7mhHw2jp1rN0PRdSFLYE/GIGRpYKyM1iNOgtqcQr+TArSz1QH75lAi 9RyA== X-Gm-Message-State: AOAM530NWLwARn89lY3lUskfGwuDphq+YxJ71KNDB7VpEn84RddjT8tm kj/EqA7W30uPaEaRuOQ+wH8GzGuzG81jAQ== X-Received: by 2002:a05:620a:22f2:: with SMTP id p18mr1317457qki.113.1602168733698; Thu, 08 Oct 2020 07:52:13 -0700 (PDT) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id t10sm4011091qkt.55.2020.10.08.07.52.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Oct 2020 07:52:12 -0700 (PDT) Sender: Arvind Sankar From: Arvind Sankar X-Google-Original-From: Arvind Sankar Date: Thu, 8 Oct 2020 10:52:11 -0400 To: Joerg Roedel Cc: Arvind Sankar , x86@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 5/5] x86/head/64: Disable stack protection for head$(BITS).o Message-ID: <20201008145211.GE2429573@rani.riverdale.lan> References: <20201007195351.776555-1-nivedita@alum.mit.edu> <20201007195351.776555-6-nivedita@alum.mit.edu> <20201008084219.GC3209@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20201008084219.GC3209@suse.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 08, 2020 at 10:42:19AM +0200, Joerg Roedel wrote: > On Wed, Oct 07, 2020 at 03:53:51PM -0400, Arvind Sankar wrote: > > On 64-bit, the startup_64_setup_env() function added in > > 866b556efa12 ("x86/head/64: Install startup GDT") > > has stack protection enabled because of set_bringup_idt_handler(). > > > > At this point, %gs is not yet initialized, and this doesn't cause a > > crash only because the #PF handler from the decompressor stub is still > > installed and handles the page fault. > > Hmm, that is weird. Can you please share your config with which this > happens? I have a commit in my local branch which disables page-faulting > in the pre-decompression code before jumping to the uncompressed kernel > image, and it did not break anything here. > > Also, what compiler did you use to trigger this? > The compiler is gcc-10. QEMU usually puts the command line in the low 1Mb, so it needs to avoid accessing the command line as well, as the stack canary is at 0x28. So defconfig with AMD_MEM_ENCRYPT enabled RANDOMIZE_BASE disabled EARLY_PRINTK disabled crashes on boot if you disable the #PF handler. I traced it down with the patch below, which produces $ qemu-system-x86_64 -m 2048 -kernel bzImage -append "earlyprintk=ttyS0,keep" -drive if=pflash,format=raw,readonly,file=OVMF_64.fd -nographic -enable-kvm ... Decompressing Linux... Error Code: 0000000000000002 CR2: 0x0000000003e00000 RIP relative to _head: 0x000000000088521d Error Code: 0000000000000002 CR2: 0x0000000004000000 RIP relative to _head: 0x000000000088521d ... Error Code: 0000000000000002 CR2: 0x0000000005a00000 RIP relative to _head: 0x00000000008854d0 Parsing ELF... done. Booting the kernel. Error Code: 0000000000000000 CR2: 0x0000000000000028 RIP relative to _head: 0xfffffffffe03b67c That last page fault is in the main kernel at the stack canary's address. Patch: diff --git a/arch/x86/boot/compressed/ident_map_64.c b/arch/x86/boot/compressed/ident_map_64.c index 063a60edcf99..e0578dcbaecc 100644 --- a/arch/x86/boot/compressed/ident_map_64.c +++ b/arch/x86/boot/compressed/ident_map_64.c @@ -325,6 +325,13 @@ void do_boot_page_fault(struct pt_regs *regs, unsigned long error_code) unsigned long end; bool ghcb_fault; + error_putstr("\nError Code: "); + error_puthex(error_code); + error_putstr("\nCR2: 0x"); + error_puthex(address); + error_putstr("\nRIP relative to _head: 0x"); + error_puthex(regs->ip - (unsigned long)_head); + error_putstr("\n"); ghcb_fault = sev_es_check_ghcb_fault(address); address &= PMD_MASK; diff --git a/arch/x86/boot/early_serial_console.c b/arch/x86/boot/early_serial_console.c index 023bf1c3de8b..d6f051e4b64b 100644 --- a/arch/x86/boot/early_serial_console.c +++ b/arch/x86/boot/early_serial_console.c @@ -50,6 +50,7 @@ static void parse_earlyprintk(void) int pos = 0; int port = 0; +#if 0 if (cmdline_find_option("earlyprintk", arg, sizeof(arg)) > 0) { char *e; @@ -93,6 +94,8 @@ static void parse_earlyprintk(void) if (baud == 0 || arg + pos == e) baud = DEFAULT_BAUD; } +#endif + port = 0x3f8; if (port) early_serial_init(port, baud);