kern/file: Implement filesystem reference counting
authorB Horn <b@horn.uk>
Sun, 12 May 2024 09:15:03 +0000 (10:15 +0100)
committerFelix Zielcke <fzielcke@z-51.de>
Wed, 11 Jun 2025 15:42:34 +0000 (17:42 +0200)
commit0a8350156865644d2ac6a07941430c74ecf73eeb
tree2f4197ff767e3e3fd4cfe86eee543a666bbe85f9
parent7973cbca0ee83c711b62ef7ce6537f1913d97902
kern/file: Implement filesystem reference counting

The grub_file_open() and grub_file_close() should be the only places
that allow a reference to a filesystem to stay open. So, add grub_dl_t
to grub_fs_t and set this in the GRUB_MOD_INIT() for each filesystem to
avoid issues when filesystems forget to do it themselves or do not track
their own references, e.g. squash4.

The fs_label(), fs_uuid(), fs_mtime() and fs_read() should all ref and
unref in the same function but it is essentially redundant in GRUB
single threaded model.

Signed-off-by: B Horn <b@horn.uk>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Conflicts:
grub-core/fs/erofs.c

Gbp-Pq: Topic cve-2025-jan
Gbp-Pq: Name kern-file-Implement-filesystem-reference-counting.patch
30 files changed:
grub-core/fs/affs.c
grub-core/fs/bfs.c
grub-core/fs/btrfs.c
grub-core/fs/cbfs.c
grub-core/fs/cpio.c
grub-core/fs/cpio_be.c
grub-core/fs/ext2.c
grub-core/fs/f2fs.c
grub-core/fs/fat.c
grub-core/fs/hfs.c
grub-core/fs/hfsplus.c
grub-core/fs/iso9660.c
grub-core/fs/jfs.c
grub-core/fs/minix.c
grub-core/fs/newc.c
grub-core/fs/nilfs2.c
grub-core/fs/ntfs.c
grub-core/fs/odc.c
grub-core/fs/proc.c
grub-core/fs/reiserfs.c
grub-core/fs/romfs.c
grub-core/fs/sfs.c
grub-core/fs/squash4.c
grub-core/fs/tar.c
grub-core/fs/udf.c
grub-core/fs/ufs.c
grub-core/fs/xfs.c
grub-core/fs/zfs/zfs.c
grub-core/kern/file.c
include/grub/fs.h