linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Nhat Pham <nphamcs@gmail.com>
To: Johannes Weiner <hannes@cmpxchg.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Yosry Ahmed <yosryahmed@google.com>,
	 Chengming Zhou <zhouchengming@bytedance.com>,
	linux-mm@kvack.org,  linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm: zswap: fix objcg use-after-free in entry destruction
Date: Mon, 29 Jan 2024 23:26:40 -0800	[thread overview]
Message-ID: <CAKEwX=N5A_b7edmqJyoKLvTCS64bpH886SSR_OUm4DZQUdL8Gg@mail.gmail.com> (raw)
In-Reply-To: <20240130013438.565167-1-hannes@cmpxchg.org>

On Mon, Jan 29, 2024 at 5:34 PM Johannes Weiner <hannes@cmpxchg.org> 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>
> ---
>  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);
> +       }

Nice catch!
Reviewed-by: Nhat Pham <nphamcs@gmail.com>

>         zswap_entry_cache_free(entry);
>         atomic_dec(&zswap_stored_pages);
>         zswap_update_total_size();
> --
> 2.43.0
>


      parent reply	other threads:[~2024-01-30  7:26 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
2024-01-30  7:26 ` Nhat Pham [this message]

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='CAKEwX=N5A_b7edmqJyoKLvTCS64bpH886SSR_OUm4DZQUdL8Gg@mail.gmail.com' \
    --to=nphamcs@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=yosryahmed@google.com \
    --cc=zhouchengming@bytedance.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