提交 ed382d58 编写于 作者: A Adrian Hunter 提交者: Artem Bityutskiy

UBIFS: ensure data read beyond i_size is zeroed out correctly

Signed-off-by: NAdrian Hunter <ext-adrian.hunter@nokia.com>
上级 2094c334
...@@ -147,6 +147,12 @@ static int do_readpage(struct page *page) ...@@ -147,6 +147,12 @@ static int do_readpage(struct page *page)
err = ret; err = ret;
if (err != -ENOENT) if (err != -ENOENT)
break; break;
} else if (block + 1 == beyond) {
int dlen = le32_to_cpu(dn->size);
int ilen = i_size & (UBIFS_BLOCK_SIZE - 1);
if (ilen && ilen < dlen)
memset(addr + ilen, 0, dlen - ilen);
} }
} }
if (++i >= UBIFS_BLOCKS_PER_PAGE) if (++i >= UBIFS_BLOCKS_PER_PAGE)
...@@ -601,7 +607,7 @@ static int populate_page(struct ubifs_info *c, struct page *page, ...@@ -601,7 +607,7 @@ static int populate_page(struct ubifs_info *c, struct page *page,
addr = zaddr = kmap(page); addr = zaddr = kmap(page);
end_index = (i_size + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; end_index = (i_size - 1) >> PAGE_CACHE_SHIFT;
if (!i_size || page->index > end_index) { if (!i_size || page->index > end_index) {
memset(addr, 0, PAGE_CACHE_SIZE); memset(addr, 0, PAGE_CACHE_SIZE);
goto out_hole; goto out_hole;
...@@ -649,7 +655,7 @@ static int populate_page(struct ubifs_info *c, struct page *page, ...@@ -649,7 +655,7 @@ static int populate_page(struct ubifs_info *c, struct page *page,
if (end_index == page->index) { if (end_index == page->index) {
int len = i_size & (PAGE_CACHE_SIZE - 1); int len = i_size & (PAGE_CACHE_SIZE - 1);
if (len < read) if (len && len < read)
memset(zaddr + len, 0, read - len); memset(zaddr + len, 0, read - len);
} }
......
...@@ -75,7 +75,6 @@ ...@@ -75,7 +75,6 @@
*/ */
#define UBIFS_BLOCK_SIZE 4096 #define UBIFS_BLOCK_SIZE 4096
#define UBIFS_BLOCK_SHIFT 12 #define UBIFS_BLOCK_SHIFT 12
#define UBIFS_BLOCK_MASK 0x00000FFF
/* UBIFS padding byte pattern (must not be first or last byte of node magic) */ /* UBIFS padding byte pattern (must not be first or last byte of node magic) */
#define UBIFS_PADDING_BYTE 0xCE #define UBIFS_PADDING_BYTE 0xCE
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册