linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Chengming Zhou <zhouchengming@bytedance.com>
To: Johannes Weiner <hannes@cmpxchg.org>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: Nhat Pham <nphamcs@gmail.com>,
	Yosry Ahmed <yosryahmed@google.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm: zswap: fix objcg use-after-free in entry destruction
Date: Tue, 30 Jan 2024 10:41:29 +0800	[thread overview]
Message-ID: <ffc74759-e3e3-499f-85fb-abe52bac2464@bytedance.com> (raw)
In-Reply-To: <20240130013438.565167-1-hannes@cmpxchg.org>

On 2024/1/30 09:34, Johannes Weiner wrote:
> In the per-memcg LRU universe, LRU removal uses entry->objcg to
> determine which list count needs to be decreased. Drop the objcg
> reference after updating the LRU, to fix a possible use-after-free.
> 
> Fixes: a65b0e7607cc ("zswap: make shrinking memcg-aware")
> Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>

LGTM, thanks!

Reviewed-by: Chengming Zhou <zhouchengming@bytedance.com>

> ---
>  mm/zswap.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/mm/zswap.c b/mm/zswap.c
> index de68a5928527..7f88b3a77e4a 100644
> --- a/mm/zswap.c
> +++ b/mm/zswap.c
> @@ -522,10 +522,6 @@ static struct zpool *zswap_find_zpool(struct zswap_entry *entry)
>   */
>  static void zswap_free_entry(struct zswap_entry *entry)
>  {
> -	if (entry->objcg) {
> -		obj_cgroup_uncharge_zswap(entry->objcg, entry->length);
> -		obj_cgroup_put(entry->objcg);
> -	}
>  	if (!entry->length)
>  		atomic_dec(&zswap_same_filled_pages);
>  	else {
> @@ -534,6 +530,10 @@ static void zswap_free_entry(struct zswap_entry *entry)
>  		atomic_dec(&entry->pool->nr_stored);
>  		zswap_pool_put(entry->pool);
>  	}
> +	if (entry->objcg) {
> +		obj_cgroup_uncharge_zswap(entry->objcg, entry->length);
> +		obj_cgroup_put(entry->objcg);
> +	}
>  	zswap_entry_cache_free(entry);
>  	atomic_dec(&zswap_stored_pages);
>  	zswap_update_total_size();


  parent reply	other threads:[~2024-01-30  2:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-30  1:34 Johannes Weiner
2024-01-30  1:44 ` Yosry Ahmed
2024-01-30  2:41 ` Chengming Zhou [this message]
2024-01-30  7:26 ` Nhat Pham

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=ffc74759-e3e3-499f-85fb-abe52bac2464@bytedance.com \
    --to=zhouchengming@bytedance.com \
    --cc=akpm@linux-foundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=nphamcs@gmail.com \
    --cc=yosryahmed@google.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