From: Alexander Potapenko <glider@google.com>
To: mawupeng <mawupeng1@huawei.com>
Cc: akpm@linux-foundation.org, ryabinin.a.a@gmail.com,
andreyknvl@gmail.com, dvyukov@google.com,
vincenzo.frascino@arm.com, kasan-dev@googlegroups.com,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [Question] race during kasan_populate_vmalloc_pte
Date: Mon, 15 Jul 2024 19:19:49 +0200 [thread overview]
Message-ID: <CAG_fn=VTKFDAx2JQAEur5cxkSwNze-SOqQRbqBGwDx96Xq-6nQ@mail.gmail.com> (raw)
In-Reply-To: <e66bb4c1-f1bc-4aeb-a413-fcdbb327e73f@huawei.com>
On Fri, Jul 12, 2024 at 4:08 AM mawupeng <mawupeng1@huawei.com> wrote:
>
> Hi maintainers,
>
> kingly ping.
>
> On 2024/6/18 14:40, Wupeng Ma wrote:
> > Hi maintainers,
> >
> > During our testing, we discovered that kasan vmalloc may trigger a false
> > vmalloc-out-of-bounds warning due to a race between kasan_populate_vmalloc_pte
> > and kasan_depopulate_vmalloc_pte.
> >
> > cpu0 cpu1 cpu2
> > kasan_populate_vmalloc_pte kasan_populate_vmalloc_pte kasan_depopulate_vmalloc_pte
> > spin_unlock(&init_mm.page_table_lock);
> > pte_none(ptep_get(ptep))
> > // pte is valid here, return here
> > pte_clear(&init_mm, addr, ptep);
> > pte_none(ptep_get(ptep))
> > // pte is none here try alloc new pages
> > spin_lock(&init_mm.page_table_lock);
> > kasan_poison
> > // memset kasan shadow region to 0
> > page = __get_free_page(GFP_KERNEL);
> > __memset((void *)page, KASAN_VMALLOC_INVALID, PAGE_SIZE);
> > pte = pfn_pte(PFN_DOWN(__pa(page)), PAGE_KERNEL);
> > spin_lock(&init_mm.page_table_lock);
> > set_pte_at(&init_mm, addr, ptep, pte);
> > spin_unlock(&init_mm.page_table_lock);
> >
> >
> > Since kasan shadow memory in cpu0 is set to 0xf0 which means it is not
> > initialized after the race in cpu1. Consequently, a false vmalloc-out-of-bounds
> > warning is triggered when a user attempts to access this memory region.
> >
> > The root cause of this problem is the pte valid check at the start of
> > kasan_populate_vmalloc_pte should be removed since it is not protected by
> > page_table_lock. However, this may result in severe performance degradation
> > since pages will be frequently allocated and freed.
> >
> > Is there have any thoughts on how to solve this issue?
> >
> > Thank you.
I am going to take a closer look at this issue. Any chance you have a
reproducer for it?
next prev parent reply other threads:[~2024-07-15 17:20 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-18 6:40 Wupeng Ma
2024-06-21 2:08 ` mawupeng
2024-07-12 2:08 ` mawupeng
2024-07-15 17:19 ` Alexander Potapenko [this message]
2024-07-16 1:12 ` mawupeng
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='CAG_fn=VTKFDAx2JQAEur5cxkSwNze-SOqQRbqBGwDx96Xq-6nQ@mail.gmail.com' \
--to=glider@google.com \
--cc=akpm@linux-foundation.org \
--cc=andreyknvl@gmail.com \
--cc=dvyukov@google.com \
--cc=kasan-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mawupeng1@huawei.com \
--cc=ryabinin.a.a@gmail.com \
--cc=vincenzo.frascino@arm.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