linux/fs/f2fs
Eric Biggers 6fe4e4b825 fscrypt: Avoid dynamic allocation in fscrypt_get_devices()
When a blk_crypto_key starts being used or is evicted, fs/crypto/ calls
fscrypt_get_devices() to get the filesystem's list of block devices,
then iterates over them and calls blk_crypto_config_supported(),
blk_crypto_start_using_key(), or blk_crypto_evict_key() on each one.

Currently, the block device pointers are placed in a dynamically
allocated array.  This dynamic allocation is problematic because:

- It can fail, especially at the fscrypt_destroy_inline_crypt_key() call
  site when it's invoked for inode eviction under direct reclaim.

- fscrypt_destroy_inline_crypt_key() doesn't handle the failure.  It
  just zeroizes and frees the blk_crypto_key without calling
  blk_crypto_evict_key().  That causes a use-after-free.

For now, let's fix this in the straightforward and easily-backportable
way by switching to an on-stack array.  Currently the fscrypt
multi-device functionality is used only by f2fs, which has a hardcoded
limit of 8 block devices.  An on-stack array works fine for that.

(Of course, this solution won't scale up to large number of block
devices.  For that we'd need a different solution, like moving the block
device iteration into the filesystem.  Or in the case of btrfs, which
will only support blk-crypto-fallback, we should make it just call
blk-crypto-fallback directly, so the block devices won't be needed.)

Fixes: 22e9947a4b ("fscrypt: stop holding extra request_queue references")
Cc: stable@vger.kernel.org
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/patchset/20260713023708.9245-1-ebiggers%40kernel.org
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://patch.msgid.link/20260719055602.78828-1-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
2026-07-20 10:39:24 -07:00
..
acl.c f2fs: validate ACL entry sizes in f2fs_acl_from_disk() 2026-06-22 19:52:37 +00:00
acl.h f2fs: Pass folios to f2fs_init_acl() 2025-04-28 15:26:41 +00:00
checkpoint.c f2fs: validate orphan inode entry count 2026-06-22 19:52:36 +00:00
compress.c f2fs: remove unneeded f2fs_is_compressed_page() 2026-06-22 19:52:38 +00:00
data.c f2fs: Split f2fs_write_end_io() 2026-06-22 19:52:37 +00:00
debug.c f2fs: Add defrag_blocks sysfs node 2026-03-24 17:20:59 +00:00
dir.c f2fs: validate dentry name length before lookup compares it 2026-06-22 19:52:37 +00:00
extent_cache.c f2fs: fix incorrect FI_NO_EXTENT handling in __destroy_extent_node() 2026-05-22 03:49:06 +00:00
f2fs.h f2fs: Rename f2fs_post_read_wq into f2fs_wq 2026-06-22 19:52:37 +00:00
file.c f2fs: fix to round down start offset of fallocate for pin file 2026-06-22 19:55:27 +00:00
gc.c f2fs: fix wrong description in printed log 2026-06-22 19:52:38 +00:00
gc.h f2fs: set default valid_thresh_ratio to 80 for zoned devices 2025-10-24 21:23:55 +00:00
hash.c fs: add helpers name_is_dot{,dot,_dotdot} 2026-01-29 10:06:59 +01:00
inline.c f2fs: validate inline dentry name lengths before conversion 2026-06-22 19:52:36 +00:00
inode.c f2fs: bound i_inline_xattr_size for non-inline-xattr inodes 2026-06-22 19:52:37 +00:00
iostat.c f2fs: add page-order information for large folio reads in iostat 2026-04-18 22:44:42 +00:00
iostat.h f2fs: add page-order information for large folio reads in iostat 2026-04-18 22:44:42 +00:00
Kconfig f2fs: switch to using the crc32 library 2024-12-01 17:23:02 -08:00
Makefile
namei.c f2fs-for-7.1-rc1 2026-04-21 14:50:04 -07:00
node.c f2fs: fix to do sanity check on f2fs_get_node_folio_ra() 2026-06-22 19:52:36 +00:00
node.h f2fs: annotate lockless NAT counter reads 2026-06-22 19:52:34 +00:00
recovery.c f2fs: support to report fserror 2026-05-22 03:49:06 +00:00
segment.c f2fs: avoid unnecessary sanity check on ckpt_valid_blocks 2026-06-22 19:52:38 +00:00
segment.h Revert: "f2fs: check in-memory sit version bitmap" 2026-06-22 19:52:35 +00:00
shrinker.c f2fs: handle error cases of memory donation 2025-05-06 15:46:55 +00:00
super.c fscrypt: Avoid dynamic allocation in fscrypt_get_devices() 2026-07-20 10:39:24 -07:00
sysfs.c f2fs: support to report fserror 2026-05-22 03:49:06 +00:00
verity.c f2fs: support to report fserror 2026-05-22 03:49:06 +00:00
xattr.c f2fs: fix listxattr handling of corrupted xattr entries 2026-06-22 19:55:27 +00:00
xattr.h f2fs: use global inline_xattr_slab instead of per-sb slab cache 2025-12-04 02:00:02 +00:00