Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp630972lqd; Wed, 24 Apr 2024 12:01:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXGDXbembuu6KICCBhANs1+PMARGP0E224CcR+0uWwdK4OKNdoEH1w9nvn9LtYlCUobeOUh3gYvQBa5ErEwGtmD58hSET3YINkIlCcqlg== X-Google-Smtp-Source: AGHT+IF/Ualz9GhMVs6jyx7ar2+HqguBerfp3c8fNquxDBIenVoLBhQsyKCjlqAkeM/VDy5MyN4Z X-Received: by 2002:a17:903:11d1:b0:1e2:3cbe:adcc with SMTP id q17-20020a17090311d100b001e23cbeadccmr4695125plh.49.1713985264556; Wed, 24 Apr 2024 12:01:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713985264; cv=pass; d=google.com; s=arc-20160816; b=tzht+gadwcW+wqX1zgYhj1TqwOJRTKf54xVZGAYUHvVoE15bDJPBgAQB4hUs6Ev9sk m4pGmKN3lNSZldHoOndbB319sC95HyEUE1VHtB7O/Al/TbhMVbZxsqgN1TTMiyqqfzYe 2vF9lB3C/aNAg3VuzrMkyPp7jxvoCsQpCH5z4cPiQpUuh8Q2Ui1oqJx27zOKmTj2PZGO +pezKvAPLJ8im+WMYZoWofQLnFalaFkBaGtqUj9OH9QCung7lWYfqXhGjjETJlBnotg/ riJnWUTEl948uNt0foBX0zE4ZmSaPb8rV12EBMfMIreeoFWMiM7un46HyQWPEuQW/7Np +Lpw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=C/9BAtndkfFaumCrUJiPVhEbeA1SDIK0JZwe5FMmllc=; fh=M+aGWyx5boT7HDSnrkFBiYgTBWPAudb4Bg09KXmERQQ=; b=If0X+7F5yKmqaIb02iQLTPT5Xsns3Y5HWff0C+tIMPONCSXX174XpIOgIdU09xR/eB +Ej1iZyFFWt1IudaCbNUnlbo8Ja1sdbKW5LrGr2KnP499oOt7qgVUPatWMJ3Ej0fuG5e yCsl+O5tIrwLuSn5/2X7Lp/osjkbJE9KUJfufgYAWAlGgVvWfKwluqcA7OB6oywiiRou QHQPyyKAizi/0S1vuwop4tQAeOOUAKWdFmYh0HCLeZI9wgv3CykM2I0mN6zuRBgra7qO rV/3RgZXsnN9W+4AKN5bNoCp+050fQywF6WQrViJXSTBXus3yANlSe8c09o6qa7namII TzaA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="LN3Dr/oZ"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-157571-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157571-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id e18-20020a170903241200b001e7a248eaafsi11679238plo.6.2024.04.24.12.01.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 12:01:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-157571-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="LN3Dr/oZ"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-157571-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157571-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 36C07286E69 for ; Wed, 24 Apr 2024 19:01:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 56B9A1CF9A; Wed, 24 Apr 2024 19:00:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LN3Dr/oZ" Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7112319479 for ; Wed, 24 Apr 2024 19:00:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713985258; cv=none; b=gG2fohO2alq/9x2LAMJIVl9w5Vbth4eNhpUPhnBNpzv2t2V5sEeYB3AuhO1tAXMvS462vIhtr33PPBE+GtQRXejIeeXyKgsC+be5Wrrxpo+BrEvLTJnPNii46chYhuvVkdJ5qa2W3iQXUf6ilNpStDlIilGbZSUpa7fKzVEAfo4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713985258; c=relaxed/simple; bh=bNe1LwivQ7x1iIF0+qk4j+3O3sy3kZEF2aWBuMXA2jg=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=fIm3ow+7wjQTVQ7VblioEKBo3drDj4QqNMZeWLy+w4HsNPzb3ypTpfzfQsrtE8cFWkiXLYbG9Dwb70h85Ub5hdov57D5cZEzLfkLHQj2UeTNzCYKSDRMhEXdbiLoJjJSGmnNe6z//Zlm7P728zAjVZFQ8bswfAs3nBDeNtcicls= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LN3Dr/oZ; arc=none smtp.client-ip=209.85.167.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-51aa6a8e49aso153707e87.3 for ; Wed, 24 Apr 2024 12:00:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713985240; x=1714590040; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=C/9BAtndkfFaumCrUJiPVhEbeA1SDIK0JZwe5FMmllc=; b=LN3Dr/oZjdSSLza53wJvzWo5l4tvxPLQTuXq1tOfmWmSZ82IhJ5ad1pX0Mj5n2Mfbr LdIXTbj8x9XiyRIlWmos7luy/uUxFjPh6FmjDXRTGF0VmYm8GygG3kVyYLdppZViKjp1 K2cG1/j+O16NtnbAJx5o/q5Tl81daqe1bqMWvvgiEqIFPFyOZqkwrW016w+s6ncI1x2x ICIL9yfvYHdsYDn+20XPhHKsxAjOHfMROGnInOOrh1tciZ9uRTQDsKwvIkbIv6OTAsiQ XwP9EdBU7E37plAVHK0XOb9PyaZCD7Dhry/JMwI15WS6VQO7fyPFDj/VgaCmA16griBm vrPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713985240; x=1714590040; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=C/9BAtndkfFaumCrUJiPVhEbeA1SDIK0JZwe5FMmllc=; b=ChNhapZ1Ll7dzfpe33VCrgQfrLv19f1o1YYLWlmQHTCST6JFgvHfbiXt6fitF6/DVn lJ6y3dwx/f806K9NNAM+6SE3IKDqfhs0N9jlfKEmIiaFEMtFXDqRpzHxSrf48EOPqk4+ NWCfZs3cGOTatB92BjM26Sznv42S1f7RrknQI3gSMQTKBUkVwxurNct25ja0SHiBiM/c NDSOBKNS5xyv/12Sx7Fe1mgmfatvpm2SW7q8S1se8Zh3ZQGH9h4v7C7EWGaVKEmddanc cQE91tYB5hra2dwUUvKkEZKGa20N2YD23nZqi4Og0Uq3+xC0o0gGAHcrU5hq5g3JNxYC 7Dkg== X-Forwarded-Encrypted: i=1; AJvYcCUffoRomSTEHIYy2qVCu6P7xLjajZmuQQ2duz1eaq6Wg353WWx6Dsoc8CD8n2hB9TvCrQXWn9b691q+6Ca2qSZ5NvgDSXRpli0Kb354 X-Gm-Message-State: AOJu0YzA4BI/Vi6Q4QJOXwsNwZHVL8Ch74/O/VAFUIAnIU7QJPmNxOA9 Z8F4az7xqx58ZWgp1oJJbLUW1iH/Vz2zeumShmvQCSl+2cGcXGPj+gGKrK8i2e3daFpQvBd56m1 keLT2hH2ylZx2nT5Epk3lSuspuw== X-Received: by 2002:a19:e00f:0:b0:51c:10b4:1d01 with SMTP id x15-20020a19e00f000000b0051c10b41d01mr1231030lfg.21.1713985239330; Wed, 24 Apr 2024 12:00:39 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240424155309.1719454-11-ardb+git@google.com> <20240424155309.1719454-15-ardb+git@google.com> In-Reply-To: From: Brian Gerst Date: Wed, 24 Apr 2024 15:00:27 -0400 Message-ID: Subject: Re: [RFC PATCH 4/9] x86/purgatory: Avoid absolute reference to GDT To: Ard Biesheuvel Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, x86@kernel.org, Arnd Bergmann , Eric Biederman , kexec@lists.infradead.org, Nathan Chancellor , Nick Desaulniers , Kees Cook , Bill Wendling , Justin Stitt , Masahiro Yamada Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Apr 24, 2024 at 1:53=E2=80=AFPM Ard Biesheuvel wr= ote: > > Hi Brian, > > Thanks for taking a look. > > On Wed, 24 Apr 2024 at 19:39, Brian Gerst wrote: > > > > On Wed, Apr 24, 2024 at 12:06=E2=80=AFPM Ard Biesheuvel wrote: > > > > > > From: Ard Biesheuvel > > > > > > The purgatory is almost entirely position independent, without any ne= ed > > > for any relocation processing at load time except for the reference t= o > > > the GDT in the entry code. Generate this reference at runtime instead= , > > > to remove the last R_X86_64_64 relocation from this code. > > > > > > While the GDT itself needs to be preserved in memory as long as it is > > > live, the GDT descriptor that is used to program the GDT can be > > > discarded so it can be allocated on the stack. > > > > > > Signed-off-by: Ard Biesheuvel > > > --- > > > arch/x86/purgatory/entry64.S | 10 +++++++--- > > > 1 file changed, 7 insertions(+), 3 deletions(-) > > > > > > diff --git a/arch/x86/purgatory/entry64.S b/arch/x86/purgatory/entry6= 4.S > > > index 9913877b0dbe..888661d9db9c 100644 > > > --- a/arch/x86/purgatory/entry64.S > > > +++ b/arch/x86/purgatory/entry64.S > > > @@ -16,7 +16,11 @@ > > > > > > SYM_CODE_START(entry64) > > > /* Setup a gdt that should be preserved */ > > > - lgdt gdt(%rip) > > > + leaq gdt(%rip), %rax > > > + pushq %rax > > > + pushw $gdt_end - gdt - 1 > > > + lgdt (%rsp) > > > + addq $10, %rsp > > > > This misaligns the stack, pushing 16 bytes on the stack but only > > removing 10 (decimal). > > > > pushw subtracts 2 from RSP and stores a word. So the total size stored > is 10 decimal not 16. I didn't notice the pushw, since I didn't think a 16-bit push was even possible in 64-bit mode. Unexpected, but clever. Brian Gerst