Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ntfs: reduce stack usage in ntfs_write_mft_block()

The use of two large arrays in this function makes the stack frame exceed
the warning limit in some configurations, especially with KASAN enabled.
When CONFIG_PAGE_SIZE is set to 65536, each of the arrays contains 128
pointers, so the combined size is 2KB:

fs/ntfs/mft.c: In function 'ntfs_write_mft_block.isra':
fs/ntfs/mft.c:2891:1: error: the frame size of 2640 bytes is larger than 1536 bytes [-Werror=frame-larger-than=]

Use dynamic allocation of these arrays to avoid getting into dangerously
high stack usage.

Unfortunately, allocating memory in the writepages() code path can be
problematic in case of low memory situations, so it would be better to
rework the code more widely to avoid the allocation entirely.

Fixes: 115380f9a2f9 ("ntfs: update mft operations")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>

authored by

Arnd Bergmann and committed by
Namjae Jeon
f462fdf3 a8fde8be

+7 -2
+7 -2
fs/ntfs/mft.c
··· 2704 2704 struct ntfs_inode *ni = NTFS_I(vi); 2705 2705 struct ntfs_volume *vol = ni->vol; 2706 2706 u8 *kaddr; 2707 - struct ntfs_inode *locked_nis[PAGE_SIZE / NTFS_BLOCK_SIZE]; 2707 + struct ntfs_inode **locked_nis __free(kfree) = kmalloc_array(PAGE_SIZE / NTFS_BLOCK_SIZE, 2708 + sizeof(struct ntfs_inode *), GFP_NOFS); 2708 2709 int nr_locked_nis = 0, err = 0, mft_ofs, prev_mft_ofs; 2709 - struct inode *ref_inos[PAGE_SIZE / NTFS_BLOCK_SIZE]; 2710 + struct inode **ref_inos __free(kfree) = kmalloc_array(PAGE_SIZE / NTFS_BLOCK_SIZE, 2711 + sizeof(struct inode *), GFP_NOFS); 2710 2712 int nr_ref_inos = 0; 2711 2713 struct bio *bio = NULL; 2712 2714 unsigned long mft_no; ··· 2722 2720 2723 2721 ntfs_debug("Entering for inode 0x%lx, attribute type 0x%x, folio index 0x%lx.", 2724 2722 vi->i_ino, ni->type, folio->index); 2723 + 2724 + if (!locked_nis || !ref_inos) 2725 + return -ENOMEM; 2725 2726 2726 2727 /* We have to zero every time due to mmap-at-end-of-file. */ 2727 2728 if (folio->index >= (i_size >> folio_shift(folio)))