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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CA+fCnZd4BaejuyyWuT4xeiEyY1J0-6RWiyP3_u+w-xdOrALd9w@mail.gmail.com>
Date:   Sun, 4 Apr 2021 01:52:04 +0200
From:   Andrey Konovalov <andreyknvl@...il.com>
To:     Marco Elver <elver@...gle.com>,
        Peter Collingbourne <pcc@...gle.com>
Cc:     Dmitry Vyukov <dvyukov@...gle.com>,
        Alexander Potapenko <glider@...gle.com>,
        Evgenii Stepanov <eugenis@...gle.com>,
        Linux Memory Management List <linux-mm@...ck.org>,
        LKML <linux-kernel@...r.kernel.org>,
        Andrew Morton <akpm@...ux-foundation.org>
Subject: Re: [PATCH] kfence: unpoison pool region before use

On Sun, Apr 4, 2021 at 12:31 AM Marco Elver <elver@...gle.com> wrote:
>
> However, given the above, I think we need to explain this in the
> commit message (which also makes the dependency between these 2
> patches clear) and add a comment above the new kasan_unpoison_range().
> That is, if we still think this is the right fix -- I'm not entirely
> sure it is.
>
> Because what I gather from "kasan: initialize shadow to TAG_INVALID
> for SW_TAGS", is the requirement that "0xFF pointer tag is a match-all
> tag, it doesn't matter what tag the accessed memory has".
>
> While KFENCE memory is accessible through the slab API, and in this
> case ksize() calling kasan_check_byte() leading to a failure, the
> kasan_check_byte() call is part of the public KASAN API. Which means
> that if some subsystem decides to memblock_alloc() some memory, and
> wishes to use kasan_check_byte() on that memory but with an untagged
> pointer, will get the same problem as KFENCE: with generic and HW_TAGS
> mode everything is fine, but with SW_TAGS mode things break.

It makes sense to allow this function to operate on any kind of
memory, including memory that hasn't been previously marked by KASAN.

> To me this indicates the fix is not with KFENCE, but should be in
> mm/kasan/sw_tags.c:kasan_byte_accessible(), which should not load the
> shadow when the pointer is untagged.

The problem isn't in accessing shadow per se. Looking at
kasan_byte_accessible() (in both sw_tags.c and kasan.h), the return
statement there seems just wrong and redundant. The KASAN_TAG_KERNEL
check should come first:

return tag == KASAN_TAG_KERNEL || (shadow_byte != KASAN_TAG_INVALID &&
tag == shadow_byte);

This way, if the pointer tag is KASAN_TAG_KERNEL, the memory is
accessible no matter what the memory tag is.

But then the KASAN_TAG_INVALID check isn't needed, as this value is
never assigned to a pointer tag. Which brings us to:

return tag == KASAN_TAG_KERNEL || tag == shadow_byte;

Which is essentially the same check that kasan_check_range() performs.

Although, kasan_check_range() also checks that the shadow is <
KASAN_SHADOW_START. It makes makes sense to add this check into
kasan_byte_accessible() as well, before accessing shadow.

Thanks!

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ