Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5130486imm; Tue, 31 Jul 2018 06:07:02 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdtuP/jfbqcrmaRFZtACE2TK51C/FjYw3r8Pg0W49y6MfaSQPq1D+L7NzyTWQPiNjodjEwz X-Received: by 2002:a63:4703:: with SMTP id u3-v6mr19808922pga.405.1533042422222; Tue, 31 Jul 2018 06:07:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533042422; cv=none; d=google.com; s=arc-20160816; b=rZlOn3Y6ym2uSRTIv1sIhqFlel/mpyZDcNa3HDDmkNAYhy/2lDqHdPcm2oR7c/Z73q qMuJwqhorNxK2Y59FwfcO36JACk06yW2XydMui2Ae2OzOxzRq9LRBBFs0tuP1WbFBr1Y O6QasHeOmYPe75XTZne8GZdB+r0KzlWZKT2BPyqyi7oeJoc16Llj35KsRqSYHqSJ752V 0EE3kwIuUuuyPP/IZmGiC3JYEj8H3nYLuS94oHXvZ3SN7vlvU2RgpB72mGC2zPQe2JLl NTLY7dOaaE3ig0uRTV40nNoLRZ1CzZ8CA8+LClxN7OhVuMt4mmvUwKIEIUOg4RYqvP8+ CkpA== 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=KDgx1wu0S4s/fsoNbAILQ44BQFWBJhQa9o5lBqBhbsA=; b=UUFsHRhrwsB2z7SRWTGJmiDYLhI5pza+Ve4vaLRhe21sgmo+CfRAzUMr9apQA9rLic fEuG/6QkGcOy1HXefGpHW9KWHcAQwR/mrBS7BYiR6CiJzaAx0jUiABgSVgN3+z7AFKWQ LTyEppCKV4xMAkFQwqsurGUJmMMCJOXOBGJWFUET/7JffwqOTXpDyE6m8LjRW2NkeG72 qp6cWXO/AcPoYOAi4piHs7RRHR/2XQbDkGSYjuFGMZI1jiFVTmjJu6gqGUZs8DGSnTKk ChjqzcGukdnAQhLp7HvvTTi8Sx/g/yJRZHl0qdgUV8I+qa89kFb6R9K7ZpKG/Hi+n9H5 2AHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=QOQWySiU; 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 s35-v6si12751493pgl.656.2018.07.31.06.06.48; Tue, 31 Jul 2018 06:07:02 -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=QOQWySiU; 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 S1732233AbeGaOqQ (ORCPT + 99 others); Tue, 31 Jul 2018 10:46:16 -0400 Received: from mail-it0-f65.google.com ([209.85.214.65]:54099 "EHLO mail-it0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732024AbeGaOqQ (ORCPT ); Tue, 31 Jul 2018 10:46:16 -0400 Received: by mail-it0-f65.google.com with SMTP id 72-v6so4318702itw.3 for ; Tue, 31 Jul 2018 06:06:01 -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=KDgx1wu0S4s/fsoNbAILQ44BQFWBJhQa9o5lBqBhbsA=; b=QOQWySiUBOrjacnJ/0qrKicp9QAp0C7Zv8NRMdXSFPVOgRPlbrS8gNd7RgL6qlUlIj 6Edog2HkYgSwovUnsQr3R6tdcWaZ6CMZOERKw/bmb15/wFIaFCBcmj6z8jkHux9rq87W AO6JyepCVfczcxK4BUkGChYkwGL58YRhMTG+GCY7pJ6Mjz2DlxjNL3eFfJ4sbUys8Pid zWWu3yP+QTS79xD9lQ2WPYNGLpo7l0LCi07KWKX9D9Ha6LTnh2DoSh08tdRfYvYMjqmC iOr2p9fMlVTF0Qu6djS0WqVPm5Dohd9sSqUco6niSssdghIxeO6QOgh2PUlh4M5UVEHI vsQA== 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=KDgx1wu0S4s/fsoNbAILQ44BQFWBJhQa9o5lBqBhbsA=; b=HI1X0qn178QoRzGiRBLfYaVNKykGnpzOT4Z+Cx+Ja9M56sgeSvvNWxN6HIses0lYWF oHa5/fRCea6E1Ux+Ob+xZ3ekiV1iWd0W5/fp7UC61lG4oGzh2os7Vjnd+gJ/3SZ1y2eZ jcUvlppRlcU1w7Z8r4k1J4LhqgWbIcagjfxwGWUfG2RCsv2DetWaiCvjTZKnc6MMQYfX Zu5EmrEmL4LRUVSrjgEXj3anAX/qxgKT7X/nV0/DGjVtknE8kt3fxPomsQPTlng5LOml IJ73/YLzIUT4lgg30ABBIzRWwd3Z5oGXT5zn73/YUj2T5uHZ6JvtkaMgeKtqZV6Jwm9C 541Q== X-Gm-Message-State: AOUpUlF2hypY7TT93b1fb2ELkvS1fE/rVPoFRYDrHjkOOz4DbHuYCMk3 rSCCezRYl4ZWrHN4NaajA3mAacI693GM95dzu/SImQ== X-Received: by 2002:a24:db05:: with SMTP id c5-v6mr3119100itg.44.1533042360087; Tue, 31 Jul 2018 06:06:00 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a02:918c:0:0:0:0:0 with HTTP; Tue, 31 Jul 2018 06:05:59 -0700 (PDT) In-Reply-To: <09cb5553-d84a-0e62-5174-315c14b88833@arm.com> References: <09cb5553-d84a-0e62-5174-315c14b88833@arm.com> From: Andrey Konovalov Date: Tue, 31 Jul 2018 15:05:59 +0200 Message-ID: Subject: Re: [PATCH v4 13/17] khwasan: add hooks implementation To: vincenzo.frascino@arm.com Cc: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , 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 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. But that is probably something we'll have to deal with if we're aiming for "near-production". I'll add this change to v5, thanks!