lkml.org 
[lkml]   [2014]   [Jan]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC PATCH V3 2/2] fs : Add sanity checks for block size > PAGE_SIZE
Date
We could hit null pointer dereference error during alloc_page_buffers
in : (1) block size > PAGE_SIZE (2) low memory.
Add sanity check for that.

Signed-off-by: Raghavendra K T <raghavendra.kt@linux.vnet.ibm.com>
---
fs/block_dev.c | 1 +
fs/buffer.c | 6 ++++++
2 files changed, 7 insertions(+)

diff --git a/fs/block_dev.c b/fs/block_dev.c
index 1e86823..2481d42 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -1027,6 +1027,7 @@ void bd_set_size(struct block_device *bdev, loff_t size)
break;
bsize <<= 1;
}
+ BUG_ON(bsize > PAGE_SIZE);
bdev->bd_block_size = bsize;
bdev->bd_inode->i_blkbits = blksize_bits(bsize);
}
diff --git a/fs/buffer.c b/fs/buffer.c
index 6024877..b039b15 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -1571,6 +1571,12 @@ void create_empty_buffers(struct page *page,
struct buffer_head *bh, *head, *tail;

head = alloc_page_buffers(page, blocksize, 1);
+
+ /*
+ * alloc_page_buffers() could return NULL on (1) bs > PAGE_SIZE
+ * (2) low memory case. Ensure that we don't dereference null ptr
+ */
+ BUG_ON(!head);
bh = head;
do {
bh->b_state |= b_state;
--
1.7.11.7


\
 
 \ /
  Last update: 2014-01-21 13:21    [W:0.136 / U:0.276 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site