summaryrefslogtreecommitdiff
path: root/Features/Ext4Pkg/Ext4Dxe/Directory.c
AgeCommit message (Collapse)AuthorFilesLines
2023-02-08Ext4Pkg: Filter out directory entry names containing \0 as invalidSavva Mitrofanov1-1/+8
The directory entry name conventions forbid having null-terminator symbols in its body and can lead to undefined behavior conditions and crashes Cc: Marvin Häuser <mhaeuser@posteo.de> Cc: Pedro Falcato <pedro.falcato@gmail.com> Cc: Vitaly Cheptsov <vit9696@protonmail.com> Fixes: 89b2bb0db263 ("Ext4Pkg: Fix and clarify handling regarding non-utf8 dir entries") Signed-off-by: Savva Mitrofanov <savvamtr@gmail.com> Reviewed-by: Pedro Falcato <pedro.falcato@gmail.com> Reviewed-by: Marvin Häuser <mhaeuser@posteo.de>
2023-02-08Ext4Pkg: Add missing exit status in Ext4OpenDirentSavva Mitrofanov1-1/+2
Missing EFI_OUT_OF_RESOURCES exit status on failed Ext4CreateDentry leads to NULL-pointer dereference in Ext4GetFileInfo (passing NULL buffer in Ext4ReadDir) Cc: Marvin Häuser <mhaeuser@posteo.de> Cc: Pedro Falcato <pedro.falcato@gmail.com> Cc: Vitaly Cheptsov <vit9696@protonmail.com> Fixes: 21b1853880d5 ("Ext4Pkg: Add a directory entry tree.") Signed-off-by: Savva Mitrofanov <savvamtr@gmail.com> Reviewed-by: Pedro Falcato <pedro.falcato@gmail.com> Reviewed-by: Marvin Häuser <mhaeuser@posteo.de>
2023-02-08Ext4Pkg: Fix memory leak in Ext4RetrieveDirentSavva Mitrofanov1-14/+16
We need to free buffer on return if BlockRemainder != 0. Also changed return logic from function to use use common exit to prevent code duplication. Cc: Marvin Häuser <mhaeuser@posteo.de> Cc: Pedro Falcato <pedro.falcato@gmail.com> Cc: Vitaly Cheptsov <vit9696@protonmail.com> Fixes: d9ceedca6c8f ("Ext4Pkg: Add Ext4Dxe driver.") Signed-off-by: Savva Mitrofanov <savvamtr@gmail.com> Reviewed-by: Pedro Falcato <pedro.falcato@gmail.com> Reviewed-by: Marvin Häuser <mhaeuser@posteo.de>
2023-01-30Ext4Pkg: Redirect internal Open("..", /) to the proper "/"Pedro Falcato1-1/+5
We have been hitting many issues with ".." ASSERTing on / in internal code, so make sure that we direct /.. to /. This is safe. Signed-off-by: Pedro Falcato <pedro.falcato@gmail.com> Cc: Marvin Häuser <mhaeuser@posteo.de> Reported-by: Savva Mitrofanov <savvamtr@gmail.com> Reviewed-by: Marvin Häuser <mhaeuser@posteo.de>
2023-01-26Ext4Pkg: Fix typos discovered by SpellCheckMarvin Häuser1-1/+1
Fix typos discovered by SpellCheck, which were discovered as part of the initial CI enablement effort. Cc: Pedro Falcato <pedro.falcato@gmail.com> Signed-off-by: Marvin Häuser <mhaeuser@posteo.de> Reviewed-by: Pedro Falcato <pedro.falcato@gmail.com>
2023-01-26Ext4Pkg: Fix and clarify handling regarding non-utf8 dir entriesPedro Falcato1-7/+30
Previously, the handling was mixed and/or non-existent regarding non utf-8 dirent names. Clarify it. Signed-off-by: Pedro Falcato <pedro.falcato@gmail.com> Cc: Marvin Häuser <mhaeuser@posteo.de> Reviewed-by: Marvin Häuser <mhaeuser@posteo.de>
2023-01-26Ext4Pkg: Fix out-of-bounds read in Ext4ReadDirPedro Falcato1-6/+8
Fix an out-of-bounds read inside CompareMem() when checking for "." or ".." by explicitly bounding name_len to [0, 2] beforehand. Reported-by: Savva Mitrofanov <savvamtr@gmail.com> Fixes: 45e37d8533ca8 ("Ext4Pkg: Hide "." and ".." entries from Read() callers.") Cc: Marvin Häuser <mhaeuser@posteo.de> Signed-off-by: Pedro Falcato <pedro.falcato@gmail.com> Reviewed-by: Marvin Häuser <mhaeuser@posteo.de>
2022-08-07Ext4Pkg: Code correctness and security improvementsSavva Mitrofanov1-26/+3
This changes tends to improve security of code sections by fixing integer overflows, missing alignment checks, unsafe casts, also simplified some routines, fixed compiler warnings and corrected some code mistakes. - Set HoleLen to UINT64 to prevent truncation in Ext4Read function - Replace EXT4_BLOCK_NR with 32-bit EXT2_BLOCK_NR in BlockMap, because by specification files using block maps must be placed within the first 2^32 blocks of a filesystem - Replace UNREACHABLE with ASSERT (FALSE) in case of new checksum algorithms, due to it is an invariant violation rather than unreachable path - Solve compiler warnings. Initialize all fields in gExt4BindingProtocol Fix comparison of integer expressions of different signedness - Field name_len has type CHAR8, while filename limit is 255 (EXT4_NAME_MAX), so because structure EXT4_DIR_ENTRY would be unchangeable in future, we could drop this check without any assertions - Simplify Ext4RemoveDentry logic by using IsNodeInList - Fix possible int overflow in Ext4ExtentsMapKeyCompare - Return bad block type in Ext4GetBlockpath - Adds 4-byte aligned check for superblock group descriptor size field Cc: Marvin Häuser <mhaeuser@posteo.de> Cc: Pedro Falcato <pedro.falcato@gmail.com> Cc: Vitaly Cheptsov <vit9696@protonmail.com> Signed-off-by: Savva Mitrofanov <savvamtr@gmail.com> Reviewed-by: Marvin Häuser <mhaeuser@posteo.de> Reviewed-by: Pedro Falcato <pedro.falcato@gmail.com>
2022-06-14Ext4Pkg: Format using uncrustifyPedro Falcato1-6/+7
Previously, Ext4Pkg was formatted using uncrustify with an older config file. Re-format it using the upstream edk2 uncrustify config file. Cc: Leif Lindholm <leif@nuviainc.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Signed-off-by: Pedro Falcato <pedro.falcato@gmail.com> Acked-by: Liming Gao <gaoliming@byosoft.com.cn>
2021-08-24Ext4Pkg: Sanity check more EXT4_DIR_ENTRY values.Pedro Falcato1-39/+51
This should close up some possible exploits using crafted filesystem images. Cc: Leif Lindholm <leif@nuviainc.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Bret Barkelew <Bret.Barkelew@microsoft.com> Signed-off-by: Pedro Falcato <pedro.falcato@gmail.com> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
2021-08-24Ext4Pkg: Add a directory entry tree.Pedro Falcato1-43/+195
This helps us track directories and directory entries, which helps us getting a general idea of how the filesystem looks. In the future, it might serve as a directory cache. Right now, it only lets us know which name "." and ".." may refer to, which fixes a EFI_FILE_PROTOCOL::GetInfo() bug that got triggered by ShellPkg, in some MdePkg code. Cc: Leif Lindholm <leif@nuviainc.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Bret Barkelew <Bret.Barkelew@microsoft.com> Signed-off-by: Pedro Falcato <pedro.falcato@gmail.com> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
2021-08-24Ext4Pkg: Hide "." and ".." entries from Read() callers.Pedro Falcato1-8/+37
This makes it so callers that may expect FAT32 filesystems (most do) have more normal looking ReadDir() results. This commit also presents a better filename for files opened through Open("."). Cc: Leif Lindholm <leif@nuviainc.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Bret Barkelew <Bret.Barkelew@microsoft.com> Signed-off-by: Pedro Falcato <pedro.falcato@gmail.com> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
2021-08-19Ext4Pkg: Add Ext4Dxe driver.Pedro Falcato1-0/+498
Adds a UEFI EXT4 filesystem driver that implements the EFI_FILE_PROTOCOL and EFI_SIMPLE_FILE_SYSTEM_PROTOCOL. Cc: Leif Lindholm <leif@nuviainc.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Bret Barkelew <Bret.Barkelew@microsoft.com> Signed-off-by: Pedro Falcato <pedro.falcato@gmail.com> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
2021-08-19Revert "Ext4Pkg: Add Ext4Dxe driver." to correct AuthorMichael D Kinney1-498/+0
This reverts commit ac10729d2c9482aff7c37545c8d84d38b685c1d9. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2021-08-18Ext4Pkg: Add Ext4Dxe driver.devel@edk2.groups.io1-0/+498
Adds a UEFI EXT4 filesystem driver that implements the EFI_FILE_PROTOCOL and EFI_SIMPLE_FILE_SYSTEM_PROTOCOL. Cc: Leif Lindholm <leif@nuviainc.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Bret Barkelew <Bret.Barkelew@microsoft.com> Signed-off-by: Pedro Falcato <pedro.falcato@gmail.com> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>