linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Vyukov <dvyukov@google.com>
To: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Andrey Konovalov <andreyknvl@google.com>,
	vincenzo.frascino@arm.com,
	Alexander Potapenko <glider@google.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will.deacon@arm.com>,
	Christoph Lameter <cl@linux.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Marc Zyngier <marc.zyngier@arm.com>,
	Dave Martin <dave.martin@arm.com>,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	"Eric W . Biederman" <ebiederm@xmission.com>,
	Ingo Molnar <mingo@kernel.org>,
	Paul Lawrence <paullawrence@google.com>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Arnd Bergmann <arnd@arndb.de>,
	"Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Kate Stewart <kstewart@linuxfoundation.org>,
	Mike Rapoport <rppt@linux.vnet.ibm.com>,
	kasan-dev <kasan-dev@googlegroups.com>,
	linux-doc@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>,
	Linux ARM <linux-arm-kernel@lists.infradead.org>,
	linux-sparse@vger.kernel.org,
	Linux Memory Management List <linux-mm@kvack.org>,
	Linux Kbuild mailing list <linux-kbuild@vger.kernel.org>,
	Chintan Pandya <cpandya@codeaurora.org>,
	Jacob Bramley <Jacob.Bramley@arm.com>,
	Jann Horn <jannh@google.com>,
	Ruben Ayrapetyan <Ruben.Ayrapetyan@arm.com>,
	Lee Smith <Lee.Smith@arm.com>, Kostya Serebryany <kcc@google.com>,
	Mark Brand <markbrand@google.com>,
	Ramana Radhakrishnan <Ramana.Radhakrishnan@arm.com>,
	Evgeniy Stepanov <eugenis@google.com>
Subject: Re: [PATCH v4 13/17] khwasan: add hooks implementation
Date: Tue, 31 Jul 2018 18:08:54 +0200	[thread overview]
Message-ID: <CACT4Y+aUs0YMTaQx4x9QiQsMjFNZ5gUFNuMkG_hneDPTb3Nu=Q@mail.gmail.com> (raw)
In-Reply-To: <b6b58786-85c9-e831-5571-58b5580c84ba@virtuozzo.com>

On Tue, Jul 31, 2018 at 6:04 PM, Andrey Ryabinin
<aryabinin@virtuozzo.com> wrote:
>>>>>> @@ -325,18 +341,41 @@ void kasan_init_slab_obj(struct kmem_cache *cache,
>>>>>> const void *object)
>>>>>>     void *kasan_slab_alloc(struct kmem_cache *cache, void *object, gfp_t
>>>>>> flags)
>>>>>>   {
>>>>>> -       return kasan_kmalloc(cache, object, cache->object_size, flags);
>>>>>> +       object = kasan_kmalloc(cache, object, cache->object_size, flags);
>>>>>> +       if (IS_ENABLED(CONFIG_KASAN_HW) && unlikely(cache->ctor)) {
>>>>>> +               /*
>>>>>> +                * Cache constructor might use object's pointer value to
>>>>>> +                * initialize some of its fields.
>>>>>> +                */
>>>>>> +               cache->ctor(object);
>>>>>>
>>>>> This seams breaking the kmem_cache_create() contract: "The @ctor is run when
>>>>> new pages are allocated by the cache."
>>>>> (https://elixir.bootlin.com/linux/v3.7/source/mm/slab_common.c#L83)
>>>>>
>>>>> Since there might be preexisting code relying on it, this could lead to
>>>>> global side effects. Did you verify that this is not the case?
>>>>>
>>>>> Another concern is performance related if we consider this solution suitable
>>>>> for "near-production", since with the current implementation you call the
>>>>> ctor (where present) on an object multiple times and this ends up memsetting
>>>>> and repopulating the memory every time (i.e. inode.c: inode_init_once). Do
>>>>> you know what is the performance impact?
>>>>
>>>> We can assign tags to objects with constructors when a slab is
>>>> allocated and call constructors once as usual. The downside is that
>>>> such object would always have the same tag when it is reallocated, so
>>>> we won't catch use-after-frees.
>>>
>>> Actually you should do this for SLAB_TYPESAFE_BY_RCU slabs. Usually they are with ->ctors but there
>>> are few without constructors.
>>> We can't reinitialize or even retag them. The latter will definitely cause false-positive use-after-free reports.
>>
>> Somewhat offtopic, but I can't understand how SLAB_TYPESAFE_BY_RCU
>> slabs can be useful without ctors or at least memset(0). Objects in
>> such slabs need to be type-stable, but I can't understand how it's
>> possible to establish type stability without a ctor... Are these bugs?
>
> Yeah, I puzzled by this too. However, I think it's hard but possible to make it work, at least in theory.
> There must be an initializer, which consists of two parts:
> a) initilize objects fields
> b) expose object to the world (add it to list or something like that)
>
> (a) part must somehow to be ok to race with another cpu which might already use the object.
> (b) part must must use e.g. barriers to make sure that racy users will see previously inilized fields.
> Racy users must have parring barrier of course.
>
> But it sound fishy, and very easy to fuck up.


Agree on both fronts: theoretically possible but easy to fuck up. Even
if it works, complexity of the code should be brain damaging and there
are unlikely good reasons to just not be more explicit and use a ctor.


> I won't be surprised if every single one SLAB_TYPESAFE_BY_RCU user
> without ->ctor is bogus. It certainly would be better to convert those to use ->ctor.

I have another hypothesis: they are not bogus, just don't need
SLAB_TYPESAFE_BY_RCU :)


> Such caches seems used by networking subsystem in proto_register():
>
>                 prot->slab = kmem_cache_create_usercopy(prot->name,
>                                         prot->obj_size, 0,
>                                         SLAB_HWCACHE_ALIGN | SLAB_ACCOUNT |
>                                         prot->slab_flags,
>                                         prot->useroffset, prot->usersize,
>                                         NULL);
>
> And certain protocols specify SLAB_TYPESAFE_BY_RCU in ->slab_flags, such as:
> llc_proto, smc_proto, smc_proto6, tcp_prot, tcpv6_prot, dccp_v6_prot, dccp_v4_prot.
>
>
> Also nf_conntrack_cachep, kernfs_node_cache, jbd2_journal_head_cache and i915_request cache.
>
>
> --
> You received this message because you are subscribed to the Google Groups "kasan-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kasan-dev+unsubscribe@googlegroups.com.
> To post to this group, send email to kasan-dev@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/b6b58786-85c9-e831-5571-58b5580c84ba%40virtuozzo.com.
> For more options, visit https://groups.google.com/d/optout.

  reply	other threads:[~2018-07-31 16:09 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-26 13:15 [PATCH v4 00/17] khwasan: kernel hardware assisted address sanitizer Andrey Konovalov
2018-06-26 13:15 ` [PATCH v4 01/17] khwasan, mm: change kasan hooks signatures Andrey Konovalov
2018-06-26 13:15 ` [PATCH v4 02/17] khwasan: move common kasan and khwasan code to common.c Andrey Konovalov
2018-06-26 13:15 ` [PATCH v4 03/17] khwasan: add CONFIG_KASAN_GENERIC and CONFIG_KASAN_HW Andrey Konovalov
2018-06-26 13:15 ` [PATCH v4 04/17] khwasan, arm64: adjust shadow size for CONFIG_KASAN_HW Andrey Konovalov
2018-06-26 13:15 ` [PATCH v4 05/17] khwasan: initialize shadow to 0xff Andrey Konovalov
2018-06-26 13:15 ` [PATCH v4 06/17] khwasan, arm64: untag virt address in __kimg_to_phys and _virt_addr_is_linear Andrey Konovalov
2018-06-26 13:15 ` [PATCH v4 07/17] khwasan: add tag related helper functions Andrey Konovalov
2018-06-26 13:15 ` [PATCH v4 08/17] khwasan, arm64: fix up fault handling logic Andrey Konovalov
2018-06-26 13:15 ` [PATCH v4 09/17] khwasan, arm64: enable top byte ignore for the kernel Andrey Konovalov
2018-06-26 13:15 ` [PATCH v4 10/17] khwasan, mm: perform untagged pointers comparison in krealloc Andrey Konovalov
2018-06-26 13:15 ` [PATCH v4 11/17] khwasan: split out kasan_report.c from report.c Andrey Konovalov
2018-06-26 13:15 ` [PATCH v4 12/17] khwasan: add bug reporting routines Andrey Konovalov
2018-06-26 13:15 ` [PATCH v4 13/17] khwasan: add hooks implementation Andrey Konovalov
2018-07-25 13:44   ` Vincenzo Frascino@Foss
2018-07-31 13:05     ` Andrey Konovalov
2018-07-31 14:50       ` Andrey Ryabinin
2018-07-31 15:03         ` Dmitry Vyukov
2018-07-31 15:38           ` Christopher Lameter
2018-07-31 16:03             ` Dmitry Vyukov
2018-07-31 16:04           ` Andrey Ryabinin
2018-07-31 16:08             ` Dmitry Vyukov [this message]
2018-07-31 16:18               ` Andrey Ryabinin
2018-07-31 15:21         ` Andrey Konovalov
2018-06-26 13:15 ` [PATCH v4 14/17] khwasan, arm64: add brk handler for inline instrumentation Andrey Konovalov
2018-06-26 13:15 ` [PATCH v4 15/17] khwasan, mm, arm64: tag non slab memory allocated via pagealloc Andrey Konovalov
2018-06-26 13:15 ` [PATCH v4 16/17] khwasan: update kasan documentation Andrey Konovalov
2018-06-26 13:15 ` [PATCH v4 17/17] kasan: add SPDX-License-Identifier mark to source files Andrey Konovalov
2018-06-27 23:08 ` [PATCH v4 00/17] khwasan: kernel hardware assisted address sanitizer Andrew Morton
2018-06-28  0:04   ` Kostya Serebryany
     [not found]     ` <CAEZpscCcP6=O_OCqSwW8Y6u9Ee99SzWN+hRcgpP2tK=OEBFnNw@mail.gmail.com>
2018-06-28  1:11       ` Andrew Morton
2018-06-28 18:26         ` Andrey Konovalov
2018-06-28  7:01     ` Geert Uytterhoeven
2018-07-02 20:33     ` Matthew Wilcox
2018-07-02 23:39       ` Evgenii Stepanov
2018-06-28 18:29   ` Andrey Konovalov
2018-06-28 19:40     ` Andrew Morton
2018-06-29 12:45       ` Andrey Konovalov
2018-06-29 13:01         ` Mark Rutland
2018-06-29 14:40           ` Andrey Konovalov
2018-06-30  2:41         ` Andrew Morton
2018-07-02 19:16           ` Evgenii Stepanov
2018-07-02 19:21             ` Andrew Morton
2018-07-02 20:22               ` Evgenii Stepanov
2018-07-02 20:30                 ` Andrew Morton
2018-06-28 10:51 ` Dave Martin
2018-06-28 18:56   ` Andrey Konovalov
2018-06-29 10:14     ` Mark Rutland
2018-06-29 11:04     ` Dave Martin
2018-06-29 11:26       ` Luc Van Oostenryck
2018-06-29 13:18         ` Andrey Konovalov
2018-06-29 13:42         ` Dan Carpenter
2018-06-29 11:07     ` Catalin Marinas
2018-06-29 11:07     ` Will Deacon
2018-06-29 16:36       ` Andrey Konovalov
2018-07-03 17:36         ` Will Deacon
2018-07-18 17:16           ` Andrey Konovalov
2018-07-31 13:22             ` Andrey Konovalov
2018-08-01 16:35               ` Will Deacon
2018-08-01 16:52                 ` Dmitry Vyukov
2018-08-02 11:10                   ` Catalin Marinas
2018-08-02 11:36                     ` Dmitry Vyukov
2018-08-02 13:52                       ` Catalin Marinas
2018-08-02 14:11                         ` Andrey Ryabinin
2018-08-03  9:23                   ` Will Deacon
2018-08-03  9:42                     ` Dmitry Vyukov
2018-08-08 16:27                       ` Will Deacon
2018-08-08 16:53                         ` Dmitry Vyukov

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='CACT4Y+aUs0YMTaQx4x9QiQsMjFNZ5gUFNuMkG_hneDPTb3Nu=Q@mail.gmail.com' \
    --to=dvyukov@google.com \
    --cc=Jacob.Bramley@arm.com \
    --cc=Lee.Smith@arm.com \
    --cc=Ramana.Radhakrishnan@arm.com \
    --cc=Ruben.Ayrapetyan@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=andreyknvl@google.com \
    --cc=ard.biesheuvel@linaro.org \
    --cc=arnd@arndb.de \
    --cc=aryabinin@virtuozzo.com \
    --cc=catalin.marinas@arm.com \
    --cc=cl@linux.com \
    --cc=cpandya@codeaurora.org \
    --cc=dave.martin@arm.com \
    --cc=ebiederm@xmission.com \
    --cc=eugenis@google.com \
    --cc=geert@linux-m68k.org \
    --cc=glider@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jannh@google.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=kcc@google.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=kstewart@linuxfoundation.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=marc.zyngier@arm.com \
    --cc=mark.rutland@arm.com \
    --cc=markbrand@google.com \
    --cc=mingo@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=paullawrence@google.com \
    --cc=rppt@linux.vnet.ibm.com \
    --cc=vincenzo.frascino@arm.com \
    --cc=will.deacon@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;
as well as URLs for NNTP newsgroup(s).