Commit ac4ecf96 authored by Kees Cook's avatar Kees Cook Committed by Linus Torvalds

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.orgSigned-off-by: default avatarKees Cook <keescook@chromium.org>
Cc: Anton Altaparmakov <anton@tuxera.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent a10dceba
...@@ -922,7 +922,7 @@ static int ntfs_write_mst_block(struct page *page, ...@@ -922,7 +922,7 @@ static int ntfs_write_mst_block(struct page *page,
ntfs_volume *vol = ni->vol; ntfs_volume *vol = ni->vol;
u8 *kaddr; u8 *kaddr;
unsigned int rec_size = ni->itype.index.block_size; unsigned int rec_size = ni->itype.index.block_size;
ntfs_inode *locked_nis[PAGE_SIZE / rec_size]; ntfs_inode *locked_nis[PAGE_SIZE / NTFS_BLOCK_SIZE];
struct buffer_head *bh, *head, *tbh, *rec_start_bh; struct buffer_head *bh, *head, *tbh, *rec_start_bh;
struct buffer_head *bhs[MAX_BUF_PER_PAGE]; struct buffer_head *bhs[MAX_BUF_PER_PAGE];
runlist_element *rl; runlist_element *rl;
...@@ -931,6 +931,9 @@ static int ntfs_write_mst_block(struct page *page, ...@@ -931,6 +931,9 @@ static int ntfs_write_mst_block(struct page *page,
bool sync, is_mft, page_is_dirty, rec_is_dirty; bool sync, is_mft, page_is_dirty, rec_is_dirty;
unsigned char bh_size_bits; unsigned char bh_size_bits;
if (WARN_ON(rec_size < NTFS_BLOCK_SIZE))
return -EINVAL;
ntfs_debug("Entering for inode 0x%lx, attribute type 0x%x, page index " ntfs_debug("Entering for inode 0x%lx, attribute type 0x%x, page index "
"0x%lx.", vi->i_ino, ni->type, page->index); "0x%lx.", vi->i_ino, ni->type, page->index);
BUG_ON(!NInoNonResident(ni)); BUG_ON(!NInoNonResident(ni));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment