android_kernel_xiaomi_sm8450/fs/incfs
Tadeusz Struk fd4c6594f5 ANDROID: incremental-fs: fix mount_fs issue
Syzbot recently found a number of issues related to incremental-fs
(see bug numbers below). All have to do with the fact that incr-fs
allows mounts of the same source and target multiple times.
The correct behavior for a file system is to allow only one such
mount, and then every subsequent attempt should fail with a -EBUSY
error code. In case of the issues listed below the common pattern
is that the reproducer calls:

mount("./file0", "./file0", "incremental-fs", 0, NULL)

many times and then invokes a file operation like chmod, setxattr,
or open on the ./file0. This causes a recursive call for all the
mounted instances, which eventually causes a stack overflow and
a kernel crash:

BUG: stack guard page was hit at ffffc90000c0fff8
kernel stack overflow (double-fault): 0000 [#1] PREEMPT SMP KASAN

The reason why many mounts with the same source and target are
possible is because the incfs_mount_fs() as it is allocates a new
super_block for every call, regardless of whether a given mount already
exists or not. This happens every time the sget() function is called
with a test param equal to NULL.
The correct behavior for an FS mount implementation is to call
appropriate mount vfs call for it's type, i.e. mount_bdev() for
a block device backed FS, mount_single() for a pseudo file system,
like sysfs that is mounted in a single, well know location, or
mount_nodev() for other special purpose FS like overlayfs.
In case of incremental-fs the open coded mount logic doesn't check
for abusive mount attempts such as overlays.
To fix this issue the logic needs to be changed to pass a proper
test function to sget() call, which then checks if a super_block
for a mount instance has already been allocated and also allows
the VFS to properly verify invalid mount attempts.

Bug: 211066171
Bug: 213140206
Bug: 213215835
Bug: 211914587
Bug: 211213635
Bug: 213137376
Bug: 211161296

Signed-off-by: Tadeusz Struk <tadeusz.struk@linaro.org>
Change-Id: I66cfc3f1b5aaffb32b0845b2dad3ff26fe952e27
2022-01-24 21:39:27 +00:00
..
data_mgmt.c ANDROID: incremental-fs: fix mount_fs issue 2022-01-24 21:39:27 +00:00
data_mgmt.h ANDROID: Incremental fs: Add uid to INCFS_IOC_GET_LAST_READ_ERROR 2021-05-17 20:08:43 +00:00
format.c ANDROID: Incremental fs: fix minor printk format warning 2021-04-15 15:22:01 +00:00
format.h ANDROID: Incremental fs: Build merkle tree when enabling verity 2021-03-01 16:16:01 +00:00
integrity.c ANDROID: Incremental fs: Remove dependency on PKCS7_MESSAGE_PARSER 2020-06-08 17:03:32 +00:00
integrity.h ANDROID: Incremental fs: Remove signature checks from kernel 2020-03-18 16:22:17 +00:00
internal.h ANDROID: Incremental fs: Add FS_IOC_ENABLE_VERITY 2021-03-01 16:15:32 +00:00
Kconfig ANDROID: Incremental fs: Add zstd compression support 2020-11-05 23:00:32 +00:00
main.c ANDROID: GKI: set vfs-only exports into their own namespace 2022-01-11 09:30:47 +01:00
Makefile ANDROID: Incremental fs: Add status to sysfs 2021-04-23 15:16:25 +00:00
pseudo_files.c ANDROID: Incremental fs: Add uid to INCFS_IOC_GET_LAST_READ_ERROR 2021-05-17 20:08:43 +00:00
pseudo_files.h ANDROID: Incremental fs: fix .blocks_written 2021-01-14 16:02:38 +00:00
sysfs.c ANDROID: Incremental fs: Make sysfs_name changeable on remount 2021-05-17 20:08:37 +00:00
sysfs.h ANDROID: Incremental fs: Make sysfs_name changeable on remount 2021-05-17 20:08:37 +00:00
verity.c ANDROID: Incremental fs: Add status to sysfs 2021-04-23 15:16:25 +00:00
verity.h ANDROID: Incremental fs: Add FS_IOC_READ_VERITY_METADATA 2021-04-23 15:16:03 +00:00
vfs.c ANDROID: incremental-fs: fix mount_fs issue 2022-01-24 21:39:27 +00:00
vfs.h ANDROID: incremental-fs: fix mount_fs issue 2022-01-24 21:39:27 +00:00