В ядре Linux устранена следующая уязвимость: handlock: Fix superblock use-after-free in release_inode() Without this fix, release_inode() (задача 1) может участвовать в гонках с операцией umount в hook_sb_delete() (задача 2). Порядок операций, в котором происходит гонка: * задача 2: hook_sb_delete() прибывает в конец функции, ожидая, что landlock_superblock(sb)->inode_refs станет нулевым. * задача 1: release_inode(): делает ли atomic_long_dec_and_test(), уменьшая inode_refs до нуля. * задача 2: просыпается с помощью каких-то других средств, видит, что inode_refs равен нулю и возвращается. Вызывающее устройство является операцией размонтирования и приступает к выпуску суперблока. * задача 1: Runs wake_up_var(&landlock_superblock(sb)->inode_refs), * отсылая sb_security на освободившийся суперблок*.
Примечательно, что wake_up_var() не отсылает указатель, переданный ему, а только использует его для определения чрезмерно приближенного набора задач для пробуждения. Таким образом, хотя злоумышленник потенциально может предоставить другое значение для этого указателя, это приводит только к тому, что просыпается неправильный набор задач, и в этом сценарии никаких дальнейших задач на самом деле не ждут. Тем не менее, KASAN обнаруживает его как slab-use-after-free, прочитанный по sb->s_security: BUG: KASAN: slab-use-after-free в release_inode+0x196/0x290 Read размера 8 в addr ffff888103b6c0a8 по задаче repro/217 release_inode+0x196/0x290 landlock_put_object+0x71/0x90 landlock_free_rules+0x38/0xc0 landlock_put_ruleset+0x47/0x130 fop_ruleset_release+0x33/0x40 __fput+0x305/0x780 Freed по задаче 54: kfree+0x11c/0x390 process_scheduled_works+0x766/0xe50 worker_thread+0x7bc/0xb20 The, чтобы определить &landlock_superblock(inode->i_sb)->inode_refs только один раз ранее в release_inode(), и позже использовать этот предварительно вычисленный адрес для вызова wake_up_var(), без необходимости удаления ссылки через суперблок.
Показать оригинальное описание (EN)
In the Linux kernel, the following vulnerability has been resolved: landlock: Fix superblock use-after-free in release_inode() Without this fix, release_inode() (task 1) can race with a umount operation in hook_sb_delete() (task 2). The order of operations in which the race occurs is: * task 2: hook_sb_delete() arrives at the end of the function, waiting for landlock_superblock(sb)->inode_refs to become zero. * task 1: release_inode(): does atomic_long_dec_and_test(), decrementing inode_refs to zero. * task 2: gets woken up through some other means, sees that inode_refs is zero and returns. The caller is the unmount operation and proceeds to release the superblock. * task 1: Runs wake_up_var(&landlock_superblock(sb)->inode_refs), *dereferencing the sb_security on the freed-up superblock*. Notably, wake_up_var() does not dereference the pointer passed to it, and only uses it to determine an overapproximated set of tasks to wake up. So while it's potentially possible for an attacker to provide a different value for that pointer, this only results in the wrong set of tasks getting woken up, and in this scenario, no further tasks are actually waiting. Nevertheless, KASAN detects it as a slab-use-after-free read on sb->s_security: BUG: KASAN: slab-use-after-free in release_inode+0x196/0x290 Read of size 8 at addr ffff888103b6c0a8 by task repro/217 release_inode+0x196/0x290 landlock_put_object+0x71/0x90 landlock_free_rules+0x38/0xc0 landlock_put_ruleset+0x47/0x130 fop_ruleset_release+0x33/0x40 __fput+0x305/0x780 Freed by task 54: kfree+0x11c/0x390 process_scheduled_works+0x766/0xe50 worker_thread+0x7bc/0xb20 The fix is to determine &landlock_superblock(inode->i_sb)->inode_refs only once earlier in release_inode(), and later use that precalculated address for the wake_up_var() call, without having to dereference through the superblock.