Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88A8DC47082 for ; Thu, 3 Jun 2021 06:15:01 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DC90A613D8 for ; Thu, 3 Jun 2021 06:15:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DC90A613D8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmx.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0F5E082F7C; Thu, 3 Jun 2021 08:14:59 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="GuK8ol6P"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1FE1482F8F; Thu, 3 Jun 2021 08:14:57 +0200 (CEST) Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 9C77F82F7C for ; Thu, 3 Jun 2021 08:14:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1622700887; bh=Hgonfcs6mVr+A0onJIS9hqAayKpuoK0xB0ToEbA3wPE=; h=X-UI-Sender-Class:Subject:To:Cc:References:From:Date:In-Reply-To; b=GuK8ol6PpgqOr6SRgEuLrg6e7oVeASpEvoPoy1HfD4WWOBSKGaA56SNEtImtq+xEs CgySdFBsZuuoggE8Y+IK/yD4lNrR5Zp+6LC+LxatecyPVpSUxB6QxwAzH90/MiSoo7 iU/MZmyqq/ui85rYCxufqSL4CXwGvuWaeSYjZ8Yc= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.123.35] ([62.143.247.63]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MHG8m-1lbR5T1TJg-00DHs0; Thu, 03 Jun 2021 08:14:47 +0200 Subject: Re: [PATCH] efi: Restrict the simple file system protocol to support only FAT To: Masami Hiramatsu Cc: Kazuhiko Sakamoto , Alexander Graf , Jesper Schmitz Mouridsen , Simon Glass , U-Boot Mailing List , =?UTF-8?Q?Vincent_Stehl=c3=a9?= , Grant Likely , Ilias Apalodimas References: <162268667641.382839.15360535926598237804.stgit@localhost> <1CB0876C-6011-450D-8293-EC3B22FDB0FB@gmx.de> From: Heinrich Schuchardt Message-ID: <9292facc-be0d-e878-fe95-c41f23c30565@gmx.de> Date: Thu, 3 Jun 2021 08:14:45 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:O1w/ss9lDATRyofBqCW9JQ5STigfackvwpVcvmAyE3GPDc9eSrA x9DG/sDBMVx1ykxCDxpODnxysRiQ5JZLZ1X1voooonvl2oLaFRhc3SPFXuJsL/THvvVaLVw 6v6Y80sbSAoP9BHdLpW6LDgSCvmJ5qZcmRTlLrlm/auu5StZUZYoAbVdVtVNdKiM+QFOjYz 1RO+mLdF3/WPKHcEcnazg== X-UI-Out-Filterresults: notjunk:1;V03:K0:khzySvMlnTk=:wR/M+AUK/laV5fbROy1vB9 KvRmTdilReSHXRwdK63r4n7BOm5DXyhDpGfNwM1xv6QLtfgJWJsylOzjGf0lpPf8eJ4zmwObW x/vtzQxeH/1H6Wz0Itpto9BFKzZUviSRjqn+YsixipTpuvoNEbYsX6jLvoYAjQgkNovHDSIbA NMEBVEoBeWla7ELiHkb3Dg2Z4g87Y8ybO2+laKFx97NC0KarNEcup/Zp3c63LZcxWeMGEIt58 6dpPbxGwg58TDcwypGznDI+djFSpgd6tG9y5SijhhDyh4pOlhKw5bhZTHh/vvkkKGB2/1fz0V zZ69mYEvojMLrfNeh18NL2yKDGRuHrvQFdtwIeNjstWGTr5FSLFFCwBZlmb73yERhUatjzk42 ARQGWOccddgOLyXOU31F2BIGV3ceMfp6ztZ4sxsvs9NvM1ffXQBmiULt5+kGmNHNVvLWUkpFM Aml0Wcakzi+/sDNu0q+zUWap2AVtzx7MmYGe7B94PJFvqDj9ZGNGfT6pX4Df2V3lsWtTobpqY APfbDz4fRkGVzkY+30MjeA8aqMluO5MP/TmZQj6HZdfK8cyhNPbSuKP7pzrkJeOKvatEg/733 KVJGOaGW5JocDoFD0pbRBvZB80eXeoNY2SZb/WzuwX0aL37lJxkaGjmDAmhtsZOoDcyHQMe2M Z5SKgg5VQbJyr7salNhI2h2d4ZF0q8lID9sA/LVkrQiy9CXqOhcHQiIdXrK9Ky+zux3vx4hug bXvXgbjQXM0EP/iWLrFc/BGrfl+DhLq681qx7WpKIxCXEfs+xUur7eVDhJuR23B6hBBpABcge ERGNH2R7kjgP1jTsurKGoeSxWekVEp6P/wkvjNxr8uhKx67Vd944Ifb38BDDM8VM2zy/Qwuis GfYeBwRn8AYBO4lPh2n/Ph+tjFo0PqOgFeeQ7uaT9nPV4MFTArU60pfUBTw45bgxMon54JSyG 9wxJ55DUqY4AVv74FOpXu+MiRz7lNPz2EEZe/53l1wQwSpAo/46ZbwMKU9AMbRoG/P+Z7a/lC /71kPJ2pSj3648f08db8ktFaqU9xTdIOuCyGkK9tK71ed5gRoaQVc+g0Ppi3m3lnNm4F2MrH5 SEo6SJ0YGzRxcbLLHbncHEmDVR289xRaXy3 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.4 at phobos.denx.de X-Virus-Status: Clean On 6/3/21 7:39 AM, Masami Hiramatsu wrote: > Hi Heinrich, > > 2021=E5=B9=B46=E6=9C=883=E6=97=A5(=E6=9C=A8) 14:15 Heinrich Schuchardt <= xypron.glpk@gmx.de>: >> >> Am 3. Juni 2021 06:57:16 MESZ schrieb Masami Hiramatsu : >>> Hi Heinrich, >>> >>> 2021=E5=B9=B46=E6=9C=883=E6=97=A5(=E6=9C=A8) 13:08 Heinrich Schuchardt= : >>>> >>>> Am 3. Juni 2021 04:17:56 MESZ schrieb Masami Hiramatsu >>> : >>>>> Because UEFI specification v2.9, 13.3 File System Format said "The >>>>> file system supported by the Extensible Firmware Interface is based >>>>> on the FAT file system.", the simple file system protocol might be >>>>> better to support only FAT filesystem. >>>>> >>>>> There must be no problem from UEFI application to access only FAT >>>>> because ESP must be formatted by FAT32 and the removable media is >>>>> FAT12 or FAT16, according to the UEFI spec. >>>>> >>>> >>>> Does the UEFI spec forbid to access to other file systems? >>> >>> No, it does not forbid. >>> >>>> >>>> Which problems were observed? >>> >>> My problem was observed by UEFI SCT ( >>> https://github.com/tianocore/edk2-test/tree/master/uefi-sct ), which >>> reported errors while testing some volumes formatted by Ext4. >>> >>> I can fix that with dropping Ext4 support from the U-Boot too. Or >>> maybe fixed by enabling Ext4 write support. But I thought that is not >>> a fundamental solution because there are other filesystems which >>> support read-only (e.g. Btrfs). And UEFI >>> configuration(CONFIG_EFI_LOADER) doesn't depend on write support. >>> >>> Of course, the test program itself should check whether the filesystem >>> is FAT (because UEFI spec only specifies FAT full support, other >>> filesystems are out-of-spec), but there is no way to determine that >>> the volume is formatted by FAT (at least in the simple filesystem >>> protocol). This is reasonable, because UEFI spec expects only FAT. >>> >>> Thus, I have some ideas except for this fix. >>> - Check the filesystem driver and only if it supports full operations >>> (read/write, mkdir etc.), makes it available from UEFI simple file >>> system protocol (this also checks CONFIG_*_WRITE). >>> - Set the volume read only if the filesystem driver doesn't support >>> write and return correct error code. This will give a consistent >>> filesystem model to the application. (maybe SCT needs to check volume >>> ReadOnly flag before test it.) >>> >>> What would you think? >>> >>> Thank you, >> >> For running the SCT I use an image which has only a FAT partition. > > That depends on the device configuration. My platform (DeveloperBox) > is something like PC, which has not only USB, but eMMC, SATA, NVMe. Of > course I can just disable CONFIG_EXT4 from U-Boot for SCT, but I don't > like erasing all the partitions on which I have installed debian... > >> >> At least Debian and Ubuntu do not allow /boot to be on a FAT file syste= m. If we want to boot Linux via the EFI stub without GRUB, we need ext4 su= pport exposed to the EFI sub-system. See Ilias' recent contributions for t= he EFI_LOAD_FILE2_PROTOCOL for initrd and efidebug. This came in handy for= booting via EFI on RISC-V where the initrd=3D command line parameter is n= ot supported by Linux. > > IMHO, such dependency is out of UEFI spec. That means Debian/Ubuntu > doesn't follow the UEFI spec. (but as far as I know, those install ESP > on the disk and install GRUB efi application for boot) > And yes, EFI_LOAD_FILE2_PROTOCOL needs to load initrd from somewhere > (I'm usually put it on the ESP). But, if the EFI_LOAD_FILE2_PROTOCOL > *requires* to access ext4 partition, I think that is not supported by > UEFI spec. > > Anyway, I agree that denying access to non-FAT partitions is too > restricted. What about my other ideas? If the volume is set to > ReadOnly, that is good for both of the SCT and the > EFI_LOAD_FILE2_PROTOCOL. > If a volume or file is read only the UEFI spec requires to report this in EFI_FILE_PROTOCOL.GetInfo(). On partition level we have the following deficiencies in U-Boot: * we cannot (re-)mount a partition read-only * we cannot determine if a partition is read-only * we can neither read nor write the volume label * we cannot determine the free space. The current implementation of the FAT driver does not support reading attributes and dates. I have started looking into what is needed in the FAT driver. https://github.com/xypron/u-boot-patches/blob/bfe483ed97978678b124f8fe5796= 82aab6e3e9d8/patch-efi-next.sh#L91 But it is not ready for submission. Best regards Heinrich > > Thank you, > >> >> Best regards >> >> Heinrich >> >> >>> >>> >>>> >>>> Best regards >>>> >>>> Heinrich >>>> >>>> >>>>> Reported-by: Kazuhiko Sakamoto >>>>> Signed-off-by: Masami Hiramatsu >>>>> --- >>>>> lib/efi_loader/efi_disk.c | 18 ++++++++++++------ >>>>> 1 file changed, 12 insertions(+), 6 deletions(-) >>>>> >>>>> diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c >>>>> index 307d5d759b..f69ae6587f 100644 >>>>> --- a/lib/efi_loader/efi_disk.c >>>>> +++ b/lib/efi_loader/efi_disk.c >>>>> @@ -318,19 +318,25 @@ efi_fs_from_path(struct efi_device_path >>>>> *full_path) >>>>> } >>>>> >>>>> /** >>>>> - * efi_fs_exists() - check if a partition bears a file system >>>>> + * efi_supported_fs_exists() - check if a partition bears a >>> supported >>>>> file system >>>>> * >>>>> * @desc: block device descriptor >>>>> * @part: partition number >>>>> - * Return: 1 if a file system exists on the partition >>>>> + * Return: 1 if a supported file system exists on the partition >>>>> * 0 otherwise >>>>> */ >>>>> -static int efi_fs_exists(struct blk_desc *desc, int part) >>>>> +static int efi_supported_fs_exists(struct blk_desc *desc, int part) >>>>> { >>>>> if (fs_set_blk_dev_with_part(desc, part)) >>>>> return 0; >>>>> >>>>> - if (fs_get_type() =3D=3D FS_TYPE_ANY) >>>>> + /* >>>>> + * Because UEFI specification v2.9, 13.3 File System Format >>> said >>>>> + * "The file system supported by the Extensible Firmware >>> Interface >>>>> + * is based on the FAT file system.", the simple file system >>> protocol >>>>> + * should support only FAT filesystem. >>>>> + */ >>>>> + if (fs_get_type() !=3D FS_TYPE_FAT) >>>>> return 0; >>>>> >>>>> fs_close(); >>>>> @@ -428,10 +434,10 @@ static efi_status_t efi_disk_add_dev( >>>>> >>>>> /* >>>>> * On partitions or whole disks without partitions install >>> the >>>>> - * simple file system protocol if a file system is available. >>>>> + * simple file system protocol if a supported file system >>> exists. >>>>> */ >>>>> if ((part || desc->part_type =3D=3D PART_TYPE_UNKNOWN) && >>>>> - efi_fs_exists(desc, part)) { >>>>> + efi_supported_fs_exists(desc, part)) { >>>>> diskobj->volume =3D efi_simple_file_system(desc, part= , >>>>> >>> diskobj->dp); >>>>> ret =3D efi_add_protocol(&diskobj->header, >>>> >> > >