From: Shakeel Butt <shakeelb@google.com>
To: Vitaly Wool <vitalywool@gmail.com>
Cc: Linux-MM <linux-mm@kvack.org>,
LKML <linux-kernel@vger.kernel.org>,
Henry Burns <henryburns@google.com>,
Andrew Morton <akpm@linux-foundation.org>,
Jonathan Adams <jwadams@google.com>
Subject: Re: [PATCH] mm/z3fold.c: don't try to use buddy slots after free
Date: Wed, 10 Jul 2019 13:50:48 -0700 [thread overview]
Message-ID: <CALvZod7Qfj+Jer1TK4P-HmoQ0now=w2JK7NNrfC6ae8R0cOLcA@mail.gmail.com> (raw)
In-Reply-To: <20190708134808.e89f3bfadd9f6ffd7eff9ba9@gmail.com>
On Mon, Jul 8, 2019 at 4:48 AM Vitaly Wool <vitalywool@gmail.com> wrote:
>
> From fd87fdc38ea195e5a694102a57bd4d59fc177433 Mon Sep 17 00:00:00 2001
> From: Vitaly Wool <vitalywool@gmail.com>
> Date: Mon, 8 Jul 2019 13:41:02 +0200
> [PATCH] mm/z3fold: don't try to use buddy slots after free
>
> As reported by Henry Burns:
>
> Running z3fold stress testing with address sanitization
> showed zhdr->slots was being used after it was freed.
>
> z3fold_free(z3fold_pool, handle)
> free_handle(handle)
> kmem_cache_free(pool->c_handle, zhdr->slots)
> release_z3fold_page_locked_list(kref)
> __release_z3fold_page(zhdr, true)
> zhdr_to_pool(zhdr)
> slots_to_pool(zhdr->slots) *BOOM*
>
> To fix this, add pointer to the pool back to z3fold_header and modify
> zhdr_to_pool to return zhdr->pool.
>
> Fixes: 7c2b8baa61fe ("mm/z3fold.c: add structure for buddy handles")
>
> Reported-by: Henry Burns <henryburns@google.com>
> Signed-off-by: Vitaly Wool <vitalywool@gmail.com>
Reviewed-by: Shakeel Butt <shakeelb@google.com>
> ---
> mm/z3fold.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/mm/z3fold.c b/mm/z3fold.c
> index 985732c8b025..e1686bf6d689 100644
> --- a/mm/z3fold.c
> +++ b/mm/z3fold.c
> @@ -101,6 +101,7 @@ struct z3fold_buddy_slots {
> * @refcount: reference count for the z3fold page
> * @work: work_struct for page layout optimization
> * @slots: pointer to the structure holding buddy slots
> + * @pool: pointer to the containing pool
> * @cpu: CPU which this page "belongs" to
> * @first_chunks: the size of the first buddy in chunks, 0 if free
> * @middle_chunks: the size of the middle buddy in chunks, 0 if free
> @@ -114,6 +115,7 @@ struct z3fold_header {
> struct kref refcount;
> struct work_struct work;
> struct z3fold_buddy_slots *slots;
> + struct z3fold_pool *pool;
> short cpu;
> unsigned short first_chunks;
> unsigned short middle_chunks;
> @@ -320,6 +322,7 @@ static struct z3fold_header *init_z3fold_page(struct page *page,
> zhdr->start_middle = 0;
> zhdr->cpu = -1;
> zhdr->slots = slots;
> + zhdr->pool = pool;
> INIT_LIST_HEAD(&zhdr->buddy);
> INIT_WORK(&zhdr->work, compact_page_work);
> return zhdr;
> @@ -426,7 +429,7 @@ static enum buddy handle_to_buddy(unsigned long handle)
>
> static inline struct z3fold_pool *zhdr_to_pool(struct z3fold_header *zhdr)
> {
> - return slots_to_pool(zhdr->slots);
> + return zhdr->pool;
> }
>
> static void __release_z3fold_page(struct z3fold_header *zhdr, bool locked)
> --
> 2.17.1
prev parent reply other threads:[~2019-07-10 20:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-08 11:48 Vitaly Wool
2019-07-10 20:50 ` Shakeel Butt [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='CALvZod7Qfj+Jer1TK4P-HmoQ0now=w2JK7NNrfC6ae8R0cOLcA@mail.gmail.com' \
--to=shakeelb@google.com \
--cc=akpm@linux-foundation.org \
--cc=henryburns@google.com \
--cc=jwadams@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=vitalywool@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