Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp781047pxb; Thu, 5 Nov 2020 12:51:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJxAsbeecKe87S0ymSCsEMbEAECl2cxs5MKsVq1WbEITEHB/FC4zTe44AmoPKulsTTYq/zEe X-Received: by 2002:a17:906:a996:: with SMTP id jr22mr4298425ejb.463.1604609497416; Thu, 05 Nov 2020 12:51:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604609497; cv=none; d=google.com; s=arc-20160816; b=VApS0U9iGxYuGstrNWBgMYt+Bun86AOqaZ60x5+uw094U6t1MGQrhYbnYRDMqEBoAv uzeVu8cZ3ezsCd2i+Z5xS9WPCHF/cIyu/w8mVrwumDTQyyUVzEVWX/WP1M4OBmwwA87v QJe0Ryyo5wWoXxypD8+b2bMuuP41av934u3d8CZ+vlyNwiwLpXiZb/gcJq4Ol6RIgKwz F/8mN/B0Ruxp4WkP07dTMoO1A+Q8ilCa/m0jZEZn3OJfATllF7fU1ZqUoxXIlfE8YiB4 Kv2xOIWLsMtJB0V8nVQlkFhvYUXWU8bEO8WpS/Dnlr4wz/N6oyvEbzkew6N+9iCVfAau MwIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=a2MIruyaauzWgJCQrDte1MB4IpvSBdXb3vNyeqYlOUw=; b=cglgh+ckCF48BA5xqxEOZPQhee1BnfpuEelj70rQr8ce2oUc48MpUpbxvbzp6E55Uf y4Ic9GFd8p8PXZ1SSCYQ9mjva1ekO2Z5+pjhbhIHi//YPBna/UU0QG6gRd1N5KXcYpEo qMdeJUrFT9BYOiDhsyFZTyqXXLhjAPkieHgihjAE5BUqxWSuSqh29AglcdXVP7P4DJOO uOfzKCUZrIv+8n3bQr/XxThsdZv7UehV7MvgJVizSfuqsMRpd8wt/azlLu2KhI0Q6/pG uMGHrjZKNIGpYkN4P0YNwMOZKBMILRIYicYPFkJuQFlsBTTvlu19UnfJlNn978nlKdWE UZZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ESrF9IcK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id k6si2030260edk.229.2020.11.05.12.51.10; Thu, 05 Nov 2020 12:51:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ESrF9IcK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1732035AbgKEUtc (ORCPT + 99 others); Thu, 5 Nov 2020 15:49:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728137AbgKEUtc (ORCPT ); Thu, 5 Nov 2020 15:49:32 -0500 Received: from mail-yb1-xb43.google.com (mail-yb1-xb43.google.com [IPv6:2607:f8b0:4864:20::b43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 479BAC0613CF for ; Thu, 5 Nov 2020 12:49:32 -0800 (PST) Received: by mail-yb1-xb43.google.com with SMTP id g15so2065644ybq.6 for ; Thu, 05 Nov 2020 12:49:32 -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; bh=a2MIruyaauzWgJCQrDte1MB4IpvSBdXb3vNyeqYlOUw=; b=ESrF9IcKhtDw5DqW9rXJ+qkn5shjVlT4Cjig2bs8yPhkAcgiU+hrT6N/0OzyZU3yjv prDeyiV6SymdWZsuBfKqyBZ+YoBHntnyygI1Xpc/Tdx4FG8SuVO86FaSB6Qb8Ig7Kpne fBf4epGDxYzLfrHKgVyFbhjOmvz8kMAkKAfPsQC2amGWqF/sfjd25MNg2/E3T3HhfpGW YZ8e2wrs0MLvpR6+6Us0x1w5mgi5Lbonal2TaMg/b9+Y10oCoAfhLV3xSqbUyzSfwdro pkO3gT0mj1UmG8cGgi/quABuGHVYVPBRyghAKqSUzESdZxzYxqrO7xwTVqYiahlmCejk NDjQ== 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; bh=a2MIruyaauzWgJCQrDte1MB4IpvSBdXb3vNyeqYlOUw=; b=NKNLlADmYGX1WFXG08SqUp0o0nLgOEZw5OLkq1Jc+CvY61pBhL/5Cgu2zQ8QSYYHl6 IKWwc+qxmDLXr0LDKpqzwRyM773ITH28019mGpWjFqGcaCsHFypf0HRi6qV81Y3wY4Ge wRAmnI3FuYIRlcHrFffgSi5of9udt2dDbvlxMdqA+edLxtxtUjEq+vvrJ139hxMmuSKL Vp4lHZ0IRGy2bpx5H8V63129I5UjTFRFDiJs21/v7zVVKbQlvIeHqIX5W4os3vu9sAXO TwOyQ3aar2sxnRolqb/Y+/iQ00gMp2ZW4R9DE3wflPOZbVRsWoX63wYbjtlpG9Oei9Yc 4N6w== X-Gm-Message-State: AOAM533ZLadtLHt7NRKzcqF71JMr/uENTpLLnYlqbQ/KgkSJ7yRPTf4a a7hEhn7nOxgoP7I2kqyfBadl5ZdCPUeIk2W7+3oY8Q== X-Received: by 2002:a25:b2a1:: with SMTP id k33mr6394582ybj.337.1604609371269; Thu, 05 Nov 2020 12:49:31 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Evgenii Stepanov Date: Thu, 5 Nov 2020 12:49:19 -0800 Message-ID: Subject: Re: [PATCH 00/20] kasan: boot parameters for hardware tag-based mode To: Andrey Konovalov Cc: Catalin Marinas , Will Deacon , Vincenzo Frascino , Dmitry Vyukov , Alexander Potapenko , Marco Elver , Andrey Ryabinin , Branislav Rankov , Kevin Brodsky , Andrew Morton , kasan-dev , Linux ARM , Linux Memory Management List , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 4, 2020 at 4:02 PM Andrey Konovalov wrote: > > === Overview > > Hardware tag-based KASAN mode [1] is intended to eventually be used in > production as a security mitigation. Therefore there's a need for finer > control over KASAN features and for an existence of a kill switch. > > This patchset adds a few boot parameters for hardware tag-based KASAN that > allow to disable or otherwise control particular KASAN features. > > There's another planned patchset what will further optimize hardware > tag-based KASAN, provide proper benchmarking and tests, and will fully > enable tag-based KASAN for production use. > > Hardware tag-based KASAN relies on arm64 Memory Tagging Extension (MTE) > [2] to perform memory and pointer tagging. Please see [3] and [4] for > detailed analysis of how MTE helps to fight memory safety problems. > > The features that can be controlled are: > > 1. Whether KASAN is enabled at all. > 2. Whether KASAN collects and saves alloc/free stacks. > 3. Whether KASAN panics on a detected bug or not. > > The patch titled "kasan: add and integrate kasan boot parameters" of this > series adds a few new boot parameters. > > kasan.mode allows to choose one of three main modes: > > - kasan.mode=off - KASAN is disabled, no tag checks are performed > - kasan.mode=prod - only essential production features are enabled > - kasan.mode=full - all KASAN features are enabled > > The chosen mode provides default control values for the features mentioned > above. However it's also possible to override the default values by > providing: > > - kasan.stack=off/on - enable stacks collection > (default: on for mode=full, otherwise off) I think this was discussed before, but should this be kasan.stacktrace or something like that? In other places "kasan stack" refers to stack instrumentation, not stack trace collection. Ex.: CONFIG_KASAN_STACK > - kasan.fault=report/panic - only report tag fault or also panic > (default: report) > > If kasan.mode parameter is not provided, it defaults to full when > CONFIG_DEBUG_KERNEL is enabled, and to prod otherwise. > > It is essential that switching between these modes doesn't require > rebuilding the kernel with different configs, as this is required by > the Android GKI (Generic Kernel Image) initiative. > > === Benchmarks > > For now I've only performed a few simple benchmarks such as measuring > kernel boot time and slab memory usage after boot. There's an upcoming > patchset which will optimize KASAN further and include more detailed > benchmarking results. > > The benchmarks were performed in QEMU and the results below exclude the > slowdown caused by QEMU memory tagging emulation (as it's different from > the slowdown that will be introduced by hardware and is therefore > irrelevant). > > KASAN_HW_TAGS=y + kasan.mode=off introduces no performance or memory > impact compared to KASAN_HW_TAGS=n. > > kasan.mode=prod (manually excluding tagging) introduces 3% of performance > and no memory impact (except memory used by hardware to store tags) > compared to kasan.mode=off. > > kasan.mode=full has about 40% performance and 30% memory impact over > kasan.mode=prod. Both come from alloc/free stack collection. > > === Notes > > This patchset is available here: > > https://github.com/xairy/linux/tree/up-boot-mte-v1 > > and on Gerrit here: > > https://linux-review.googlesource.com/c/linux/kernel/git/torvalds/linux/+/3707 > > This patchset is based on v8 of "kasan: add hardware tag-based mode for > arm64" patchset [1]. > > For testing in QEMU hardware tag-based KASAN requires: > > 1. QEMU built from master [6] (use "-machine virt,mte=on -cpu max" arguments > to run). > 2. GCC version 10. > > [1] https://lkml.org/lkml/2020/11/4/1208 > [2] https://community.arm.com/developer/ip-products/processors/b/processors-ip-blog/posts/enhancing-memory-safety > [3] https://arxiv.org/pdf/1802.09517.pdf > [4] https://github.com/microsoft/MSRC-Security-Research/blob/master/papers/2020/Security%20analysis%20of%20memory%20tagging.pdf > [5] https://source.android.com/devices/architecture/kernel/generic-kernel-image > [6] https://github.com/qemu/qemu > > === History > > Changes RFC v2 -> v1: > - Rebrand the patchset from fully enabling production use to partially > addressing that; another optimization and testing patchset will be > required. > - Rebase onto v8 of KASAN_HW_TAGS series. > - Fix "ASYNC" -> "async" typo. > - Rework depends condition for VMAP_STACK and update config text. > - Remove unneeded reset_tag() macro, use kasan_reset_tag() instead. > - Rename kasan.stack to kasan.stacks to avoid confusion with stack > instrumentation. > - Introduce kasan_stack_collection_enabled() and kasan_is_enabled() > helpers. > - Simplify kasan_stack_collection_enabled() usage. > - Rework SLAB_KASAN flag and metadata allocation (see the corresponding > patch for details). > - Allow cache merging with KASAN_HW_TAGS when kasan.stacks is off. > - Use sync mode dy default for both prod and full KASAN modes. > - Drop kasan.trap=sync/async boot parameter, as async mode isn't supported > yet. > - Choose prod or full mode depending on CONFIG_DEBUG_KERNEL when no > kasan.mode boot parameter is provided. > - Drop krealloc optimization changes, those will be included in a separate > patchset. > - Update KASAN documentation to mention boot parameters. > > Changes RFC v1 -> RFC v2: > - Rework boot parameters. > - Drop __init from empty kasan_init_tags() definition. > - Add cpu_supports_mte() helper that can be used during early boot and use > it in kasan_init_tags() > - Lots of new KASAN optimization commits. > > Andrey Konovalov (20): > kasan: simplify quarantine_put call site > kasan: rename get_alloc/free_info > kasan: introduce set_alloc_info > kasan, arm64: unpoison stack only with CONFIG_KASAN_STACK > kasan: allow VMAP_STACK for HW_TAGS mode > kasan: remove __kasan_unpoison_stack > kasan: inline kasan_reset_tag for tag-based modes > kasan: inline random_tag for HW_TAGS > kasan: inline kasan_poison_memory and check_invalid_free > kasan: inline and rename kasan_unpoison_memory > kasan: add and integrate kasan boot parameters > kasan, mm: check kasan_enabled in annotations > kasan: simplify kasan_poison_kfree > kasan, mm: rename kasan_poison_kfree > kasan: don't round_up too much > kasan: simplify assign_tag and set_tag calls > kasan: clarify comment in __kasan_kfree_large > kasan: clean up metadata allocation and usage > kasan, mm: allow cache merging with no metadata > kasan: update documentation > > Documentation/dev-tools/kasan.rst | 180 ++++++++++++-------- > arch/Kconfig | 8 +- > arch/arm64/kernel/sleep.S | 2 +- > arch/x86/kernel/acpi/wakeup_64.S | 2 +- > include/linux/kasan.h | 253 +++++++++++++++++++++------ > include/linux/mm.h | 22 ++- > kernel/fork.c | 2 +- > mm/kasan/common.c | 274 ++++++++++++++++++------------ > mm/kasan/generic.c | 27 +-- > mm/kasan/hw_tags.c | 171 ++++++++++++++++--- > mm/kasan/kasan.h | 113 ++++++++---- > mm/kasan/quarantine.c | 13 +- > mm/kasan/report.c | 61 ++++--- > mm/kasan/report_hw_tags.c | 2 +- > mm/kasan/report_sw_tags.c | 13 +- > mm/kasan/shadow.c | 5 +- > mm/kasan/sw_tags.c | 17 +- > mm/mempool.c | 2 +- > mm/slab_common.c | 13 +- > 19 files changed, 816 insertions(+), 364 deletions(-) > > -- > 2.29.1.341.ge80a0c044ae-goog >