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=-23.2 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_IN_DEF_DKIM_WL 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 7BBFEC6369E for ; Wed, 18 Nov 2020 16:04:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 991592087D for ; Wed, 18 Nov 2020 16:04:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="bkJ9XPUm" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 991592087D Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B8C6E6B0075; Wed, 18 Nov 2020 11:04:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B15EE6B0078; Wed, 18 Nov 2020 11:04:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9DD9A6B007B; Wed, 18 Nov 2020 11:04:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0067.hostedemail.com [216.40.44.67]) by kanga.kvack.org (Postfix) with ESMTP id 69B1D6B0075 for ; Wed, 18 Nov 2020 11:04:35 -0500 (EST) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id EA923181AEF21 for ; Wed, 18 Nov 2020 16:04:34 +0000 (UTC) X-FDA: 77498011668.01.tray43_311134b2733b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin01.hostedemail.com (Postfix) with ESMTP id 0E7E71004F638 for ; Wed, 18 Nov 2020 16:04:15 +0000 (UTC) X-HE-Tag: tray43_311134b2733b X-Filterd-Recvd-Size: 10260 Received: from mail-qk1-f196.google.com (mail-qk1-f196.google.com [209.85.222.196]) by imf36.hostedemail.com (Postfix) with ESMTP for ; Wed, 18 Nov 2020 16:04:14 +0000 (UTC) Received: by mail-qk1-f196.google.com with SMTP id d28so2216934qka.11 for ; Wed, 18 Nov 2020 08:04:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=mlFiY9rY2V1HzrQlBE+sq5fSkw65JXH+u+EE2Nk2n44=; b=bkJ9XPUmNNJ7/6NIKcAbzPhmQpCAtoRYSGEL4qMTRyQA5Pqkkzp/Mt31P4NRs5W9Yj ppD0Suno3fMJ75wBayjUV0JjcDrWqdxc3Vu0R6mZV8O+W5pfS3tO6n2Dwmcs8Hf8MKtM 1VS49R0oKaHkuv+RKHCrEfeY1NdvtaAPPYfvWWZofovIPNIVJJ8yW6BSL+U9xpSZrfEn MkfcV1l7E3mzVM1MoHKgOIayblHGQNDveOaA5G1mgm2EQ5jXdl4miLiNzThpf5am5lJo 03CiB2iVbdKFGn0Y4i2zx6OAm25M+fb0G3ZpRnzMjGPokXNfC+gcRr7jWicaP+smvCUd w+jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=mlFiY9rY2V1HzrQlBE+sq5fSkw65JXH+u+EE2Nk2n44=; b=HPcFGyfEy3YMfn5K1aPCbRmSIgbpk5ecnLm5D+cGhMVgoG/JccFWc1eSdKmA2AMQ/9 9MLeE935H5fXjcGfS/u1qZBG1HbSJPLy4ZXhZ8/uHZYzUrF0SxzP7uyLD7KlVg4kDH2p ossxzz5LtbMDimIu/KwY1xWUuq2Rkr8RunNc790viTo6v0ri7KWwq18mfGQIXtvIbGuK wxw0CBwx2H41wDM3xjoGodUmxk5F3gdz19PKQ2RSWHR8s7tJUJwL9KD7ydeiUfHjZOwy cWLii1/AoEqnlfqm/aQjm960yPaGurjfinhwwIpJNHqjgDX3bi7p6kbHeRFqKc07N5lC hGPA== X-Gm-Message-State: AOAM532AeW6jdzNUJ1zmUA0NO7z/PMuCxjyEqqhKu9/bZKnpuqBXxW7g arHen1T44hp8YYQTBjhd/Ca31wkl278YLLy+NNI+xw== X-Google-Smtp-Source: ABdhPJwEPbJwrFv+0QgMETmeDZm0HCOqFCDLwfbZRkv+G6SWeQ2jvh0BYURYXScv2GYkJs9kwCrbu/srzzkQHjHfs1g= X-Received: by 2002:a05:620a:f95:: with SMTP id b21mr5514724qkn.403.1605715453444; Wed, 18 Nov 2020 08:04:13 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Alexander Potapenko Date: Wed, 18 Nov 2020 17:04:02 +0100 Message-ID: Subject: Re: [PATCH mm v10 23/42] kasan: introduce CONFIG_KASAN_HW_TAGS To: Andrey Konovalov Cc: Andrew Morton , Catalin Marinas , Will Deacon , Vincenzo Frascino , Dmitry Vyukov , Andrey Ryabinin , Marco Elver , Evgenii Stepanov , Branislav Rankov , Kevin Brodsky , kasan-dev , Linux ARM , Linux Memory Management List , LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, Nov 13, 2020 at 11:17 PM Andrey Konovalov w= rote: > > This patch adds a configuration option for a new KASAN mode called > hardware tag-based KASAN. This mode uses the memory tagging approach > like the software tag-based mode, but relies on arm64 Memory Tagging > Extension feature for tag management and access checking. > > Signed-off-by: Andrey Konovalov > Co-developed-by: Vincenzo Frascino > Signed-off-by: Vincenzo Frascino > Reviewed-by: Marco Elver Reviewed-by: Alexander Potapenko > --- > Change-Id: I246c2def9fffa6563278db1bddfbe742ca7bdefe > --- > lib/Kconfig.kasan | 61 ++++++++++++++++++++++++++++++++++------------- > 1 file changed, 44 insertions(+), 17 deletions(-) > > diff --git a/lib/Kconfig.kasan b/lib/Kconfig.kasan > index c0e9e7874122..f5fa4ba126bf 100644 > --- a/lib/Kconfig.kasan > +++ b/lib/Kconfig.kasan > @@ -6,7 +6,10 @@ config HAVE_ARCH_KASAN > config HAVE_ARCH_KASAN_SW_TAGS > bool > > -config HAVE_ARCH_KASAN_VMALLOC > +config HAVE_ARCH_KASAN_HW_TAGS > + bool > + > +config HAVE_ARCH_KASAN_VMALLOC > bool > > config CC_HAS_KASAN_GENERIC > @@ -15,16 +18,19 @@ config CC_HAS_KASAN_GENERIC > config CC_HAS_KASAN_SW_TAGS > def_bool $(cc-option, -fsanitize=3Dkernel-hwaddress) > > +# This option is only required for software KASAN modes. > +# Old GCC versions don't have proper support for no_sanitize_address. > +# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D89124 for details. > config CC_HAS_WORKING_NOSANITIZE_ADDRESS > def_bool !CC_IS_GCC || GCC_VERSION >=3D 80300 > > menuconfig KASAN > bool "KASAN: runtime memory debugger" > - depends on (HAVE_ARCH_KASAN && CC_HAS_KASAN_GENERIC) || \ > - (HAVE_ARCH_KASAN_SW_TAGS && CC_HAS_KASAN_SW_TAGS) > + depends on (((HAVE_ARCH_KASAN && CC_HAS_KASAN_GENERIC) || \ > + (HAVE_ARCH_KASAN_SW_TAGS && CC_HAS_KASAN_SW_TAGS)) &= & \ > + CC_HAS_WORKING_NOSANITIZE_ADDRESS) || \ > + HAVE_ARCH_KASAN_HW_TAGS > depends on (SLUB && SYSFS) || (SLAB && !DEBUG_SLAB) > - depends on CC_HAS_WORKING_NOSANITIZE_ADDRESS > - select CONSTRUCTORS > select STACKDEPOT > help > Enables KASAN (KernelAddressSANitizer) - runtime memory debugge= r, > @@ -37,18 +43,24 @@ choice > prompt "KASAN mode" > default KASAN_GENERIC > help > - KASAN has two modes: generic KASAN (similar to userspace ASan, > - x86_64/arm64/xtensa, enabled with CONFIG_KASAN_GENERIC) and > - software tag-based KASAN (a version based on software memory > - tagging, arm64 only, similar to userspace HWASan, enabled with > - CONFIG_KASAN_SW_TAGS). > + KASAN has three modes: > + 1. generic KASAN (similar to userspace ASan, > + x86_64/arm64/xtensa, enabled with CONFIG_KASAN_GENERIC), > + 2. software tag-based KASAN (arm64 only, based on software > + memory tagging (similar to userspace HWASan), enabled with > + CONFIG_KASAN_SW_TAGS), and > + 3. hardware tag-based KASAN (arm64 only, based on hardware > + memory tagging, enabled with CONFIG_KASAN_HW_TAGS). > + > + All KASAN modes are strictly debugging features. > > - Both generic and tag-based KASAN are strictly debugging feature= s. > + For better error reports enable CONFIG_STACKTRACE. > > config KASAN_GENERIC > bool "Generic mode" > depends on HAVE_ARCH_KASAN && CC_HAS_KASAN_GENERIC > select SLUB_DEBUG if SLUB > + select CONSTRUCTORS > help > Enables generic KASAN mode. > > @@ -61,8 +73,6 @@ config KASAN_GENERIC > and introduces an overhead of ~x1.5 for the rest of the allocat= ions. > The performance slowdown is ~x3. > > - For better error detection enable CONFIG_STACKTRACE. > - > Currently CONFIG_KASAN_GENERIC doesn't work with CONFIG_DEBUG_S= LAB > (the resulting kernel does not boot). > > @@ -70,11 +80,15 @@ config KASAN_SW_TAGS > bool "Software tag-based mode" > depends on HAVE_ARCH_KASAN_SW_TAGS && CC_HAS_KASAN_SW_TAGS > select SLUB_DEBUG if SLUB > + select CONSTRUCTORS > help > Enables software tag-based KASAN mode. > > - This mode requires Top Byte Ignore support by the CPU and there= fore > - is only supported for arm64. This mode requires Clang. > + This mode require software memory tagging support in the form o= f > + HWASan-like compiler instrumentation. > + > + Currently this mode is only implemented for arm64 CPUs and reli= es on > + Top Byte Ignore. This mode requires Clang. > > This mode consumes about 1/16th of available memory at kernel s= tart > and introduces an overhead of ~20% for the rest of the allocati= ons. > @@ -82,15 +96,27 @@ config KASAN_SW_TAGS > casting and comparison, as it embeds tags into the top byte of = each > pointer. > > - For better error detection enable CONFIG_STACKTRACE. > - > Currently CONFIG_KASAN_SW_TAGS doesn't work with CONFIG_DEBUG_S= LAB > (the resulting kernel does not boot). > > +config KASAN_HW_TAGS > + bool "Hardware tag-based mode" > + depends on HAVE_ARCH_KASAN_HW_TAGS > + depends on SLUB > + help > + Enables hardware tag-based KASAN mode. > + > + This mode requires hardware memory tagging support, and can be = used > + by any architecture that provides it. > + > + Currently this mode is only implemented for arm64 CPUs starting= from > + ARMv8.5 and relies on Memory Tagging Extension and Top Byte Ign= ore. > + > endchoice > > choice > prompt "Instrumentation type" > + depends on KASAN_GENERIC || KASAN_SW_TAGS > default KASAN_OUTLINE > > config KASAN_OUTLINE > @@ -114,6 +140,7 @@ endchoice > > config KASAN_STACK_ENABLE > bool "Enable stack instrumentation (unsafe)" if CC_IS_CLANG && !C= OMPILE_TEST > + depends on KASAN_GENERIC || KASAN_SW_TAGS > help > The LLVM stack address sanitizer has a know problem that > causes excessive stack usage in a lot of functions, see > -- > 2.29.2.299.gdc1121823c-goog > --=20 Alexander Potapenko Software Engineer Google Germany GmbH Erika-Mann-Stra=C3=9Fe, 33 80636 M=C3=BCnchen Gesch=C3=A4ftsf=C3=BChrer: Paul Manicle, Halimah DeLaine Prado Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg