lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Sat, 15 Jan 2022 00:58:44 +0300
From:   Andrey Konovalov <andreyknvl@...il.com>
To:     Peter Collingbourne <pcc@...gle.com>
Cc:     Andrew Morton <akpm@...ux-foundation.org>,
        Linux Memory Management List <linux-mm@...ck.org>,
        LKML <linux-kernel@...r.kernel.org>, stable@...r.kernel.org
Subject: Re: [PATCH] mm: use compare-exchange operation to set KASAN page tag

 On Thu, Jan 13, 2022 at 6:14 AM Peter Collingbourne <pcc@...gle.com> wrote:
>
> It has been reported that the tag setting operation on newly-allocated
> pages can cause the page flags to be corrupted when performed
> concurrently with other flag updates as a result of the use of
> non-atomic operations.

Is it know how exactly this race happens? Why are flags for a newly
allocated page being accessed concurrently?

> Fix the problem by using a compare-exchange
> loop to update the tag.
>
> Signed-off-by: Peter Collingbourne <pcc@...gle.com>
> Link: https://linux-review.googlesource.com/id/I456b24a2b9067d93968d43b4bb3351c0cec63101
> Fixes: 2813b9c02962 ("kasan, mm, arm64: tag non slab memory allocated via pagealloc")
> Cc: stable@...r.kernel.org
> ---
>  include/linux/mm.h | 16 +++++++++++-----
>  1 file changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index c768a7c81b0b..b544b0a9f537 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -1531,11 +1531,17 @@ static inline u8 page_kasan_tag(const struct page *page)
>
>  static inline void page_kasan_tag_set(struct page *page, u8 tag)
>  {
> -       if (kasan_enabled()) {
> -               tag ^= 0xff;
> -               page->flags &= ~(KASAN_TAG_MASK << KASAN_TAG_PGSHIFT);
> -               page->flags |= (tag & KASAN_TAG_MASK) << KASAN_TAG_PGSHIFT;
> -       }
> +       unsigned long old_flags, flags;
> +
> +       if (!kasan_enabled())
> +               return;
> +
> +       tag ^= 0xff;
> +       do {
> +               old_flags = flags = page->flags;

I guess this should be at least READ_ONCE(page->flags) if we care
about concurrency.

> +               flags &= ~(KASAN_TAG_MASK << KASAN_TAG_PGSHIFT);
> +               flags |= (tag & KASAN_TAG_MASK) << KASAN_TAG_PGSHIFT;
> +       } while (unlikely(cmpxchg(&page->flags, old_flags, flags) != old_flags));
>  }
>
>  static inline void page_kasan_tag_reset(struct page *page)
> --
> 2.34.1.575.g55b058a8bb-goog
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ