From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 8A97A9416F1 for ; Wed, 18 Oct 2023 11:34:02 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=1YptRFc9G3oWM+tTwSnC88fBWSPvIQJzI0s5L5oHBLg=; c=relaxed/simple; d=groups.io; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject:To:Cc:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type:Content-Transfer-Encoding; s=20140610; t=1697628841; v=1; b=KOwSOElXqUrVsEvdpGw0bRx0RmQhhvGrVNsOeV8DzaJukFCd8odI4vOuFsYRVKHC73z1Xnbm PeUCIY32qISoDPEYXT4hPu5SmIuq0XmH5MHN8TowIzi20oXqmKm1EXogdjO2bzl3WdOgrVYdYXR f7cKxe5Z/zEZdN6YbTrRIJi8= X-Received: by 127.0.0.2 with SMTP id HsIWYY7687511xdoJ4yIeZn0; Wed, 18 Oct 2023 04:34:01 -0700 X-Received: from mail-vk1-f176.google.com (mail-vk1-f176.google.com [209.85.221.176]) by mx.groups.io with SMTP id smtpd.web10.279494.1697628840641548257 for ; Wed, 18 Oct 2023 04:34:00 -0700 X-Received: by mail-vk1-f176.google.com with SMTP id 71dfb90a1353d-49d39f07066so2859440e0c.0 for ; Wed, 18 Oct 2023 04:34:00 -0700 (PDT) X-Gm-Message-State: DQSP5FVmr58x5VQ7y7koIKQbx7686176AA= X-Google-Smtp-Source: AGHT+IEoi9ZjvgJ1doH4swy1wNPEu/T27Bpm6A3/HiDdeLk/muoktn7wzSyTXBIkswfi4QI62NHwxX+UYRGLpu82wgM= X-Received: by 2002:a05:6122:c96:b0:49a:c339:11b9 with SMTP id ba22-20020a0561220c9600b0049ac33911b9mr5543038vkb.11.1697628839514; Wed, 18 Oct 2023 04:33:59 -0700 (PDT) MIME-Version: 1.0 References: <20231018103328.91093-1-kraxel@redhat.com> In-Reply-To: From: "Pedro Falcato" Date: Wed, 18 Oct 2023 12:33:48 +0100 Message-ID: Subject: Re: [edk2-devel] [PATCH 1/1] OvmfPkg/VirtioFsDxe: fix SimpleFileOpen To: devel@edk2.groups.io, lersek@redhat.com Cc: Gerd Hoffmann , Jordan Justen , Ard Biesheuvel , Oliver Steffen , Jiewen Yao , =?UTF-8?Q?Marvin_H=C3=A4user?= Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pedro.falcato@gmail.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=KOwSOElX; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io On Wed, Oct 18, 2023 at 12:20=E2=80=AFPM Laszlo Ersek w= rote: > > On 10/18/23 12:33, Gerd Hoffmann wrote: > > VirtiofsDxe throws an error in case the caller tries to open a file or > > directory using an handle with is not a directory, claiming that openin= g > > something relative to a file does not make sense. > > > > The claim is correct, but the code throws errors for both relative and > > absolute paths. Add a check to fix that. > > > > Signed-off-by: Gerd Hoffmann > > --- > > OvmfPkg/VirtioFsDxe/SimpleFsOpen.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsOpen.c b/OvmfPkg/VirtioFsDxe/S= impleFsOpen.c > > index a13d4f6a1e2d..1729ea2f5cf2 100644 > > --- a/OvmfPkg/VirtioFsDxe/SimpleFsOpen.c > > +++ b/OvmfPkg/VirtioFsDxe/SimpleFsOpen.c > > @@ -397,7 +397,7 @@ VirtioFsSimpleFileOpen ( > > // it cannot be implemented consistently with how a file is referred= to > > // relative to a directory). > > // > > - if (!VirtioFsFile->IsDirectory) { > > + if (!VirtioFsFile->IsDirectory && FileName[0] !=3D '\\') { > > DEBUG (( > > DEBUG_ERROR, > > ("%a: Label=3D\"%s\" CanonicalPathname=3D\"%a\" FileName=3D\"%s\= ": " > > It's nice to see this topic pop up on edk2-devel; apparently you started > testing shim on top of virtio-fs. :) > > I have had the following patch in my local repo, on a separate branch, > since April this year: > > > commit cb4a6d1664ea6cabd14d2af0e5d9abb114973870 > > Author: Laszlo Ersek > > Date: Sat Apr 8 22:50:50 2023 +0200 > > > > OvmfPkg/VirtioFsDxe: tolerate opening an abs. pathname rel. to a re= g. file > > > > Referring to a file relative to a regular file makes no sense (or a= t least > > it cannot be implemented consistently with how a file is referred t= o > > relative to a directory). VirtioFsSimpleFileOpen() has enforced thi= s > > strictly since the beginning, and a few months ago I reported USWG = Mantis > > ticket #2367 [1] too, for clearing up the related confusion in the = UEFI > > spec. > > > > Unfortunately, the shim boot loader contains such a bug [2] [3]. I = don't > > believe the shim bug is ever going to be fixed. We can however rela= x the > > check in VirtioFsSimpleFileOpen() a bit: if the pathname that's bei= ng > > opened relative to a regular file is absolute, then the base file i= s going > > to be ignored anyway, so we can let the caller's bug slide. This ha= ppens > > to make shim work. > > > > Why this matters: UEFI-bootable Linux installer ISOs tend to come w= ith > > shim and grub in the embedded (ElTorito) FAT image (ESP). Sometimes= you > > want to build upstream shim/grub binaries, but boot the same ISO > > otherwise. The fastest way for overriding the ESP for this purpose = is to > > copy its original contents to a virtio filesystem, then overwrite t= he shim > > and grub binaries from the host side. Note that this is different f= rom > > direct-booting a kernel (via fw_cfg); the point is to check whether= the > > just-built shim and grub are able to boot the rest of the ISO. > > > > [1] https://mantis.uefi.org/mantis/view.php?id=3D2367 What does the mantis ticket say/conclude? Yay for private bug trackers that need corporate buy-in... FWIW, Ext4Dxe does [...] if (!Ext4FileIsDir (Current)) { return EFI_INVALID_PARAMETER; } // If the path starts with a backslash, we treat the root directory as the base directory if (FileName[0] =3D=3D L'\\') { FileName++; Current =3D Partition->Root; } so if shim/other important UEFI apps have a bug, I may need to fix this as well... --=20 Pedro -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#109732): https://edk2.groups.io/g/devel/message/109732 Mute This Topic: https://groups.io/mt/102036263/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-