Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5263202imm; Tue, 31 Jul 2018 08:05:52 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfyLeM3a4nxKDWNOoaHLM27qbfXdqC0Uk4Xdb5qz092V+iJ98R1Q3DFd/HJkUE/tT6BiQsd X-Received: by 2002:a65:6102:: with SMTP id z2-v6mr21131665pgu.46.1533049551992; Tue, 31 Jul 2018 08:05:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533049551; cv=none; d=google.com; s=arc-20160816; b=T5btBNrimdeMMICpdzGz7I49nrWXv7b49EFFPRYQCamNI8nhH5OfLMtxn2JMbivtSx Y4ocdX0P2eDyQbdOWtUrPMiZ8Bts0d6eIjM2mjTTJnav6ADERYDddxO15I8xpP2Tud6M qaC7fT0l6kj6ECE08FMUMfRyjyDWi3A/qtctrFLqQzDk90KWxs7z0e/NFZxiT8gs8zP7 uKe+nKrdkUWtTA2Q2zkhkJR75VqZ2poXeNDGuDWtNbXrvgHDetzsJBtztGdAIACwSwD8 cv8d+WAC5+1oAfahbkuSJbP8K0Vb/KxQrBgGTBYakepDA2GljTBTPOBOOx8ZLFk+wmGp 22kQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=hxKwoqPx+1v6QE4Wii7+9bEFKhtnRYZZMZ0YRW09gbw=; b=Rr9uunKCvaCVG0N9bou62TaZUAC+65kA29H0KzQpEINwNA6xr+9lvwv28+44Ez25Bi f3N3H7ej9WTPRuFG/AgQCV07lqeghx54Zis3guzxjJ30HjT/LnC/b7eUDx/VWc6bxcE5 XGA/iH0wZzxBFOt++4/TY8u7oamqg5bpisaLgGSakIi8jF//IBPrzVuiZSoxaHo/v4Hr ls9ZNtYehZp+KhnznC2yiHuKRxVbNI06E4xmC6y3cQoHxbtGX+gredBzzzaq3A3VJyuz l2FfEJJtWcsLjUqfovln6MPdWD7J+pmKVUBLNSLlb6GsGPSX3AxINR1LxBFkEmaJlx5K qfDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=G0AnkvIl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n17-v6si14344729pgh.609.2018.07.31.08.05.37; Tue, 31 Jul 2018 08:05:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=G0AnkvIl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732481AbeGaQoy (ORCPT + 99 others); Tue, 31 Jul 2018 12:44:54 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:46112 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729175AbeGaQox (ORCPT ); Tue, 31 Jul 2018 12:44:53 -0400 Received: by mail-pf1-f194.google.com with SMTP id u24-v6so6242872pfn.13 for ; Tue, 31 Jul 2018 08:04:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=hxKwoqPx+1v6QE4Wii7+9bEFKhtnRYZZMZ0YRW09gbw=; b=G0AnkvIlSl+p3X1Kd4p4zsGfzPma6opgB7tPaIPB/12olRSkjplGAua8uKPCCe6Yw1 jgFoJ4L2+gqX3N+qmRopgkfRzzxe9kWOgg4GcRGD7lLGfNjjoGEkpQnBaHvCN1H052l/ Q5Q/iL933M/AGNUbxGYo85kn4EtTpZLADYQpUXpZqXRzvUo8mdFBGPcOtfOGqTTuuJcj L6jFczWCtRem96i4CYUJnjZPoVuzReLi9gYbpwiABPP2up717sqgF0h8utSoWf2SRKLo I8CMD1EiOZ6n+AtzVuRIcxKgjwyRwxe2MwDddT1jhlfuEhL5jyr0htxEPQ/bqvQJG3in +sKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=hxKwoqPx+1v6QE4Wii7+9bEFKhtnRYZZMZ0YRW09gbw=; b=f7QlWG5EBbc4E7b6dBvsk7r6kznHV9agbGPxwoeRDD93YCoGbQ2k+tmP0PM+XsiFbP wntjs3IpPerW6+XKTHFUyXLVYnARd08qaPJ+dqsFD0EYH3xDy/mwSYQojIIiniMboGHt djCCzgWFLOMop/TisWd2PCMOnD1KSWZFyhxvD3vz+g34kcYxCHa2GuzwIgFuVzjLtz+i whr0gdM4VCzPto3TGX3KxSJYMjvzF/G+oEwLJkdd/VPNs37AYayIbfpr1hMu6GkZEwED AlmKtpUsGPbNo0fiJSberHvXTWmMz7lnXOt2OVYriOpgVbqymC/hiZ/Lm6EROiCeUaFq bg1A== X-Gm-Message-State: AOUpUlHCeBUI0Mug3d5i/9W9JsXTiIJAlhpZ9dQAiJWwEcVyLRSNjEq8 GtYudwGDqVRVYAjFYZWcaKxxh1E/z9GbpsQ9K+zEPg== X-Received: by 2002:a63:743:: with SMTP id 64-v6mr21432509pgh.216.1533049448980; Tue, 31 Jul 2018 08:04:08 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a17:90a:ac14:0:0:0:0 with HTTP; Tue, 31 Jul 2018 08:03:48 -0700 (PDT) In-Reply-To: <8240d4f9-c8df-cfe9-119d-6e933f8b13df@virtuozzo.com> References: <09cb5553-d84a-0e62-5174-315c14b88833@arm.com> <8240d4f9-c8df-cfe9-119d-6e933f8b13df@virtuozzo.com> From: Dmitry Vyukov Date: Tue, 31 Jul 2018 17:03:48 +0200 Message-ID: Subject: Re: [PATCH v4 13/17] khwasan: add hooks implementation To: Andrey Ryabinin Cc: Andrey Konovalov , vincenzo.frascino@arm.com, Alexander Potapenko , Catalin Marinas , Will Deacon , Christoph Lameter , Andrew Morton , Mark Rutland , Nick Desaulniers , Marc Zyngier , Dave Martin , Ard Biesheuvel , "Eric W . Biederman" , Ingo Molnar , Paul Lawrence , Geert Uytterhoeven , Arnd Bergmann , "Kirill A . Shutemov" , Greg Kroah-Hartman , Kate Stewart , Mike Rapoport , kasan-dev , linux-doc@vger.kernel.org, LKML , Linux ARM , linux-sparse@vger.kernel.org, Linux Memory Management List , Linux Kbuild mailing list , Chintan Pandya , Jacob Bramley , Jann Horn , Ruben Ayrapetyan , Lee Smith , Kostya Serebryany , Mark Brand , Ramana Radhakrishnan , Evgeniy Stepanov Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 31, 2018 at 4:50 PM, Andrey Ryabinin wrote: > > > On 07/31/2018 04:05 PM, Andrey Konovalov wrote: >> On Wed, Jul 25, 2018 at 3:44 PM, Vincenzo Frascino@Foss >> wrote: >>> On 06/26/2018 02:15 PM, Andrey Konovalov 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? Or I am missing something subtle? What would be a canonical usage of SLAB_TYPESAFE_BY_RCU slab without a ctor?