grub2/grub-core
Erwan Velu bf29fbd997 fs/xfs: Fix unreadable filesystem with v4 superblock
The commit 8b1e5d193 (fs/xfs: Add bigtime incompat feature support)
introduced the bigtime support by adding some features in v3 inodes.
This change extended grub_xfs_inode struct by 76 bytes but also changed
the computation of XFS_V2_INODE_SIZE and XFS_V3_INODE_SIZE. Prior this
commit, XFS_V2_INODE_SIZE was 100 bytes. After the commit it's 84 bytes
XFS_V2_INODE_SIZE becomes 16 bytes too small.

As a result, the data structures aren't properly aligned and the GRUB
generates "attempt to read or write outside of partition" errors when
trying to read the XFS filesystem:

                             GNU GRUB  version 2.11
	....
	grub> set debug=efi,gpt,xfs
	grub> insmod part_gpt
	grub> ls (hd0,gpt1)/
	partmap/gpt.c:93: Read a valid GPT header
	partmap/gpt.c:115: GPT entry 0: start=4096, length=1953125
	fs/xfs.c:931: Reading sb
	fs/xfs.c:270: Validating superblock
	fs/xfs.c:295: XFS v4 superblock detected
	fs/xfs.c:962: Reading root ino 128
	fs/xfs.c:515: Reading inode (128) - 64, 0
	fs/xfs.c:515: Reading inode (739521961424144223) - 344365866970255880, 3840
	error: attempt to read or write outside of partition.

This commit change the XFS_V2_INODE_SIZE computation by subtracting 76
bytes instead of 92 bytes from the actual size of grub_xfs_inode struct.
This 76 bytes value comes from added members:
	20 grub_uint8_t   unused5
	 1 grub_uint64_t  flags2
        48 grub_uint8_t   unused6

This patch explicitly splits the v2 and v3 parts of the structure.
The unused4 is still ending of the v2 structures and the v3 starts
at unused5. Thanks to this we will avoid future corruptions of v2
or v3 inodes.

The XFS_V2_INODE_SIZE is returning to its expected size and the
filesystem is back to a readable state:

                      GNU GRUB  version 2.11
	....
	grub> set debug=efi,gpt,xfs
	grub> insmod part_gpt
	grub> ls (hd0,gpt1)/
	partmap/gpt.c:93: Read a valid GPT header
	partmap/gpt.c:115: GPT entry 0: start=4096, length=1953125
	fs/xfs.c:931: Reading sb
	fs/xfs.c:270: Validating superblock
	fs/xfs.c:295: XFS v4 superblock detected
	fs/xfs.c:962: Reading root ino 128
	fs/xfs.c:515: Reading inode (128) - 64, 0
	fs/xfs.c:515: Reading inode (128) - 64, 0
	fs/xfs.c:931: Reading sb
	fs/xfs.c:270: Validating superblock
	fs/xfs.c:295: XFS v4 superblock detected
	fs/xfs.c:962: Reading root ino 128
	fs/xfs.c:515: Reading inode (128) - 64, 0
	fs/xfs.c:515: Reading inode (128) - 64, 0
	fs/xfs.c:515: Reading inode (128) - 64, 0
	fs/xfs.c:515: Reading inode (131) - 64, 768
	efi/ fs/xfs.c:515: Reading inode (3145856) - 1464904, 0
	grub2/ fs/xfs.c:515: Reading inode (132) - 64, 1024
	grub/ fs/xfs.c:515: Reading inode (139) - 64, 2816
	grub>

Fixes: 8b1e5d193 (fs/xfs: Add bigtime incompat feature support)

Signed-off-by: Erwan Velu <e.velu@criteo.com>
Tested-by: Carlos Maiolino <cmaiolino@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>

Origin: upstream, https://git.savannah.gnu.org/cgit/grub.git/commit/?id=a4b495520e4dc41a896a8b916a64eda9970c50ea
Last-Update: 2021-09-24

Patch-Name: xfs-fix-v4-superblock.patch
2021-09-27 20:09:39 +01:00
..
boot Add configure option to reduce visual clutter at boot time 2021-09-27 20:09:38 +01:00
bus usb/usbhub: Use GRUB_USB_MAX_CONF macro instead of literal in hub for maximum configs 2021-04-12 16:26:49 +02:00
commands tpm: Pass unknown error as non-fatal, but debug print the error we got 2021-09-27 20:09:39 +01:00
disk i18n: Format large integers before the translation message 2021-04-13 17:16:04 +02:00
efiemu i18n: Format large integers before the translation message 2021-04-13 17:16:04 +02:00
font font: Do not load more than one NAME section 2020-07-29 16:55:48 +02:00
fs fs/xfs: Fix unreadable filesystem with v4 superblock 2021-09-27 20:09:39 +01:00
gdb gdb: Restrict GDB access when locked down 2021-03-02 15:54:15 +01:00
gettext Silence error messages when translations are unavailable 2021-09-24 22:18:50 +01:00
gfxmenu gfxmenu/gui: Check printf() format in the gui_progress_bar and gui_label 2021-03-02 15:54:20 +01:00
hello * grub-core/commands/gptsync.c: Fix typographic quoting. 2012-03-03 13:05:08 +01:00
hook * grub-core/hook/datehook.c (grub_read_hook_datetime): Small stylistic 2011-11-11 21:03:49 +01:00
io io/gzio: Zero gzio->tl/td in init_dynamic_block() if huft_build() fails 2021-03-02 15:54:18 +01:00
kern Add debug to display what's going on with verifiers 2021-09-27 20:09:39 +01:00
lib Import grub2_2.06.orig.tar.xz 2021-09-24 10:34:42 +01:00
loader Do not overwrite sentinel byte in boot_params, breaks lockdown 2021-09-27 20:09:39 +01:00
mmap mmap: Fix memory leak when iterating over mapped memory 2021-03-02 15:54:15 +01:00
net efinet: Setting DNS server from UEFI protocol 2021-09-27 20:09:39 +01:00
normal Add configure option to bypass boot menu if possible 2021-09-27 20:09:38 +01:00
osdep Minimise writes to EFI variable storage 2021-09-27 20:09:39 +01:00
partmap mbr: Warn if MBR gap is small and user uses advanced modules 2020-12-12 01:19:03 +01:00
parttool parttool/msdospart: grub_error() missing format string argument 2021-03-10 14:50:44 +01:00
script misc: Format string for grub_error() should be a literal 2021-03-10 14:50:44 +01:00
term at_keyboard: initialize keyboard in module init if keyboard is ready 2021-09-27 20:09:39 +01:00
tests fs: Use 64-bit type for filesystem timestamp 2021-06-01 17:19:13 +02:00
video Blacklist 1440x900x32 from VBE preferred mode handling 2021-09-24 23:29:41 +01:00
gdb_grub.in * grub-core/gdb_grub.in: Fix overflow and wrong field. 2013-10-14 03:40:20 +02:00
genemuinit.sh use MODULE_FILES for genemuinit* instead of MOD_FILES 2014-01-18 23:15:40 +04:00
genemuinitheader.sh use MODULE_FILES for genemuinit* instead of MOD_FILES 2014-01-18 23:15:40 +04:00
genmod.sh.in .mod files: Strip annobin annotations and .eh_frame, and their relocations 2018-03-05 14:08:22 +01:00
genmoddep.awk enforcing fixup 2017-08-14 16:27:10 +02:00
gensyminfo.sh.in Fix shebang for termux. 2017-05-03 12:49:31 +02:00
gensymlist.sh Make 'make check' work on emu. 2013-04-27 02:00:16 +02:00
gentrigtables.c * grub-core/gentrigtables.c: Make tables const. 2013-03-01 11:15:09 +01:00
gmodule.pl.in * grub-core/gmodule.pl.in: Accept newer binutils which output 2014-09-21 18:23:23 +02:00
Makefile.am i386-pc: build verifiers API as module 2021-09-27 20:09:39 +01:00
Makefile.core.am Import grub2_2.06.orig.tar.xz 2021-09-24 10:34:42 +01:00
Makefile.core.def i386-pc: build verifiers API as module 2021-09-27 20:09:39 +01:00
Makefile.gcry.def Import grub2_2.02~beta3.orig.tar.xz 2016-09-18 17:40:00 +01:00
Makefile.in Import grub2_2.06.orig.tar.xz 2021-09-24 10:34:42 +01:00
modinfo.sh.in Fix shebang for termux. 2017-05-03 12:49:31 +02:00
unidata.c Import grub2_2.02~beta3.orig.tar.xz 2016-09-18 17:40:00 +01:00