u-boot/fs
Alexander Dahl df86e81f0a fs: ubifs: Fix memleak and double free in u-boot wrapper functions
When mounting ubifs e.g. through command 'ubifsmount' one global static
superblock 'ubifs_sb' is used _and_ the requested volume is opened (like
in Linux).  The pointer returned by 'ubifs_open_volume()' is stored in
that superblock struct and freed later on cmd 'ubifsumount' or another
call to 'ubifsmount' with a different volume, through ubifs_umount() and
ubi_close_volume().

In ubifs_ls(), ubifs_exists(), ubifs_size(), and ubifs_read() the volume
was opened again, which is technically no problem with regard to
refcounting, but here the still valid pointer in sb was overwritten,
leading to a memory leak.  Even worse, when using one of those
functions and calling ubifsumount later, ubi_close_volume() was called
again but now on an already freed pointer, leading to a double free.
This actually crashed with different invalid memory accesses on a board
using the old distro boot and a rather long script handling RAUC
updates.

Example:

    > ubi part UBI
    > ubifsmount ubi0:boot
    > test -e ubi ubi0:boot /boot.scr.uimg
    > ubifsumount

The ubifs specific commands 'ubifsls' and 'ubifsload' check for a
mounted volume by themselves, for the generic fs variants 'ls', 'load',
(and 'size', and 'test -e') this is covered by special ubifs handling in
fs_set_blk_dev() and deeper down blk_get_device_part_str() then.  So for
ubifs_ls(), ubifs_exists(), ubifs_size(), and ubifs_read() we can be
sure the volume is opened and the necessary struct pointer in sb is
valid, so it is not needed to open volume again.

Fixes: 9eefe2a2b3 ("UBIFS: Implement read-only UBIFS support in U-Boot")
Fixes: 29cc5bcadf ("ubifs: Add functions for generic fs use")
Signed-off-by: Alexander Dahl <ada@thorsis.com>
2024-08-10 11:54:02 +02:00
..
btrfs fs: Remove duplicate newlines 2024-07-15 12:12:17 -06:00
cbfs Restore patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet" 2024-05-20 13:35:03 -06:00
cramfs Restore patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet" 2024-05-20 13:35:03 -06:00
erofs fs/erofs: fix an overflow issue of unmapped extents 2024-06-14 12:59:06 -06:00
ext4 fs: Remove duplicate newlines 2024-07-15 12:12:17 -06:00
fat Restore patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet" 2024-05-20 13:35:03 -06:00
jffs2 fs: Remove duplicate newlines 2024-07-15 12:12:17 -06:00
sandbox Restore patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet" 2024-05-20 13:35:03 -06:00
squashfs fs/squashfs: enable LZ4 compression support 2023-11-16 18:53:09 -05:00
ubifs fs: ubifs: Fix memleak and double free in u-boot wrapper functions 2024-08-10 11:54:02 +02:00
yaffs2 fs: Remove duplicate newlines 2024-07-15 12:12:17 -06:00
zfs fs: Remove duplicate newlines 2024-07-15 12:12:17 -06:00
fs.c fs: relax ext4_write_file() dependency 2024-06-07 16:20:27 -06:00
fs_internal.c Restore patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet" 2024-05-20 13:35:03 -06:00
Kconfig fs: drop reiserfs 2024-03-04 10:25:47 -05:00
Makefile fs: drop reiserfs 2024-03-04 10:25:47 -05:00
semihostingfs.c Restore patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet" 2024-05-20 13:35:03 -06:00