Skip to content

Commit 100266f

Browse files
arndb1Naim
authored andcommitted
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: 115380f ("ntfs: update mft operations") Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
1 parent 1596fc0 commit 100266f

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

fs/ntfs/mft.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2704,9 +2704,11 @@ static int ntfs_write_mft_block(struct folio *folio, struct writeback_control *w
27042704
struct ntfs_inode *ni = NTFS_I(vi);
27052705
struct ntfs_volume *vol = ni->vol;
27062706
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);
27082709
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);
27102712
int nr_ref_inos = 0;
27112713
struct bio *bio = NULL;
27122714
unsigned long mft_no;
@@ -2721,6 +2723,9 @@ static int ntfs_write_mft_block(struct folio *folio, struct writeback_control *w
27212723
ntfs_debug("Entering for inode 0x%lx, attribute type 0x%x, folio index 0x%lx.",
27222724
vi->i_ino, ni->type, folio->index);
27232725

2726+
if (!locked_nis || !ref_inos)
2727+
return -ENOMEM;
2728+
27242729
/* We have to zero every time due to mmap-at-end-of-file. */
27252730
if (folio->index >= (i_size >> folio_shift(folio)))
27262731
/* The page straddles i_size. */

0 commit comments

Comments
 (0)