zram: avoid invalid memory access in zram_exit()

Date	Mon, 3 Jun 2013 23:42:14 +0800

Memory for zram->disk object may have already been freed after returning
from destroy_device(zram), then it's unsafe for zram_reset_device(zram)
to access zram->disk again.

Fix it by holding an extra reference to zram->disk before calling
destroy_device(zram).

Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
zram: use zram->lock to protect zram_free_page() in swap free notify path

Date	Mon, 3 Jun 2013 23:42:15 +0800

zram_free_page() is protected by down_write(&zram->lock) when called by
zram_bvec_write(), but there's no such protection when called by
zram_slot_free_notify(), which may cause wrong states to zram object.

So enhance zram_slot_free_notify() to acquire writer lock on zram->lock
before calling zram_free_page().

Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Signed-off-by: Paul Reioux <reioux@gmail.com>
zram: destroy all devices on error recovery path in zram_init()

Date	Mon, 3 Jun 2013 23:42:16 +0800

On error recovery path of zram_init(), it leaks the zram device object
causing the failure.

Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Signed-off-by: Paul Reioux <reioux@gmail.com>
zram: avoid double free in error recovery path of zram_bvec_write()

Date	Mon, 3 Jun 2013 23:42:17 +0800

Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Signed-off-by: Paul Reioux <reioux@gmail.com>
zram: avoid access beyond the zram device

Date	Mon, 3 Jun 2013 23:42:18 +0800

Function valid_io_request() should verify the entire request doesn't
exceed the zram device, otherwise it will cause invalid memory access.

Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Signed-off-by: Paul Reioux <reioux@gmail.com>
zram: protect sysfs handler from invalid memory access

Date	Mon, 3 Jun 2013 23:42:20 +0800

Use zram->init_lock to protect access to zram->meta, otherwise it
may cause invalid memory access if zram->meta has been freed by
__zram_reset_device().

Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Signed-off-by: Paul Reioux <reioux@gmail.com>