Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CFD79C36010 for ; Fri, 4 Apr 2025 14:45:29 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u0iI4-00041B-RN; Fri, 04 Apr 2025 10:45:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u0iI2-00040c-D9 for grub-devel@gnu.org; Fri, 04 Apr 2025 10:45:02 -0400 Received: from mail-il1-x130.google.com ([2607:f8b0:4864:20::130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1u0iI0-0003TS-2W for grub-devel@gnu.org; Fri, 04 Apr 2025 10:45:01 -0400 Received: by mail-il1-x130.google.com with SMTP id e9e14a558f8ab-3d44d66d9d2so529285ab.2 for ; Fri, 04 Apr 2025 07:44:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743777898; x=1744382698; darn=gnu.org; h=mime-version:message-id:subject:to:from:date:from:to:cc:subject :date:message-id:reply-to; bh=Sp28luRM32I0FkvcKDyjAu2rxUBG8V2rZhkl2M/BaZI=; b=YgmXmId161WSq5FDp25QQq4eMxCyLhuMP35v0EZqcFzLjOZEoIF2Vtz5r1Y/PNL+4f /k73ryNRvgOnpGyrKJnmFks5dVPRcXrzA9fezUNX70x8ifUQUPntxav0m//orPVh3zR5 cAK7vyHaouHBLw+l8D/T41uCH1/jA+Npg6W3bnMIwdxn+g/2hTIpr/fK5vmoZLhey/2C 6qS4kkKUgtMpuLUUW1dvdaSQ4w9kPB968lKAzXIfEk+utyBLppInlKNLBldYGyviiy1e /9DyAlEkdpd661iFSSlf/GegXRPUZeAaanwd4Nh6JvjOiEKaLX+B8fSxLgnnfBemZXO1 RFBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743777898; x=1744382698; h=mime-version:message-id:subject:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Sp28luRM32I0FkvcKDyjAu2rxUBG8V2rZhkl2M/BaZI=; b=RpzpXy8Z7mEvCJZFC0oZuWe1ReN8N7p2HkdZiL/wKQippBCP05ClwOlLERobU5TKMj j7CEgZQMtRS88aB60SAwWFVxEPssPMz0+8nCOlBmVUplErElcnCvKSX2NSTwAFvDEWqe gZeprQ0jX3UBLKuND6W15Mv9zrJnGQUDq7RsTMIpnmPZ+QyL8V7ssT/YKKJkuJa8ZKDr G+ifLbKTo2kmsiMqQSX2z8zhtykdvXbN5ggAQkT8EInpFdNp/dbkV2Kdar2bY802vg+N m9QWytgKwvt+VQtPOZJTKuazFvLVcsmr1UGQsaKWLHd2s4HeH7Mzg+BFKFeF9pzdY+Wr ekAQ== X-Gm-Message-State: AOJu0Yy6SaDehU6pYEU6K7s9Cfb1x2qFzImmnVbwjOc20SL7MZcz8gXT N7oogbnsLYDbGh1KFIVblDJj/LzGNy0KFPytmEZuymleQE07r8G57ks84A== X-Gm-Gg: ASbGncsn4YNUdzlxeEhEfZliEPDpELgmfsU4/Z1nVoC3AXNQxIdDuCq8YHkRfRbaARM J3cO7y7tFSC1aFGpqS8oyZ+m1w9MD63s3jXniNLSv/vvoNttK+OkbYAetKoa6Z/YYIH0gh7+2aA OhwkThynBRuau6z4Ni3XE72TPOI/B6jDqudwWL90/86W7VCgL2D8zPMckg/Z5omQf3g+m8dx8Oc B9TXG0A5NyIafPEYAFD6B1bMWWznNOPO8oD7TT358Q9YsLNzYCdo1oJLl3lburrWn/Jnz5Gr/RA pkiz524kfPzxglDInrNvvwg3e+bDeIRNuDHFHCLP5Q== X-Google-Smtp-Source: AGHT+IGU8h9pYOBBmC8uBDm32AQpYo8DAmls63vaaA9SOBTJt8/v6fNw8G0t6Mk/vGVVaUl6ENxY/w== X-Received: by 2002:a92:cdae:0:b0:3d5:be78:a09a with SMTP id e9e14a558f8ab-3d6e3f7574bmr10697415ab.5.1743777898060; Fri, 04 Apr 2025 07:44:58 -0700 (PDT) Received: from kf-m2g5 ([2607:fb90:cf8f:c3b4:84e1:f685:d52:5be5]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-3d6de973f87sm8355475ab.64.2025.04.04.07.44.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Apr 2025 07:44:57 -0700 (PDT) Date: Fri, 4 Apr 2025 09:44:46 -0500 From: Aaron Rainbolt To: grub-devel@gnu.org Subject: [DRAFT PATCH 0/1] Add Xen command line parsing Message-ID: <20250404094446.6bdb8259@kf-m2g5> X-Mailer: Claws Mail 4.3.1 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::130; envelope-from=arraybolt3@gmail.com; helo=mail-il1-x130.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The development of GNU GRUB Content-Type: multipart/mixed; boundary="===============1804677490632689477==" Errors-To: grub-devel-bounces+grub-devel=archiver.kernel.org@gnu.org Sender: grub-devel-bounces+grub-devel=archiver.kernel.org@gnu.org --===============1804677490632689477== Content-Type: multipart/signed; boundary="Sig_/wFJWjcklz9KVoVT79pyRnxR"; protocol="application/pgp-signature"; micalg=pgp-sha512 --Sig_/wFJWjcklz9KVoVT79pyRnxR Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Sending this for preliminary review, this was originally developed downstre= am for the Qubes OS project and I was requested to send the patch upstream. Th= is has been tested pretty well on Qubes OS R4.3, I haven't tested it in a more "vanilla" environment yet as I cannot for the life of me get GRUB from git master to compile right on Fedora 41 due to linker bugs. The purpose of this patch is to allow the Xen hypervisor to pass extra data= to GRUB as a kernel command line, allowing the host to customize the boot proc= ess of the guest. The command line from Xen is parsed and the data within it exposed as environment variables. The grub.cfg script can then use those environment variables as it sees fit. The main reason for doing this is to allow implementing boot modes in Qubes= OS while also using in-VM kernels. For more context on Qubes boot modes, see [= 1]. In order for this to work with in-VM kernels, it is necessary for dom0 to p= ass kernel parameters to the guest without modifying the guest's grub.cfg manually. This patch allows this to happen, by allowing dom0 to pass kernel parameters to GRUB, which then provides them as an environment variable. The grub.cfg script within the VM can then append those variables to the kernel command line. The way this works is pretty simple: * When booting in PVH mode, grab the command line passed by Xen and copy it into the `start_info` struct ointed to by `grub_xen_start_page_addr`. (In= PV mode, this struct has the command line pre-populated by the hypervisor, in PVH mode it has to be manually populated.) * Before parsing the GRUB configuration (or dropping to a rescue shell), pa= rse the Xen command line: * Break apart the command line into words, using spaces as the separator. Quotes (both single and double) can be used to suppress splitting, and backslashes can be used to escape characters. * For each word: * If the word contains an `=3D`, split the word on the first `=3D` sign. Export an environment variable with the name set to the word portion = on the left of the sign, and the value set to the word portion to the ri= ght of the sign. * Otherwise, export an environment variable with the name set to the wo= rd, and the value set to `1`. I do have some concerns with how my code does this at the moment, which is part of why this is a draft: * `pvh_start_info->cmdline_paddr` is a physical address. I use `grub_strcpy` to copy its contents into `grub_xen_start_page_addr->cmd_line`, so this means my code assumes that paging is disabled, or the page(s) containing = the command line source and destination are identity-mapped. I tested this in= a PVH VM and it seems to work without issues, but seeming to work and actua= lly working aren't necessarily the same thing, and I can't tell how paging wo= rks in GRUB in this particular area of things, so I'm unsure if this is safe. * This patch assumes dom0 is fully trusted - it can clobber arbitrary environment variables in GRUB with whatever it wants. I'm unsure if Xen is used in any confidential computing situations, but if it is, this probably is unacceptable. * Every single parameter passed from Xen to GRUB will end up an environment variable used when parsing the config file. THis means that if in the fut= ure there's ever a reason to pass parameters to GRUB on the Xen command line that do something other than set environment variables, there will be a (potentially mild) API breakage. * All testing has only been done on Qubes OS, which patches both its Xen and its GRUB pretty heavily. I tried to test this on Fedora 41 with a vanilla Xen and GRUB, but no matter what I did I would end up getting a linker-related error when trying to make an i386-xen_pvh GRUB image. [2] I'm very open to making large changes to this patch to make it acceptable f= or integration into GRUB upstream. Consider this a prototype implementation th= at simply proves that the concept I'm going for is possible. If there's a bett= er way to do the kind of thing I'm trying to do, I'd be more than happy to do = it that way instead. Final copyright-related note, I am working on this patch as part of my contracter work with ENCRYPTED SUPORT LLC (the main developers of Kicksecur= e). I've already talked to them about it and they're fine with transferring copyright for GNU contributions to the FSF when and if it is requested. [1] https://github.com/QubesOS/qubes-issues/issues/9750 (includes notes abo= ut the testing done so far) [2] Trying to build an unpatched, vanilla GRUB: $ ./configure TARGET_LDFLAGS=3D-static --target=3Di386-redhat-linux-gnu --with-platform=3Dxen_pvh --disable-grub-mount --disable-werror $ make -j16 $ # create grub-bootstrap.cfg and memdisk.tar $ ./grub-mkimage -O i386-xen_pvh -o grub-i386-xen_pvh.bin -c grub-bootstrap.cfg -m memdisk.tar -d grub-core grub-core/*.mod ./grub-mkimage: error: `grub-core/kernel.img' is miscompiled: its sta= rt address is 0x9000 instead of 0x100000: ld.gold bug? This issue occurs using the BFD and LLD linkers, gold ends up placing t= he start address at 0x9072. Aaron Rainbolt (1): Add Xen command line parsing grub-core/Makefile.core.def | 4 +- grub-core/kern/i386/xen/pvh.c | 16 +++ grub-core/kern/main.c | 12 ++ grub-core/kern/xen/cmdline.c | 223 ++++++++++++++++++++++++++++++++++ include/grub/xen.h | 2 + 5 files changed, 256 insertions(+), 1 deletion(-) create mode 100644 grub-core/kern/xen/cmdline.c -- 2.43.0 --Sig_/wFJWjcklz9KVoVT79pyRnxR Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEudh48PFXwyPDa0wGpwkWDXPHkQkFAmfv8F4ACgkQpwkWDXPH kQma/g//UXQWFapmy3dUyztfzGL8mi+mugAvmEThR3HMdsxzt+Do2Gn6egTa04Xn ddURQ3i3ef6HcWOrwLqTRet8QZaCqDdo6YY0Lu8m0WDgi7eewvdMZSxCxvh4xDZJ 5ClKOpGq+suts5cZH0ZcgkHAK8laqHsTz6bgDsr0O8yWvLjJyvx970luXVRtL7j7 w4XQUIA5cIALO/9gtaiws49hsaV1B5ZEo8LaCaVKRpxfBKRrXHzn1fmB++qwpkf7 Y1so3CybyNwqm1xJf3LfgFGLa+tK8mR+PJ4IeryAg/w3z9JBmpAb7X0EFbybzepJ jAwPeVxTA0Haq+rFUuiY+12n1Wmm2EZG2ZmNm6YGdTG3s8ycGh/7ko4Ja+/dToP0 m1SfrtY20dxkbYGCB4nB+lx04pgGcoIZaVeL0ehxVVvZvT9PA2Nb88RTGugenInd VGCWHeCw76OTLzB59ygp0NU7HuyqM5yEAQE4zDrCRz0oX6ScjG027jXROQuhmDor oo+lWwcDdh1WJwuv2CDaFq8o5prWrp3Wuj6beue+6gLAv8Jsvl8uV+pjKEObfA+N asPtbK3WLKfbi3m3u9VJSLNhFNxUcC3o7tBHlFoWa+Qy8f025tse8QAHLOEf0moj 2mC4+mJsy8o4g7JIi0PFe9hLwS33UTg/QdTjY9amludDo8d5X3w= =n5l3 -----END PGP SIGNATURE----- --Sig_/wFJWjcklz9KVoVT79pyRnxR-- --===============1804677490632689477== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KR3J1Yi1kZXZl bCBtYWlsaW5nIGxpc3QKR3J1Yi1kZXZlbEBnbnUub3JnCmh0dHBzOi8vbGlzdHMuZ251Lm9yZy9t YWlsbWFuL2xpc3RpbmZvL2dydWItZGV2ZWwK --===============1804677490632689477==--