grub2/grub-core/fs
Daniel Axtens 2ca0e5dbcd fs/hfsplus: Don't use uninitialized data on corrupt filesystems
Valgrind identified the following use of uninitialized data:

  ==2782220== Conditional jump or move depends on uninitialised value(s)
  ==2782220==    at 0x42B364: grub_hfsplus_btree_search (hfsplus.c:566)
  ==2782220==    by 0x42B21D: grub_hfsplus_read_block (hfsplus.c:185)
  ==2782220==    by 0x42A693: grub_fshelp_read_file (fshelp.c:386)
  ==2782220==    by 0x42C598: grub_hfsplus_read_file (hfsplus.c:219)
  ==2782220==    by 0x42C598: grub_hfsplus_mount (hfsplus.c:330)
  ==2782220==    by 0x42B8C5: grub_hfsplus_dir (hfsplus.c:958)
  ==2782220==    by 0x4C1AE6: grub_fs_probe (fs.c:73)
  ==2782220==    by 0x407C94: grub_ls_list_files (ls.c:186)
  ==2782220==    by 0x407C94: grub_cmd_ls (ls.c:284)
  ==2782220==    by 0x4D7130: grub_extcmd_dispatcher (extcmd.c:55)
  ==2782220==    by 0x4045A6: execute_command (grub-fstest.c:59)
  ==2782220==    by 0x4045A6: fstest (grub-fstest.c:433)
  ==2782220==    by 0x4045A6: main (grub-fstest.c:772)
  ==2782220==  Uninitialised value was created by a heap allocation
  ==2782220==    at 0x483C7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
  ==2782220==    by 0x4C0305: grub_malloc (mm.c:42)
  ==2782220==    by 0x42C21D: grub_hfsplus_mount (hfsplus.c:239)
  ==2782220==    by 0x42B8C5: grub_hfsplus_dir (hfsplus.c:958)
  ==2782220==    by 0x4C1AE6: grub_fs_probe (fs.c:73)
  ==2782220==    by 0x407C94: grub_ls_list_files (ls.c:186)
  ==2782220==    by 0x407C94: grub_cmd_ls (ls.c:284)
  ==2782220==    by 0x4D7130: grub_extcmd_dispatcher (extcmd.c:55)
  ==2782220==    by 0x4045A6: execute_command (grub-fstest.c:59)
  ==2782220==    by 0x4045A6: fstest (grub-fstest.c:433)
  ==2782220==    by 0x4045A6: main (grub-fstest.c:772)

This happens when the process of reading the catalog file goes sufficiently
wrong that there's an attempt to read the extent overflow file, which has
not yet been loaded. Keep track of when the extent overflow file is
fully loaded and refuse to use it before then.

The load valgrind doesn't like is btree->nodesize, and that's then used
to allocate a data structure. It looks like there are subsequently a lot
of reads based on that pointer so OOB reads are likely, and indeed crashes
(albeit difficult-to-replicate ones) have been observed in fuzzing.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2021-03-02 15:54:18 +01:00
..
zfs zfsinfo: Correct a check for error allocating memory 2021-03-02 15:54:16 +01:00
affs.c affs: Fix memory leaks 2021-03-02 15:54:16 +01:00
afs.c Leverage BFS implementation to read AFS. 2011-10-30 16:10:18 +01:00
archelp.c archelp: Never pass NULL as mtime. 2015-07-27 13:19:02 +02:00
bfs.c Change fs functions to add fs_ prefix 2019-04-09 10:03:29 +10:00
btrfs.c malloc: Use overflow checking primitives where we do complex allocations 2020-07-29 16:55:47 +02:00
cbfs.c disk: Rename grub_disk_get_size() to grub_disk_native_sectors() 2020-12-12 01:19:03 +01:00
cpio_be.c Add gcc_struct to all packed structures when compiling with mingw. 2013-12-15 14:14:30 +01:00
cpio_common.c cpio: Disable gcc9 -Waddress-of-packed-member 2019-04-23 11:37:08 +02:00
cpio.c Add gcc_struct to all packed structures when compiling with mingw. 2013-12-15 14:14:30 +01:00
exfat.c exfat reader 2011-04-11 18:13:00 +02:00
ext2.c malloc: Use overflow checking primitives where we do complex allocations 2020-07-29 16:55:47 +02:00
f2fs.c f2fs: Disable gcc9 -Waddress-of-packed-member 2019-06-03 11:18:31 +02:00
fat.c fat: Support file modification times 2020-03-10 21:52:07 +01:00
fshelp.c fs/fshelp: Catch impermissibly large block sizes in read helper 2021-03-02 15:54:18 +01:00
hfs.c calloc: Use calloc() at most places 2020-07-29 16:55:47 +02:00
hfsplus.c fs/hfsplus: Don't use uninitialized data on corrupt filesystems 2021-03-02 15:54:18 +01:00
hfspluscomp.c Make grub_zlib_decompress handle incomplete chunks. 2013-12-18 23:39:49 +01:00
iso9660.c iso9660: Don't leak memory on realloc() failures 2020-07-29 16:55:48 +02:00
jfs.c jfs: Disable gcc9 -Waddress-of-packed-member 2019-04-23 11:37:08 +02:00
minix2_be.c Handle big-endian minixfs (fixes minixfs tests on bigendian). 2012-04-01 21:35:18 +02:00
minix2.c Split minix.mod into minix.mod and minix2.mod. 2010-09-08 19:13:48 +02:00
minix3_be.c Handle big-endian minixfs (fixes minixfs tests on bigendian). 2012-04-01 21:35:18 +02:00
minix3.c minix3fs support 2011-04-11 08:16:13 +02:00
minix_be.c Handle big-endian minixfs (fixes minixfs tests on bigendian). 2012-04-01 21:35:18 +02:00
minix.c Change fs functions to add fs_ prefix 2019-04-09 10:03:29 +10:00
newc.c Add gcc_struct to all packed structures when compiling with mingw. 2013-12-15 14:14:30 +01:00
nilfs2.c disk: Rename grub_disk_get_size() to grub_disk_native_sectors() 2020-12-12 01:19:03 +01:00
ntfs.c calloc: Use calloc() at most places 2020-07-29 16:55:47 +02:00
ntfscomp.c Fix warnings when compiling with -O3 2016-02-17 17:56:41 +01:00
odc.c Add gcc_struct to all packed structures when compiling with mingw. 2013-12-15 14:14:30 +01:00
proc.c Change fs functions to add fs_ prefix 2019-04-09 10:03:29 +10:00
reiserfs.c Change fs functions to add fs_ prefix 2019-04-09 10:03:29 +10:00
romfs.c Change fs functions to add fs_ prefix 2019-04-09 10:03:29 +10:00
sfs.c malloc: Use overflow checking primitives where we do complex allocations 2020-07-29 16:55:47 +02:00
squash4.c malloc: Use overflow checking primitives where we do complex allocations 2020-07-29 16:55:47 +02:00
tar.c calloc: Use calloc() at most places 2020-07-29 16:55:47 +02:00
udf.c udf: Fix memory leak 2020-07-29 16:55:48 +02:00
ufs2.c automake commit without merge history 2010-05-06 11:34:04 +05:30
ufs_be.c Support big-endian UFS1. 2012-12-08 20:56:58 +01:00
ufs.c Change fs functions to add fs_ prefix 2019-04-09 10:03:29 +10:00
xfs.c malloc: Use overflow checking primitives where we do complex allocations 2020-07-29 16:55:47 +02:00