2014-10-30 06:21:36

by Weijie Yang

[permalink] [raw]
Subject: [PATCH] zram: avoid kunmap_atomic a NULL pointer

zram could kunmap_atomic a NULL pointer in a rare situation:
a zram page become a full-zeroed page after a partial write io.
The current code doesn't handle this case and kunmap_atomic a
NULL porinter, which panic the kernel.

This patch fixes this issue.

Signed-off-by: Weijie Yang <[email protected]>
---
drivers/block/zram/zram_drv.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 2ad0b5b..3920ee4 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -560,7 +560,8 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
}

if (page_zero_filled(uncmem)) {
- kunmap_atomic(user_mem);
+ if (user_mem)
+ kunmap_atomic(user_mem);
/* Free memory associated with this sector now. */
bit_spin_lock(ZRAM_ACCESS, &meta->table[index].value);
zram_free_page(zram, index);
--
1.7.0.4


2014-10-30 13:13:26

by Jerome Marchand

[permalink] [raw]
Subject: Re: [PATCH] zram: avoid kunmap_atomic a NULL pointer

On 10/30/2014 02:20 AM, Weijie Yang wrote:
> zram could kunmap_atomic a NULL pointer in a rare situation:
> a zram page become a full-zeroed page after a partial write io.
> The current code doesn't handle this case and kunmap_atomic a
> NULL porinter, which panic the kernel.
>
> This patch fixes this issue.
>
> Signed-off-by: Weijie Yang <[email protected]>

Acked-by: Jerome Marchand <[email protected]>

> ---
> drivers/block/zram/zram_drv.c | 3 ++-
> 1 files changed, 2 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> index 2ad0b5b..3920ee4 100644
> --- a/drivers/block/zram/zram_drv.c
> +++ b/drivers/block/zram/zram_drv.c
> @@ -560,7 +560,8 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
> }
>
> if (page_zero_filled(uncmem)) {
> - kunmap_atomic(user_mem);
> + if (user_mem)
> + kunmap_atomic(user_mem);
> /* Free memory associated with this sector now. */
> bit_spin_lock(ZRAM_ACCESS, &meta->table[index].value);
> zram_free_page(zram, index);
>



Attachments:
signature.asc (473.00 B)
OpenPGP digital signature

2014-10-31 13:46:13

by Sergey Senozhatsky

[permalink] [raw]
Subject: Re: [PATCH] zram: avoid kunmap_atomic a NULL pointer

On (10/30/14 14:20), Weijie Yang wrote:
> zram could kunmap_atomic a NULL pointer in a rare situation:
> a zram page become a full-zeroed page after a partial write io.
> The current code doesn't handle this case and kunmap_atomic a
> NULL porinter, which panic the kernel.
>
> This patch fixes this issue.
>
> Signed-off-by: Weijie Yang <[email protected]>

thank you, Weijie.

Acked-by: Sergey Senozhatsky <[email protected]>

-ss

> ---
> drivers/block/zram/zram_drv.c | 3 ++-
> 1 files changed, 2 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> index 2ad0b5b..3920ee4 100644
> --- a/drivers/block/zram/zram_drv.c
> +++ b/drivers/block/zram/zram_drv.c
> @@ -560,7 +560,8 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
> }
>
> if (page_zero_filled(uncmem)) {
> - kunmap_atomic(user_mem);
> + if (user_mem)
> + kunmap_atomic(user_mem);
> /* Free memory associated with this sector now. */
> bit_spin_lock(ZRAM_ACCESS, &meta->table[index].value);
> zram_free_page(zram, index);
> --
> 1.7.0.4
>
>