Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2020274imu; Fri, 14 Dec 2018 04:37:11 -0800 (PST) X-Google-Smtp-Source: AFSGD/XcAVzNDArTjMV7Zq5ZYg4yRwfuGs2pd0h/kWFAbHowVAP4RjsYhCkE1DDzjbnFD30QYscF X-Received: by 2002:a62:1d4c:: with SMTP id d73mr2732732pfd.90.1544791031421; Fri, 14 Dec 2018 04:37:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544791031; cv=none; d=google.com; s=arc-20160816; b=KbPVKC8IGhH32URVX0boW9OAo0GHTHHunmSkFsLXD6NP9eRluDpXLj82WU2WAEE0jb 0xE+60vBLd8C7TBWqz9K6k2i3eCeLoIG9Dax32b23uC4nayGnMvE4/RBlANRdgldhTgB vrEFUR7anmMRGdd47JnX/7+RKtDJcD4chp+F0WjBEEZKGIme8ZHRSrxniO+FDmaE45ac DsjwDJhs2oB4WsH5y3zrwmFSQWRxe4dykkrF5GbUlg415yX0IbQjUDWcW5srfeG9TB2N tLSXFVEd+ulG1O6dRgADpylWdYNe9iySgFHeecGADYaWzqlLB5erkjuEdw8yfGoq9+/D OQNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=mvwHwR6J2yIrhmsntILr2oxLhkrT1EkD1i4g4jw/joI=; b=0eW2o+Oa7PCAQHds0/14Jxf63y40fjLy8lmnwgzOxNzqvthOUYs+oicKUdLmPOO2T4 CVVFzOGRGljs5Ox6VilTAVtY/ZSqI6O5RhvrDYRmnqe7BKTkdEzeVFPItSPytRbRZ/Jc XKzPwIfc4FaZ/QjtxLEacRxJFUA/SPPRvn2yzWPyEhFfvCq2Qc/Xr35iOUniE19gDkPQ ikUHZID1PjX7qsVWg/J/63JO+qa3wzapl9PLEVgC8FKK0xVb3qFJpqysyR2kGGHKpcmu 1TNm5uQvYgwsFYJiUjigY9wPFIuXv+HIdRjQBcKfWxTQ/Q3d7F8ndLcuYPyxoep75M2z VTLg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u9si4178542plk.61.2018.12.14.04.36.57; Fri, 14 Dec 2018 04:37:11 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731444AbeLNMew (ORCPT + 99 others); Fri, 14 Dec 2018 07:34:52 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:51034 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731336AbeLNMeq (ORCPT ); Fri, 14 Dec 2018 07:34:46 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8B412EBD; Fri, 14 Dec 2018 04:34:45 -0800 (PST) Received: from [10.37.12.200] (unknown [10.37.12.200]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DFCDF3F575; Fri, 14 Dec 2018 04:34:36 -0800 (PST) Subject: Re: [PATCH v13 19/25] kasan: add hooks implementation for tag-based mode To: Andrey Konovalov 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 , "open list:DOCUMENTATION" , LKML , Linux ARM , linux-sparse@vger.kernel.org, Linux Memory Management List , Linux Kbuild mailing list , Vishwath Mohan , Chintan Pandya , Jacob Bramley , Jann Horn , Ruben Ayrapetyan , Lee Smith , Kostya Serebryany , Mark Brand , Ramana Radhakrishnan , Evgenii Stepanov References: <2bf7415e-2724-b3c3-9571-20c8b6d43b92@arm.com> From: Vincenzo Frascino Message-ID: Date: Fri, 14 Dec 2018 12:35:38 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/12/18 3:04 PM, Andrey Konovalov wrote: > On Tue, Dec 11, 2018 at 5:22 PM Vincenzo Frascino > wrote: >> >> Hi Andrey, >> >> On 06/12/2018 12:24, Andrey Konovalov wrote: >>> This commit adds tag-based KASAN specific hooks implementation and >>> adjusts common generic and tag-based KASAN ones. >>> >>> 1. When a new slab cache is created, tag-based KASAN rounds up the size of >>> the objects in this cache to KASAN_SHADOW_SCALE_SIZE (== 16). >>> >>> 2. On each kmalloc tag-based KASAN generates a random tag, sets the shadow >>> memory, that corresponds to this object to this tag, and embeds this >>> tag value into the top byte of the returned pointer. >>> >>> 3. On each kfree tag-based KASAN poisons the shadow memory with a random >>> tag to allow detection of use-after-free bugs. >>> >>> The rest of the logic of the hook implementation is very much similar to >>> the one provided by generic KASAN. Tag-based KASAN saves allocation and >>> free stack metadata to the slab object the same way generic KASAN does. >>> >>> Reviewed-by: Andrey Ryabinin >>> Reviewed-by: Dmitry Vyukov >>> Signed-off-by: Andrey Konovalov >>> --- >>> mm/kasan/common.c | 116 ++++++++++++++++++++++++++++++++++++++-------- >>> mm/kasan/kasan.h | 8 ++++ >>> mm/kasan/tags.c | 48 +++++++++++++++++++ >>> 3 files changed, 153 insertions(+), 19 deletions(-) >>> >> >> >> [...] >> >>> @@ -265,6 +290,8 @@ void kasan_cache_create(struct kmem_cache *cache, unsigned int *size, >>> return; >>> } >>> >>> + cache->align = round_up(cache->align, KASAN_SHADOW_SCALE_SIZE); >>> + >> >> Did you consider to set ARCH_SLAB_MINALIGN instead of this round up? > > I didn't know about this macro. Looks like we can use it to do the > same thing. Do you think it's a better solution to redefine > ARCH_SLAB_MINALIGN to KASAN_SHADOW_SCALE_SIZE for arm64 when tag-based > KASAN is enabled instead of adjusting cache->align in > kasan_cache_create? > Yes, I think it is better because in this way we do not need to add extra code to do the rounding. Curiosity, did you try your patches with SLUB red zoning enabled? Since the area used for the Redzone is just after the payload, aligning the object_size independently from the allocator could have side effects, at least if I understand well how the mechanism works. Setting ARCH_SLAB_MINALIGN should avoid this as well. What do you think? >> >> -- >> Regards, >> Vincenzo >> >> -- >> 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/2bf7415e-2724-b3c3-9571-20c8b6d43b92%40arm.com. >> For more options, visit https://groups.google.com/d/optout. -- Regards, Vincenzo