* [PATCH v2] zram: fix null dereference of handle
@ 2017-09-20 6:02 Minchan Kim
2017-09-20 6:29 ` Sergey Senozhatsky
0 siblings, 1 reply; 2+ messages in thread
From: Minchan Kim @ 2017-09-20 6:02 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel, kernel-team, Minchan Kim, Sergey Senozhatsky
For the testing, I found handle passed to zs_map_object in __zram_bvec_read
is NULL so that kernel goes the Oops by 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.
* From v1:
* remove unlikely branch - Sergey
* In !handle case, use 0 instead of zram_get_element - Sergey
Fixes: 1f7319c74275 ("zram: partial IO refactoring")
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Signed-off-by: Minchan Kim <minchan@kernel.org>
---
drivers/block/zram/zram_drv.c | 36 ++++++++++++------------------------
1 file changed, 12 insertions(+), 24 deletions(-)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 2981c27d3aae..f149d3e61234 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -766,27 +766,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;
@@ -884,11 +863,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);
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] zram: fix null dereference of handle
2017-09-20 6:02 [PATCH v2] zram: fix null dereference of handle Minchan Kim
@ 2017-09-20 6:29 ` Sergey Senozhatsky
0 siblings, 0 replies; 2+ messages in thread
From: Sergey Senozhatsky @ 2017-09-20 6:29 UTC (permalink / raw)
To: Minchan Kim; +Cc: Andrew Morton, linux-kernel, kernel-team, Sergey Senozhatsky
On (09/20/17 15:02), Minchan Kim wrote:
> For the testing, I found handle passed to zs_map_object in __zram_bvec_read
> is NULL so that kernel goes the Oops by 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.
>
> * From v1:
> * remove unlikely branch - Sergey
> * In !handle case, use 0 instead of zram_get_element - Sergey
>
> Fixes: 1f7319c74275 ("zram: partial IO refactoring")
> Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
> Signed-off-by: Minchan Kim <minchan@kernel.org>
Reviewed-by: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
-ss
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-09-20 6:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-20 6:02 [PATCH v2] zram: fix null dereference of handle Minchan Kim
2017-09-20 6:29 ` Sergey Senozhatsky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox