mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
To: Minchan Kim <minchan@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org, kernel-team <kernel-team@lge.com>,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Subject: Re: [PATCH] zram: fix null dereference of handle
Date: Tue, 19 Sep 2017 14:39:35 +0900	[thread overview]
Message-ID: <20170919053934.GC16991@jagdpanzerIV.localdomain> (raw)
In-Reply-To: <1505788488-26723-1-git-send-email-minchan@kernel.org>

On (09/19/17 11:34), Minchan Kim wrote:
[..]
>  static void zram_meta_free(struct zram *zram, u64 disksize)
>  {
>  	size_t num_pages = disksize >> PAGE_SHIFT;
> @@ -876,11 +855,18 @@ 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 (unlikely(!handle || zram_test_flag(zram, index, ZRAM_SAME))) {
> +		void *mem;


is this branch really unlikely()? ZRAM_SAME ratio really depends,
on some setups it can be quite likely, I suspect.


another question, "!handle  ==  value & ZRAM_SAME"? if so, then why not
just check for `flags & ZRAM_SAME'? if not then:

-  for `value & ZRAM_SAME' you fill the page with zram_get_element(zram, index)
   and return 0. ok.

-  for !handle.... you also fill the page with zram_get_element(zram, index)
   and return 0. is this ok? shouldn't !handle return error in this case?


I really suspect that there are some paths that can lead to !handle
entry, that will not be ZRAM_SAME. e.g. error return from compression
path.

	-ss

> +		mem = kmap_atomic(page);
> +		zram_fill_page(mem, PAGE_SIZE, zram_get_element(zram, index));
> +		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
> 

  reply	other threads:[~2017-09-19  5:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-19  2:34 Minchan Kim
2017-09-19  5:39 ` Sergey Senozhatsky [this message]
2017-09-19  6:59   ` Minchan Kim
2017-09-19 10:15     ` Sergey Senozhatsky
2017-09-19 10:21 Sergey Senozhatsky
2017-09-20  5:51 ` Minchan Kim
2017-09-20  6:28   ` Sergey Senozhatsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170919053934.GC16991@jagdpanzerIV.localdomain \
    --to=sergey.senozhatsky.work@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=kernel-team@lge.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=minchan@kernel.org \
    --cc=sergey.senozhatsky@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®