From: "Sridhar, Kanchana P" <kanchana.p.sridhar@intel.com>
To: Chengming Zhou <chengming.zhou@linux.dev>,
Johannes Weiner <hannes@cmpxchg.org>
Cc: Nhat Pham <nphamcs@gmail.com>,
Yosry Ahmed <yosryahmed@google.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
"usamaarif642@gmail.com" <usamaarif642@gmail.com>,
"ryan.roberts@arm.com" <ryan.roberts@arm.com>,
"Huang, Ying" <ying.huang@intel.com>,
"21cnbao@gmail.com" <21cnbao@gmail.com>,
"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
"Feghali, Wajdi K" <wajdi.k.feghali@intel.com>,
"Gopal, Vinodh" <vinodh.gopal@intel.com>,
"Sridhar, Kanchana P" <kanchana.p.sridhar@intel.com>
Subject: RE: [PATCH v1] mm: zswap: Fix a potential memory leak in zswap_decompress().
Date: Fri, 15 Nov 2024 21:12:40 +0000 [thread overview]
Message-ID: <SJ0PR11MB567847C73338BC325FE49D11C9242@SJ0PR11MB5678.namprd11.prod.outlook.com> (raw)
In-Reply-To: <9a807484-6693-4e2a-a087-97bbc5ee4ed9@linux.dev>
Hi Chengming,
> -----Original Message-----
> From: Chengming Zhou <chengming.zhou@linux.dev>
> Sent: Wednesday, November 13, 2024 11:24 PM
> To: Sridhar, Kanchana P <kanchana.p.sridhar@intel.com>; Johannes Weiner
> <hannes@cmpxchg.org>
> Cc: Nhat Pham <nphamcs@gmail.com>; Yosry Ahmed
> <yosryahmed@google.com>; linux-kernel@vger.kernel.org; linux-
> mm@kvack.org; usamaarif642@gmail.com; ryan.roberts@arm.com; Huang,
> Ying <ying.huang@intel.com>; 21cnbao@gmail.com; akpm@linux-
> foundation.org; Feghali, Wajdi K <wajdi.k.feghali@intel.com>; Gopal, Vinodh
> <vinodh.gopal@intel.com>
> Subject: Re: [PATCH v1] mm: zswap: Fix a potential memory leak in
> zswap_decompress().
>
> Hello,
>
> On 2024/11/14 14:37, Sridhar, Kanchana P wrote:
> >
> >> -----Original Message-----
> >> From: Johannes Weiner <hannes@cmpxchg.org>
> >> Sent: Wednesday, November 13, 2024 9:12 PM
> >> To: Sridhar, Kanchana P <kanchana.p.sridhar@intel.com>
> >> Cc: Nhat Pham <nphamcs@gmail.com>; Yosry Ahmed
> >> <yosryahmed@google.com>; linux-kernel@vger.kernel.org; linux-
> >> mm@kvack.org; chengming.zhou@linux.dev; usamaarif642@gmail.com;
> >> ryan.roberts@arm.com; Huang, Ying <ying.huang@intel.com>;
> >> 21cnbao@gmail.com; akpm@linux-foundation.org; Feghali, Wajdi K
> >> <wajdi.k.feghali@intel.com>; Gopal, Vinodh <vinodh.gopal@intel.com>
> >> Subject: Re: [PATCH v1] mm: zswap: Fix a potential memory leak in
> >> zswap_decompress().
> >>
> >> On Thu, Nov 14, 2024 at 01:56:16AM +0000, Sridhar, Kanchana P wrote:
> >>> So my question was, can we prevent the migration to a different cpu
> >>> by relinquishing the mutex lock after this conditional
> >>
> >> Holding the mutex doesn't prevent preemption/migration.
> >
> > Sure, however, is this also applicable to holding the mutex of a per-cpu
> > structure obtained via raw_cpu_ptr()?
>
> Yes, unless you use migration_disable() or cpus_read_lock() to protect
> this section.
Ok.
>
> >
> > Would holding the mutex prevent the acomp_ctx of the cpu prior to
> > the migration (in the UAF scenario you described) from being deleted?
>
> No, cpu offline can kick in anytime to free the acomp_ctx->buffer.
>
> >
> > If holding the per-cpu acomp_ctx's mutex isn't sufficient to prevent the
> > UAF, I agree, we might need a way to prevent the acomp_ctx from being
> > deleted, e.g. with refcounts as you've suggested, or to not use the
>
> Right, refcount solution from Johannes is very good IMHO.
>
> > acomp_ctx at all for the check, instead use a boolean.
>
> But this is not enough to just avoid using acomp_ctx for the check,
> the usage of acomp_ctx inside the mutex is also UAF, since cpu offline
> can kick in anytime to free the acomp_ctx->buffer.
I see. How would the refcounts work? Would this add latency to zswap
ops? In low memory situations, could the cpu offlining code over-ride
the refcounts?
Based on Johannes' earlier comments, I don't think it makes sense for
me to submit a v2.
Thanks,
Kanchana
>
> Thanks.
next prev parent reply other threads:[~2024-11-15 21:14 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-13 5:24 Kanchana P Sridhar
2024-11-13 5:34 ` Yosry Ahmed
2024-11-13 5:58 ` Sridhar, Kanchana P
2024-11-13 6:21 ` Yosry Ahmed
2024-11-13 19:12 ` Sridhar, Kanchana P
2024-11-13 20:11 ` Yosry Ahmed
2024-11-13 20:59 ` Sridhar, Kanchana P
2024-11-13 20:59 ` Yosry Ahmed
2024-11-13 21:12 ` Sridhar, Kanchana P
2024-11-13 21:30 ` Johannes Weiner
2024-11-13 22:01 ` Yosry Ahmed
2024-11-13 22:13 ` Sridhar, Kanchana P
2024-11-14 0:28 ` Nhat Pham
2024-11-14 1:56 ` Sridhar, Kanchana P
2024-11-14 5:11 ` Johannes Weiner
2024-11-14 6:37 ` Sridhar, Kanchana P
2024-11-14 7:24 ` Chengming Zhou
2024-11-15 21:12 ` Sridhar, Kanchana P [this message]
2024-11-15 21:49 ` Yosry Ahmed
2024-11-19 19:22 ` Sridhar, Kanchana P
2024-11-19 19:27 ` Yosry Ahmed
2024-11-19 19:41 ` Sridhar, Kanchana P
2024-11-19 19:51 ` Yosry Ahmed
2024-11-19 22:35 ` Sridhar, Kanchana P
2024-11-19 23:44 ` Yosry Ahmed
2024-11-20 0:00 ` Sridhar, Kanchana P
2024-11-20 2:31 ` Chengming Zhou
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=SJ0PR11MB567847C73338BC325FE49D11C9242@SJ0PR11MB5678.namprd11.prod.outlook.com \
--to=kanchana.p.sridhar@intel.com \
--cc=21cnbao@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=chengming.zhou@linux.dev \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nphamcs@gmail.com \
--cc=ryan.roberts@arm.com \
--cc=usamaarif642@gmail.com \
--cc=vinodh.gopal@intel.com \
--cc=wajdi.k.feghali@intel.com \
--cc=ying.huang@intel.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