From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.9 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D581C6786C for ; Fri, 14 Dec 2018 12:34:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 441A520892 for ; Fri, 14 Dec 2018 12:34:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 441A520892 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731452AbeLNMex (ORCPT ); Fri, 14 Dec 2018 07:34:53 -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 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Vincenzo Frascino Subject: Re: [PATCH v13 19/25] kasan: add hooks implementation for tag-based mode Date: Fri, 14 Dec 2018 12:35:38 +0000 Message-ID: References: <2bf7415e-2724-b3c3-9571-20c8b6d43b92@arm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org 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 List-Id: linux-sparse@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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1ACBFC67839 for ; Fri, 14 Dec 2018 12:35:05 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DF529208E7 for ; Fri, 14 Dec 2018 12:35:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="lqEMgLQT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DF529208E7 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date: Message-ID:From:References:To:Subject:Reply-To:Content-ID:Content-Description :Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=HQA6dnr1l3iouS9d/kXf7ud++a8jbCrosiXk5b2z26M=; b=lqEMgLQTTHCw2p tV1op3+kuKWW1+aLZy2jL7xx9trEHYOAMSEwLjWqciUHi5A+ECGFndojh3J9e09D/LFNyGo0thtv/ cnp3uFY/AzdlZ8q2+VQttsFejeNncgNdw4y8wlMJYgZ4nKUF/7aOLlq0BMUovkw1WMnWXfKdK+ZAM jc5kEynW1B4PqYolovNl4gkRNZ3nXw00kgrDGymcKuMTze6+XHRC7TZsfyDZ/AIqJuKbp+lcQZw2j V/UtJ6OSxM/kLMPge8/PxPsJY3WrQuxPbS/29HtcPLtcrZ7Bq4ZYDZmsoES5vFxVKFeIbtq1PV+i+ yKosoy3gckh6hWXrKtfw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gXmgJ-0001as-Oz; Fri, 14 Dec 2018 12:35:03 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gXmgG-0001Nw-Oe for linux-arm-kernel@lists.infradead.org; Fri, 14 Dec 2018 12:35:02 +0000 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 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-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181214_043500_808904_CAA9424F X-CRM114-Status: GOOD ( 27.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Kate Stewart , "open list:DOCUMENTATION" , Catalin Marinas , Will Deacon , Paul Lawrence , Linux Memory Management List , Alexander Potapenko , Chintan Pandya , Christoph Lameter , Ingo Molnar , Jacob Bramley , Jann Horn , Mark Brand , kasan-dev , linux-sparse@vger.kernel.org, Geert Uytterhoeven , Linux ARM , Andrey Ryabinin , Dave Martin , Evgenii Stepanov , Vishwath Mohan , Arnd Bergmann , Linux Kbuild mailing list , Marc Zyngier , Ramana Radhakrishnan , Ruben Ayrapetyan , Mike Rapoport , Dmitry Vyukov , Kostya Serebryany , Ard Biesheuvel , Greg Kroah-Hartman , Nick Desaulniers , LKML , "Eric W . Biederman" , Lee Smith , Andrew Morton , "Kirill A. Shutemov" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel