Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7168117rwb; Wed, 23 Nov 2022 03:10:43 -0800 (PST) X-Google-Smtp-Source: AA0mqf41bJlugYPdNuKSCDZEvIPnYHvxJJ088geMF1vL2dCM8oqLxC342MPO67ia8BJ3yKJAItAw X-Received: by 2002:a17:902:b20f:b0:188:d4ea:251f with SMTP id t15-20020a170902b20f00b00188d4ea251fmr21120120plr.36.1669201843436; Wed, 23 Nov 2022 03:10:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669201843; cv=none; d=google.com; s=arc-20160816; b=o2F4r71xVnn+lbDICfobbib8qpXFCgrr/ydHxOmvh/R/W/Uyp6/BQ4tjhGXoSbFOn9 84X4+gyenw6PoZOoXrAfJe9+7+rq6je75N7A3M00tH1kvqwi4V79AD+yPQ8zvJ5xHN9N UktFBKsqPFw9l6AFn5VSlYj7oyXDXHloMg1156rpE4npYAPYfoNTNcBHNjUanvZc0TYK 5pDgQ2izq/Y+OEJMF+Zu5DFVJGXBj/tBIbnwoernyozv6Utsj5o06jhVfoIjGmNMkASn lN+jUwUH46+hnG/N07aAvHIK9nc/6CR5EJGtfzXSyYXwPa4t4m5kI+SBxxZaIx8X3DRL ZHQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=I6slaSBgsj5bxhqJUlt9jhYAv4JJ2li4fwM6GK/C6ds=; b=D+Acb7KQxhbRCYuMp5pCp06bnI86l8BMudEK9TvA2PlxtooQCKJVI79N/363ffUBcu v+eaN/jRAWh9rvsNzxKFA9dWa0e8APCwRysy2AO9pg1c9ZE4Pw0quGPVd5BccWcgYomj HmnFhpGYNHyNA71YKWI7wS4Ikqj8J3Hjpf4TdAm0WdkjVTC07cZPA8hIW1X4l/fLSvYm 0RiX7Y2Yj473c+5YM0ZvM2arXRWqp4H8yNUPCwM6R1fyn/W5TXlnuFFg2a/A+QVgK7kr 4uH078xKKZ0LeazOTPf4FNfq1ohA9rmrmuaZkiIGGE5vnG3FpFOlqgVnKlI+i9s0M96U V0dQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=F43AtqmB; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w38-20020a634926000000b0046aeabd6548si16647404pga.104.2022.11.23.03.10.31; Wed, 23 Nov 2022 03:10:43 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=F43AtqmB; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237258AbiKWK7o (ORCPT + 88 others); Wed, 23 Nov 2022 05:59:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237222AbiKWK7Y (ORCPT ); Wed, 23 Nov 2022 05:59:24 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06BBA17ABC; Wed, 23 Nov 2022 02:52:48 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id EB784B81F03; Wed, 23 Nov 2022 10:52:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8C7AC433C1; Wed, 23 Nov 2022 10:52:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669200765; bh=WCuZfrHfJi8JZnk4DYCT3piFu5GW3N8kXKAvJ0v7b7M=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=F43AtqmBGvByBl+jmywNCIWicC6I3TG7EnMvVna41n2ksHWcp6tVyNfnd7BLqSboW 95tjUigoidk9Dnl45Xiu9IyKaO2C5XzmNbCoCtM/ghk8UIeQSopmprAi4Tl3GdcrrJ gQ2VBCWsLF2ltqAEz+usgQkyBZPVnw01Uh4U1L1TLtOeYljX8PT/zY/lnF/L+ElRMd F3T//wZHd+IOtB3Ol50xrzml2bOFX0M14shp+uiezrTrJ1DcmGSYQYjK0AylChznDI vR1Jjc70hQTYsr+/V/ZW3uFvNeNo21fi5i/arqEC/F+b/fUwYm3O8ZcjG+7MxdcKE9 SCcfa1wN9HS4g== Received: by mail-lj1-f172.google.com with SMTP id k19so20951904lji.2; Wed, 23 Nov 2022 02:52:45 -0800 (PST) X-Gm-Message-State: ANoB5pn+BLWuY8Vh9m1yt/bkkXQ4QAcuR1Eu2ISbPCB/3SvVimCyFGCN aG8xHOLMpxY+Tz4V4rGYJlRZvmYK6zXDZkYLHvc= X-Received: by 2002:a05:651c:220a:b0:277:2428:3682 with SMTP id y10-20020a05651c220a00b0027724283682mr9482830ljq.291.1669200763666; Wed, 23 Nov 2022 02:52:43 -0800 (PST) MIME-Version: 1.0 References: <20221122161017.2426828-1-ardb@kernel.org> <5750d157-43dd-6f3d-1407-f41af3cff207@amd.com> <26c34f9e-3b09-7b10-09a2-993a50790447@amd.com> In-Reply-To: From: Ard Biesheuvel Date: Wed, 23 Nov 2022 11:52:32 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 00/17] x86: head_64.S spring cleaning To: Borislav Petkov Cc: Tom Lendacky , linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Dave Hansen , Michael Roth Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 On Wed, 23 Nov 2022 at 11:49, Borislav Petkov wrote: > > On Tue, Nov 22, 2022 at 03:49:29PM -0600, Tom Lendacky wrote: > > diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c > > index cb5f0befee57..a0bfd31358ba 100644 > > --- a/drivers/firmware/efi/libstub/x86-stub.c > > +++ b/drivers/firmware/efi/libstub/x86-stub.c > > @@ -23,7 +23,7 @@ > > const efi_system_table_t *efi_system_table; > > const efi_dxe_services_table_t *efi_dxe_table; > > -u32 image_offset; > > +u32 image_offset __section(".data"); > > static efi_loaded_image_t *image = NULL; > > static efi_status_t > > > > I assume it has to do with being in .data vs .bss and not being explicitly > > cleared with the encryption bit set. With the change to put image_offset in > > the .data section, it is read as zero, where as when it was in the .bss > > section it was reading "ciphertext". > > Hmm, two points about this: > > 1. Can we do > > u32 image_offset __bss_decrypted; > > here instead? We have this special section just for that fun and it > self-documents this way. > The patch moves it from .data to .bss inadvertently, and I am not convinced Tom's analysis is entirely accurate: we may simply have garbage in image_offset if we access it before .bss gets cleared. > 2. Also, why does my SEV-ES guest boot just fine without that change? > Indeed, so it needs to be in .data > [ 0.000000] Linux version 6.1.0-rc6+ (root@ml) (gcc (Debian 11.3.0-1) 11.3.0, GNU ld (GNU Binutils for Debian) 2.38) #1 SMP PREEMPT_DYNAMIC Wed Nov 23 11:27:17 CET 2022 > ... > [ 0.336132] Memory Encryption Features active: AMD SEV SEV-ES > > Thx. > > -- > Regards/Gruss, > Boris. > > https://people.kernel.org/tglx/notes-about-netiquette