diff options
author | Minchan Kim <minchan@kernel.org> | 2017-10-03 19:15:19 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-10-03 20:54:24 -0400 |
commit | ae94264ed4b0cf7cd887947650db4c69acb62072 (patch) | |
tree | 5e291f4bf79421a4a5b46122b31841844a67a98d /drivers/block/zram | |
parent | a872eb2131e91ce7c89a8888974a5e22a272b12f (diff) |
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>
Diffstat (limited to 'drivers/block/zram')
-rw-r--r-- | drivers/block/zram/zram_drv.c | 36 |
1 files 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) | |||
766 | bit_spin_unlock(ZRAM_ACCESS, &zram->table[index].value); | 766 | bit_spin_unlock(ZRAM_ACCESS, &zram->table[index].value); |
767 | } | 767 | } |
768 | 768 | ||
769 | static bool zram_same_page_read(struct zram *zram, u32 index, | ||
770 | struct page *page, | ||
771 | unsigned int offset, unsigned int len) | ||
772 | { | ||
773 | zram_slot_lock(zram, index); | ||
774 | if (unlikely(!zram_get_handle(zram, index) || | ||
775 | zram_test_flag(zram, index, ZRAM_SAME))) { | ||
776 | void *mem; | ||
777 | |||
778 | zram_slot_unlock(zram, index); | ||
779 | mem = kmap_atomic(page); | ||
780 | zram_fill_page(mem + offset, len, | ||
781 | zram_get_element(zram, index)); | ||
782 | kunmap_atomic(mem); | ||
783 | return true; | ||
784 | } | ||
785 | zram_slot_unlock(zram, index); | ||
786 | |||
787 | return false; | ||
788 | } | ||
789 | |||
790 | static void zram_meta_free(struct zram *zram, u64 disksize) | 769 | static void zram_meta_free(struct zram *zram, u64 disksize) |
791 | { | 770 | { |
792 | size_t num_pages = disksize >> PAGE_SHIFT; | 771 | size_t num_pages = disksize >> PAGE_SHIFT; |
@@ -884,11 +863,20 @@ static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index, | |||
884 | zram_slot_unlock(zram, index); | 863 | zram_slot_unlock(zram, index); |
885 | } | 864 | } |
886 | 865 | ||
887 | if (zram_same_page_read(zram, index, page, 0, PAGE_SIZE)) | ||
888 | return 0; | ||
889 | |||
890 | zram_slot_lock(zram, index); | 866 | zram_slot_lock(zram, index); |
891 | handle = zram_get_handle(zram, index); | 867 | handle = zram_get_handle(zram, index); |
868 | if (!handle || zram_test_flag(zram, index, ZRAM_SAME)) { | ||
869 | unsigned long value; | ||
870 | void *mem; | ||
871 | |||
872 | value = handle ? zram_get_element(zram, index) : 0; | ||
873 | mem = kmap_atomic(page); | ||
874 | zram_fill_page(mem, PAGE_SIZE, value); | ||
875 | kunmap_atomic(mem); | ||
876 | zram_slot_unlock(zram, index); | ||
877 | return 0; | ||
878 | } | ||
879 | |||
892 | size = zram_get_obj_size(zram, index); | 880 | size = zram_get_obj_size(zram, index); |
893 | 881 | ||
894 | src = zs_map_object(zram->mem_pool, handle, ZS_MM_RO); | 882 | src = zs_map_object(zram->mem_pool, handle, ZS_MM_RO); |