summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2018-08-17 18:44:07 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-08-17 19:20:27 -0400
commitac4ecf968acb9e54c335f99d842d56d6b90e28fb (patch)
treebfbd2cc93a3d3e1e8de4f2f6df6a248252a8fb9e
parenta10dcebacdb0cf6eb29c211e99cf190cd131a16a (diff)
ntfs: aops: remove VLA usage
In the quest to remove all stack VLA usage from the kernel[1], this uses the maximum size needed on the stack and adds a sanity check for robustness: index.block_size cannot be larger than PAGE_SIZE nor less than NTFS_BLOCK_SIZE. [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com Link: http://lkml.kernel.org/r/20180626172909.41453-2-keescook@chromium.org Signed-off-by: Kees Cook <keescook@chromium.org> Cc: Anton Altaparmakov <anton@tuxera.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--fs/ntfs/aops.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/fs/ntfs/aops.c b/fs/ntfs/aops.c
index 01c770979921..8946130c87ad 100644
--- a/fs/ntfs/aops.c
+++ b/fs/ntfs/aops.c
@@ -922,7 +922,7 @@ static int ntfs_write_mst_block(struct page *page,
922 ntfs_volume *vol = ni->vol; 922 ntfs_volume *vol = ni->vol;
923 u8 *kaddr; 923 u8 *kaddr;
924 unsigned int rec_size = ni->itype.index.block_size; 924 unsigned int rec_size = ni->itype.index.block_size;
925 ntfs_inode *locked_nis[PAGE_SIZE / rec_size]; 925 ntfs_inode *locked_nis[PAGE_SIZE / NTFS_BLOCK_SIZE];
926 struct buffer_head *bh, *head, *tbh, *rec_start_bh; 926 struct buffer_head *bh, *head, *tbh, *rec_start_bh;
927 struct buffer_head *bhs[MAX_BUF_PER_PAGE]; 927 struct buffer_head *bhs[MAX_BUF_PER_PAGE];
928 runlist_element *rl; 928 runlist_element *rl;
@@ -931,6 +931,9 @@ static int ntfs_write_mst_block(struct page *page,
931 bool sync, is_mft, page_is_dirty, rec_is_dirty; 931 bool sync, is_mft, page_is_dirty, rec_is_dirty;
932 unsigned char bh_size_bits; 932 unsigned char bh_size_bits;
933 933
934 if (WARN_ON(rec_size < NTFS_BLOCK_SIZE))
935 return -EINVAL;
936
934 ntfs_debug("Entering for inode 0x%lx, attribute type 0x%x, page index " 937 ntfs_debug("Entering for inode 0x%lx, attribute type 0x%x, page index "
935 "0x%lx.", vi->i_ino, ni->type, page->index); 938 "0x%lx.", vi->i_ino, ni->type, page->index);
936 BUG_ON(!NInoNonResident(ni)); 939 BUG_ON(!NInoNonResident(ni));