UPSTREAM: zram: fix null dereference of handle
In testing I found handle passed to zs_map_object in __zram_bvec_read is NULL so eh kernel goes oops in pin_object(). The reason is there is no routine to check the slot's freeing after getting the slot's lock. This patch fixes it. [minchan@kernel.org: v2] Link: http://lkml.kernel.org/r/1505887347-10881-1-git-send-email-minchan@kernel.org Link: http://lkml.kernel.org/r/1505788488-26723-1-git-send-email-minchan@kernel.org Fixes: 1f7319c74275 ("zram: partial IO refactoring") Signed-off-by: Minchan Kim <minchan@kernel.org> Reviewed-by: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> (cherry picked from commit ae94264ed4b0cf7cd887947650db4c69acb62072) Signed-off-by: Peter Kalauskas <peskal@google.com> Bug: 112488418 Change-Id: I0ff4a8c2f1fcd0ee39511985809b58bf94b2d44c
This commit is contained in:
parent
8a610b438d
commit
edf99a4a6e
1 changed files with 12 additions and 24 deletions
|
@ -781,27 +781,6 @@ static void zram_slot_unlock(struct zram *zram, u32 index)
|
|||
bit_spin_unlock(ZRAM_ACCESS, &zram->table[index].value);
|
||||
}
|
||||
|
||||
static bool zram_same_page_read(struct zram *zram, u32 index,
|
||||
struct page *page,
|
||||
unsigned int offset, unsigned int len)
|
||||
{
|
||||
zram_slot_lock(zram, index);
|
||||
if (unlikely(!zram_get_handle(zram, index) ||
|
||||
zram_test_flag(zram, index, ZRAM_SAME))) {
|
||||
void *mem;
|
||||
|
||||
zram_slot_unlock(zram, index);
|
||||
mem = kmap_atomic(page);
|
||||
zram_fill_page(mem + offset, len,
|
||||
zram_get_element(zram, index));
|
||||
kunmap_atomic(mem);
|
||||
return true;
|
||||
}
|
||||
zram_slot_unlock(zram, index);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void zram_meta_free(struct zram *zram, u64 disksize)
|
||||
{
|
||||
size_t num_pages = disksize >> PAGE_SHIFT;
|
||||
|
@ -899,11 +878,20 @@ static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index,
|
|||
zram_slot_unlock(zram, index);
|
||||
}
|
||||
|
||||
if (zram_same_page_read(zram, index, page, 0, PAGE_SIZE))
|
||||
return 0;
|
||||
|
||||
zram_slot_lock(zram, index);
|
||||
handle = zram_get_handle(zram, index);
|
||||
if (!handle || zram_test_flag(zram, index, ZRAM_SAME)) {
|
||||
unsigned long value;
|
||||
void *mem;
|
||||
|
||||
value = handle ? zram_get_element(zram, index) : 0;
|
||||
mem = kmap_atomic(page);
|
||||
zram_fill_page(mem, PAGE_SIZE, value);
|
||||
kunmap_atomic(mem);
|
||||
zram_slot_unlock(zram, index);
|
||||
return 0;
|
||||
}
|
||||
|
||||
size = zram_get_obj_size(zram, index);
|
||||
|
||||
src = zs_map_object(zram->mem_pool, handle, ZS_MM_RO);
|
||||
|
|
Loading…
Add table
Reference in a new issue