From patchwork Fri Mar 12 14:24:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12134785 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=-26.3 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, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL 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 CF92FC433DB for ; Fri, 12 Mar 2021 14:24:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 79B3964FC3 for ; Fri, 12 Mar 2021 14:24:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 79B3964FC3 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 ECE2D8D035B; Fri, 12 Mar 2021 09:24:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E7E298D0346; Fri, 12 Mar 2021 09:24:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D46768D035B; Fri, 12 Mar 2021 09:24:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0242.hostedemail.com [216.40.44.242]) by kanga.kvack.org (Postfix) with ESMTP id BAA908D0346 for ; Fri, 12 Mar 2021 09:24:39 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 7F04818149422 for ; Fri, 12 Mar 2021 14:24:39 +0000 (UTC) X-FDA: 77911443078.19.67626BC Received: from mail-qk1-f202.google.com (mail-qk1-f202.google.com [209.85.222.202]) by imf01.hostedemail.com (Postfix) with ESMTP id 43E792000380 for ; Fri, 12 Mar 2021 14:24:39 +0000 (UTC) Received: by mail-qk1-f202.google.com with SMTP id h134so18300000qke.1 for ; Fri, 12 Mar 2021 06:24:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=iXUBccT1s/Tpz0xpM0wAfa/pMQuz7eoXMXGou1E4nY8=; b=nXGX3uu1DMoAwGMzh6ZF3gsPGgxXAloDpF10xlKbClV0eN/txB0mPw/MO61bESnYPT O3eBA7dXz9prhNZzsetEN2ZQGjvCLoYEu4JFwYiPAUgLsDKEBLDW2HdeogZB6H/8/jlC +3rUnQnIi+sVzOY9L9AgXOxd+I4xNMIVZQBArHnJJ5BHjT0kCarwVSpWrf6sMPAFZZK7 xGujlM8ClMOuEZjK+cJTGGDUDXenoZphVsSac6CId3FGYGrd5nJ4tigA11sKhYU9AU2d KMVNImLe8WH9EM0IZY/K0PYPUudSmeB5CgLTOW6vKnZTsxsEoF6tx37zkTQ1wF7ebK3f MRbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=iXUBccT1s/Tpz0xpM0wAfa/pMQuz7eoXMXGou1E4nY8=; b=mpCCm4ZrLlWf2lIrgNaG2PGscIRj4WmV1PW9CJfcQ3NebLb9gj/7Vk2Jw0KPuaum2a lBTVdqymM5+gzlsgAeO+HeH6nTQiZ1sMe+dk7OL12MVmjNf9l9J/q2yZnl4+m3wmQ/89 KcfuLMtcMaiHnL16Z/7ZmVKZ1NRrYDhA98sIk6SOPpoufV4TsSgOylgAPCLjwHLOb7SR APApRyI1J15ASRJhMWkYWn4+MnIFdtj/HZNuR4q4iJx/ZwfTJCB3N19T+wkkIQp/CrFy K5YTsbO40UtV7wbwhumO12MgeA4jfVPTCjT3IVESsRIJFtZf+orq65x81oZIAMd5w/4g ZqYw== X-Gm-Message-State: AOAM530++GoQbGYCYtV4vb7/ihl1AvAjZ8GEad8giHVaWVdxb1pBTx49 kvvedBOEuW5XK/Inhwnf0dLNkLIin9IisTEV X-Google-Smtp-Source: ABdhPJz9mDUjTU99hjsECwi+EVDjFSiRUu2Cbxnw2RJk16AhnoByPHfMDcrVC6QGLFbIw0tfj/qLuVL6uKemhBfp X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:95a:d8a8:4925:42be]) (user=andreyknvl job=sendgmr) by 2002:a0c:8f1a:: with SMTP id z26mr11991825qvd.51.1615559078072; Fri, 12 Mar 2021 06:24:38 -0800 (PST) Date: Fri, 12 Mar 2021 15:24:24 +0100 Message-Id: Mime-Version: 1.0 X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog Subject: [PATCH v2 01/11] kasan: docs: clean up sections From: Andrey Konovalov To: Andrew Morton , Alexander Potapenko , Marco Elver Cc: Andrey Ryabinin , Dmitry Vyukov , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Stat-Signature: rxddye39oo67snjf6a1nk7e8ie1ehuuz X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 43E792000380 Received-SPF: none (flex--andreyknvl.bounces.google.com>: No applicable sender policy available) receiver=imf01; identity=mailfrom; envelope-from="<3pnlLYAoKCM8v8yCzJ58G619916z.x97638FI-775Gvx5.9C1@flex--andreyknvl.bounces.google.com>"; helo=mail-qk1-f202.google.com; client-ip=209.85.222.202 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615559079-454937 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: Update KASAN documentation: - Give some sections clearer names. - Remove unneeded subsections in the "Tests" section. - Move the "For developers" section and split into subsections. Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver --- Changes v1->v2: - Rename "By default" section to "Default behaviour". --- Documentation/dev-tools/kasan.rst | 54 +++++++++++++++---------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/Documentation/dev-tools/kasan.rst b/Documentation/dev-tools/kasan.rst index ddf4239a5890..b3b2c517db55 100644 --- a/Documentation/dev-tools/kasan.rst +++ b/Documentation/dev-tools/kasan.rst @@ -168,24 +168,6 @@ particular KASAN features. report or also panic the kernel (default: ``report``). Note, that tag checking gets disabled after the first reported bug. -For developers -~~~~~~~~~~~~~~ - -Software KASAN modes use compiler instrumentation to insert validity checks. -Such instrumentation might be incompatible with some part of the kernel, and -therefore needs to be disabled. To disable instrumentation for specific files -or directories, add a line similar to the following to the respective kernel -Makefile: - -- For a single file (e.g. main.o):: - - KASAN_SANITIZE_main.o := n - -- For all files in one directory:: - - KASAN_SANITIZE := n - - Implementation details ---------------------- @@ -299,8 +281,8 @@ support MTE (but supports TBI). Hardware tag-based KASAN only reports the first found bug. After that MTE tag checking gets disabled. -What memory accesses are sanitised by KASAN? --------------------------------------------- +Shadow memory +------------- The kernel maps memory in a number of different parts of the address space. This poses something of a problem for KASAN, which requires @@ -311,8 +293,8 @@ The range of kernel virtual addresses is large: there is not enough real memory to support a real shadow region for every address that could be accessed by the kernel. -By default -~~~~~~~~~~ +Default behaviour +~~~~~~~~~~~~~~~~~ By default, architectures only map real memory over the shadow region for the linear mapping (and potentially other small areas). For all @@ -362,8 +344,29 @@ unmapped. This will require changes in arch-specific code. This allows ``VMAP_STACK`` support on x86, and can simplify support of architectures that do not have a fixed module region. -CONFIG_KASAN_KUNIT_TEST and CONFIG_KASAN_MODULE_TEST ----------------------------------------------------- +For developers +-------------- + +Ignoring accesses +~~~~~~~~~~~~~~~~~ + +Software KASAN modes use compiler instrumentation to insert validity checks. +Such instrumentation might be incompatible with some part of the kernel, and +therefore needs to be disabled. To disable instrumentation for specific files +or directories, add a line similar to the following to the respective kernel +Makefile: + +- For a single file (e.g. main.o):: + + KASAN_SANITIZE_main.o := n + +- For all files in one directory:: + + KASAN_SANITIZE := n + + +Tests +~~~~~ KASAN tests consist of two parts: @@ -409,21 +412,18 @@ Or, if one of the tests failed:: There are a few ways to run KUnit-compatible KASAN tests. 1. Loadable module -~~~~~~~~~~~~~~~~~~ With ``CONFIG_KUNIT`` enabled, ``CONFIG_KASAN_KUNIT_TEST`` can be built as a loadable module and run on any architecture that supports KASAN by loading the module with insmod or modprobe. The module is called ``test_kasan``. 2. Built-In -~~~~~~~~~~~ With ``CONFIG_KUNIT`` built-in, ``CONFIG_KASAN_KUNIT_TEST`` can be built-in on any architecure that supports KASAN. These and any other KUnit tests enabled will run and print the results at boot as a late-init call. 3. Using kunit_tool -~~~~~~~~~~~~~~~~~~~ With ``CONFIG_KUNIT`` and ``CONFIG_KASAN_KUNIT_TEST`` built-in, it's also possible use ``kunit_tool`` to see the results of these and other KUnit tests From patchwork Fri Mar 12 14:24:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12134787 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=-26.3 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, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL 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 D6A49C433DB for ; Fri, 12 Mar 2021 14:24:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6334A64FB2 for ; Fri, 12 Mar 2021 14:24:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6334A64FB2 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 077EE8D035C; Fri, 12 Mar 2021 09:24:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 04E9E8D0346; Fri, 12 Mar 2021 09:24:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E301C8D035C; Fri, 12 Mar 2021 09:24:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0237.hostedemail.com [216.40.44.237]) by kanga.kvack.org (Postfix) with ESMTP id CA6C18D0346 for ; Fri, 12 Mar 2021 09:24:42 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 897A1181CBDCE for ; Fri, 12 Mar 2021 14:24:42 +0000 (UTC) X-FDA: 77911443204.14.151B345 Received: from mail-ej1-f73.google.com (mail-ej1-f73.google.com [209.85.218.73]) by imf08.hostedemail.com (Postfix) with ESMTP id CF2378019153 for ; Fri, 12 Mar 2021 14:24:33 +0000 (UTC) Received: by mail-ej1-f73.google.com with SMTP id t21so2211813ejf.14 for ; Fri, 12 Mar 2021 06:24:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=YmrfZsjCUnsbI/dxLimuvoNopBZleUT55sQpN4+LAO4=; b=j/FaqdN61zL6WvpcKOGOU2tM9vngAJHnvFQAG9snOCBc7cjO4jQA4laHGxNPE3iol7 bTvUQd9R4paQnOS0/atIt5fTkAnxkGcZasXLem38BWaBtqHdLhpa1rd+rSx+RaSpW7tN M72oqJz0uX8j54HywoEZ70+yXJavAEboopaFmB8Z2A92JySJCH5xEqOay87JMUkyK37q erxXZWqAntLuDrpnqt4kiGbh71iP4qJjfpkORzXPvCeODseooVn6Qe6rBeUicTzcZyID 2TvJc/8mEXO9WXK1Fcg15bqM8m3gGLQ4LW1ASek4Pcc8JAwE6/h92cXjTVzPLsq/lmst vFxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=YmrfZsjCUnsbI/dxLimuvoNopBZleUT55sQpN4+LAO4=; b=NStJW1uXZWe+6FXhcs5zGjhMBmUq25TrOMwfS9huMoHAUHH66wtHPxNEO59FzASZfy OIB6tTwPAE7VhfDSFd1lVU68keZEMVjuCCTBbWdmJUQlfHDqvmoLWGoD/TbSh6YDGvhR BONCXvp9GFD7iDBmEJIr+dRegvhK9w+UsWhuOuiBkATtqabHaCUvuXupLPHAE4tBvDyM m7yiNk8jkGhDT8Y8hrqTpRjk/y5AQg9dewirfsH+jMwQvRpDeR0nWV4q8+cnZfcSRmR/ RBS72pHg68Yh91dhdgKrLbP1l6z7LuxuzFjP2i3xfXx+XwV4ByM4oP0KAagj+dHLPwqJ MICw== X-Gm-Message-State: AOAM531jgvk+V9KGNyj/rP8lRgbv/C+2MqvQZvsnMeyCpNmw6FY3aUak TSvcDv3vixWPDF1LT5LvDoS6huYnKdW9bBpF X-Google-Smtp-Source: ABdhPJxp7kOe5CQTLKqSu61Pmt1p/02N6FRencBxyisW0zbM9w4CjKAGwVOwb28H7CndKCl0Pj/9qXZbp1GrMyxc X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:95a:d8a8:4925:42be]) (user=andreyknvl job=sendgmr) by 2002:a17:906:a049:: with SMTP id bg9mr8819448ejb.186.1615559080372; Fri, 12 Mar 2021 06:24:40 -0800 (PST) Date: Fri, 12 Mar 2021 15:24:25 +0100 In-Reply-To: Message-Id: <1486fba8514de3d7db2f47df2192db59228b0a7b.1615559068.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog Subject: [PATCH v2 02/11] kasan: docs: update overview section From: Andrey Konovalov To: Andrew Morton , Alexander Potapenko , Marco Elver Cc: Andrey Ryabinin , Dmitry Vyukov , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Stat-Signature: qhmidydnefsk6j4bzkby59rxfg7qjw7r X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: CF2378019153 Received-SPF: none (flex--andreyknvl.bounces.google.com>: No applicable sender policy available) receiver=imf08; identity=mailfrom; envelope-from="<3qHlLYAoKCNExA0E1L7AI83BB381.zB985AHK-997Ixz7.BE3@flex--andreyknvl.bounces.google.com>"; helo=mail-ej1-f73.google.com; client-ip=209.85.218.73 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615559073-957852 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: Update the "Overview" section in KASAN documentation: - Outline main use cases for each mode. - Mention that HW_TAGS mode need compiler support too. - Move the part about SLUB/SLAB support from "Usage" to "Overview". - Punctuation, readability, and other minor clean-ups. Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver --- Changes v1->v2: - Mention GCC support for HW_TAGS. --- Documentation/dev-tools/kasan.rst | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/Documentation/dev-tools/kasan.rst b/Documentation/dev-tools/kasan.rst index b3b2c517db55..2f2697b290d5 100644 --- a/Documentation/dev-tools/kasan.rst +++ b/Documentation/dev-tools/kasan.rst @@ -11,17 +11,31 @@ designed to find out-of-bound and use-after-free bugs. KASAN has three modes: 2. software tag-based KASAN (similar to userspace HWASan), 3. hardware tag-based KASAN (based on hardware memory tagging). -Software KASAN modes (1 and 2) use compile-time instrumentation to insert -validity checks before every memory access, and therefore require a compiler +Generic KASAN is mainly used for debugging due to a large memory overhead. +Software tag-based KASAN can be used for dogfood testing as it has a lower +memory overhead that allows using it with real workloads. Hardware tag-based +KASAN comes with low memory and performance overheads and, therefore, can be +used in production. Either as an in-field memory bug detector or as a security +mitigation. + +Software KASAN modes (#1 and #2) use compile-time instrumentation to insert +validity checks before every memory access and, therefore, require a compiler version that supports that. -Generic KASAN is supported in both GCC and Clang. With GCC it requires version +Generic KASAN is supported in GCC and Clang. With GCC, it requires version 8.3.0 or later. Any supported Clang version is compatible, but detection of out-of-bounds accesses for global variables is only supported since Clang 11. -Tag-based KASAN is only supported in Clang. +Software tag-based KASAN mode is only supported in Clang. -Currently generic KASAN is supported for the x86_64, arm, arm64, xtensa, s390 +The hardware KASAN mode (#3) relies on hardware to perform the checks but +still requires a compiler version that supports memory tagging instructions. +This mode is supported in GCC 10+ and Clang 11+. + +Both software KASAN modes work with SLUB and SLAB memory allocators, +while the hardware tag-based KASAN currently only supports SLUB. + +Currently, generic KASAN is supported for the x86_64, arm, arm64, xtensa, s390, and riscv architectures, and tag-based KASAN modes are supported only for arm64. Usage @@ -39,9 +53,6 @@ For software modes, you also need to choose between CONFIG_KASAN_OUTLINE and CONFIG_KASAN_INLINE. Outline and inline are compiler instrumentation types. The former produces smaller binary while the latter is 1.1 - 2 times faster. -Both software KASAN modes work with both SLUB and SLAB memory allocators, -while the hardware tag-based KASAN currently only support SLUB. - For better error reports that include stack traces, enable CONFIG_STACKTRACE. To augment reports with last allocation and freeing stack of the physical page, From patchwork Fri Mar 12 14:24:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12134789 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=-26.3 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, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL 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 339E4C433E0 for ; Fri, 12 Mar 2021 14:24:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CE9E864FC3 for ; Fri, 12 Mar 2021 14:24:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CE9E864FC3 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 708118D035D; Fri, 12 Mar 2021 09:24:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6E2AA8D0346; Fri, 12 Mar 2021 09:24:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4E2848D035D; Fri, 12 Mar 2021 09:24:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0227.hostedemail.com [216.40.44.227]) by kanga.kvack.org (Postfix) with ESMTP id 2D6A08D0346 for ; Fri, 12 Mar 2021 09:24:44 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id D16D083F8 for ; Fri, 12 Mar 2021 14:24:43 +0000 (UTC) X-FDA: 77911443246.07.EFBE5A3 Received: from mail-qv1-f74.google.com (mail-qv1-f74.google.com [209.85.219.74]) by imf25.hostedemail.com (Postfix) with ESMTP id 8C1596000111 for ; Fri, 12 Mar 2021 14:24:41 +0000 (UTC) Received: by mail-qv1-f74.google.com with SMTP id i1so17662848qvu.12 for ; Fri, 12 Mar 2021 06:24:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=UIn9R6iWNTpuninm8yzAqfvqLsQ1Z3TszvORzjzD33U=; b=BfEhzme8NfucFms3TKi7BojlgEWJYM76BAeBCWDV2onmk63nYw8AWfe/XU1X7ifiQ7 5uRMoXe9Ikc/W7RI035b0qscpd8roWNpxeMSEllp4YO1FTC2sFGr0BNbtY3+TufVBmt/ URK7CrQbV13rwXPEi+EwDf+xXnFlQJ0hVrt51LE+sMH9dZK/nUoXS+mbn2uf68Km+Yoo HU/UnO6E+lqMkw2TTcN1WKvT7fpLpVUGpg+S1m6SkcMuU3agedBTSxKNxBQIWlL4VTBi m8230PNbLFrfbIk4DV3yRw4fPuYGAAuXZbdB09lBg8+JNxKYV75kfWkwLZyOu24KMBIj n+Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=UIn9R6iWNTpuninm8yzAqfvqLsQ1Z3TszvORzjzD33U=; b=pjH/JWB58LIztrEPIO/IyV4clEho/RVWTwfw/w36vi4PGe9GvwFYOML/b/cmKy7NDB odSqRtQEBMXUzb4p0olhEiS7xRNkAH0fnyERsZz5e0niZefbrQpvO42A3LyMhs0MD7uu jwddTsKvwK6uG4yW5WVfhl7kvgPp7NUh63/qW5SQYVohskXyHrrYWFhocm0/4PdmFdRZ sE+D7pCq4MZlqgY3oNPN4Z7IN5F4jsE0Y8ZyBzSiCDYt7YlOC1H/O8VjoJFU1C8O3o3l 0Gs61S4T1sBVVaecY98r/4lCvX8Q6c/x7NxZP+CJXURNuPk33pIGLXlmZdMsJsjyE8Uh 9wbg== X-Gm-Message-State: AOAM533fuP4S50hwk7N9H8tenA19sd/cBuRy/RShUaDE/sP46XgnYUq9 Nk6IUxzNZUrvZ8yat0TGK5e9LyqCoqURpWZC X-Google-Smtp-Source: ABdhPJxhhQrSrGA1QsOqnoYKLh4lvDwtbCsjqjKI4lZ1uccEccLCH1TKhzag8wYYWyL8wB6MDNjfjq9i8g2TZq7N X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:95a:d8a8:4925:42be]) (user=andreyknvl job=sendgmr) by 2002:a0c:aa45:: with SMTP id e5mr1897790qvb.44.1615559082706; Fri, 12 Mar 2021 06:24:42 -0800 (PST) Date: Fri, 12 Mar 2021 15:24:26 +0100 In-Reply-To: Message-Id: <48427809cd4b8b5d6bc00926cbe87e2b5081df17.1615559068.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog Subject: [PATCH v2 03/11] kasan: docs: update usage section From: Andrey Konovalov To: Andrew Morton , Alexander Potapenko , Marco Elver Cc: Andrey Ryabinin , Dmitry Vyukov , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 8C1596000111 X-Stat-Signature: fygd6dcti6mh3qtqo8um6k48drcbiyio Received-SPF: none (flex--andreyknvl.bounces.google.com>: No applicable sender policy available) receiver=imf25; identity=mailfrom; envelope-from="<3qnlLYAoKCNMzC2G3N9CKA5DD5A3.1DBA7CJM-BB9Kz19.DG5@flex--andreyknvl.bounces.google.com>"; helo=mail-qv1-f74.google.com; client-ip=209.85.219.74 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615559081-566667 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: Update the "Usage" section in KASAN documentation: - Add inline code snippet markers. - Reword the part about stack traces for clarity. - Other minor clean-ups. Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver --- Documentation/dev-tools/kasan.rst | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Documentation/dev-tools/kasan.rst b/Documentation/dev-tools/kasan.rst index 2f2697b290d5..46f4e9680805 100644 --- a/Documentation/dev-tools/kasan.rst +++ b/Documentation/dev-tools/kasan.rst @@ -41,22 +41,21 @@ and riscv architectures, and tag-based KASAN modes are supported only for arm64. Usage ----- -To enable KASAN configure kernel with:: +To enable KASAN, configure the kernel with:: - CONFIG_KASAN = y + CONFIG_KASAN=y -and choose between CONFIG_KASAN_GENERIC (to enable generic KASAN), -CONFIG_KASAN_SW_TAGS (to enable software tag-based KASAN), and -CONFIG_KASAN_HW_TAGS (to enable hardware tag-based KASAN). +and choose between ``CONFIG_KASAN_GENERIC`` (to enable generic KASAN), +``CONFIG_KASAN_SW_TAGS`` (to enable software tag-based KASAN), and +``CONFIG_KASAN_HW_TAGS`` (to enable hardware tag-based KASAN). -For software modes, you also need to choose between CONFIG_KASAN_OUTLINE and -CONFIG_KASAN_INLINE. Outline and inline are compiler instrumentation types. -The former produces smaller binary while the latter is 1.1 - 2 times faster. +For software modes, also choose between ``CONFIG_KASAN_OUTLINE`` and +``CONFIG_KASAN_INLINE``. Outline and inline are compiler instrumentation types. +The former produces a smaller binary while the latter is 1.1-2 times faster. -For better error reports that include stack traces, enable CONFIG_STACKTRACE. - -To augment reports with last allocation and freeing stack of the physical page, -it is recommended to enable also CONFIG_PAGE_OWNER and boot with page_owner=on. +To include alloc and free stack traces of affected slab objects into reports, +enable ``CONFIG_STACKTRACE``. To include alloc and free stack traces of affected +physical pages, enable ``CONFIG_PAGE_OWNER`` and boot with ``page_owner=on``. Error reports ~~~~~~~~~~~~~ From patchwork Fri Mar 12 14:24:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12134791 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=-26.3 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, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL 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 DC08AC433E0 for ; Fri, 12 Mar 2021 14:24:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8B07364FC3 for ; Fri, 12 Mar 2021 14:24:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8B07364FC3 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 2C1418D035F; Fri, 12 Mar 2021 09:24:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 27FD28D035E; Fri, 12 Mar 2021 09:24:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 137B78D035E; Fri, 12 Mar 2021 09:24:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0213.hostedemail.com [216.40.44.213]) by kanga.kvack.org (Postfix) with ESMTP id E78CB8D0346 for ; Fri, 12 Mar 2021 09:24:48 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 0088381CC for ; Fri, 12 Mar 2021 14:24:47 +0000 (UTC) X-FDA: 77911443456.18.BF8D3CD Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf17.hostedemail.com (Postfix) with ESMTP id B7D3F40001DE for ; Fri, 12 Mar 2021 14:24:45 +0000 (UTC) Received: by mail-wm1-f74.google.com with SMTP id m17so2103867wml.3 for ; Fri, 12 Mar 2021 06:24:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=0tHYzYXuuuKT6r1BbOh9jnZkvIRx4Zusj9wo+yaKFLc=; b=sNp2DgDmylfnS/Ht/6f++D6EQH9D86XWw0M6iwarW68/F2DW3jJ2h1ksTDPv3+/C87 pHHYdYTwSOZDZjMyEBULBU3suACHGMtTYH+xUFvBQeSNvTX9u3GDd7/iCHmjVjv2oVGP d9ID8wr2BDrtrTAySXF+Y+WnlUlluKg7uZ6kVckHBZmDAAjE7wjwmqulaTSlQTXX7Qnn 2wZltVoSlSUohS/adb26/ByRLH5goLNkjBZYV5ddzvTVOlzN9fb1BYBCDYUUxR0a0ynv cxoDzqrQv+n3qwNxzHuWgzmpGozNfTqC8HnfSYaC7PGEqZ4ZPv1lDOUdpNuzcd9cdWvo jIAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=0tHYzYXuuuKT6r1BbOh9jnZkvIRx4Zusj9wo+yaKFLc=; b=KOdlxZau/+W31gvkebkK72HJwJPW0iTOpK+fQx/HprWoCuaHSmKJiWbXdQFQwCE546 KY+z4ZGgy+0AF9wrU8V/vgBoYxj9OZh4LOeSzkcZ/f4nWj2qNu9BFksalMT8moy5pL39 thD1PiXtusmpMclmYS5aYHFzrd68OyLnpWQJZnd7LBqBcr7BJcAnF/TCsjtHNFAPiMIH ZpJkjIxIcr/wOyn6XE3OB16JhBPocichQ+Bj79ITOfxJzDgs4lMf3gIz03IJbTOP4Hqc B3FB6zDguR6NasLdmGUQ6oIS2gp2K5OwPY2sQtwlrYoaQ6u6IZrSPOhSlpCebg0LoKwA 87Kw== X-Gm-Message-State: AOAM530TeJyKgUkTe9/deUuUyGq8jzS2d98UxcFY3vviQVl6IPb9Ou/d p5Jcc6Y0Sh+03ZgRLRIl1hlKbKu80iHuUXiF X-Google-Smtp-Source: ABdhPJwdQSHPjvRDAQY5lwOlRkmuLODK/9QSFnR3qAqJKcfl49OirF7C7hzxiTfnjTq8ZyWFvU3BH/BT9cVzEaqw X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:95a:d8a8:4925:42be]) (user=andreyknvl job=sendgmr) by 2002:a1c:4145:: with SMTP id o66mr8525472wma.68.1615559085218; Fri, 12 Mar 2021 06:24:45 -0800 (PST) Date: Fri, 12 Mar 2021 15:24:27 +0100 In-Reply-To: Message-Id: <3531e8fe6972cf39d1954e3643237b19eb21227e.1615559068.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog Subject: [PATCH v2 04/11] kasan: docs: update error reports section From: Andrey Konovalov To: Andrew Morton , Alexander Potapenko , Marco Elver Cc: Andrey Ryabinin , Dmitry Vyukov , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Stat-Signature: y3ix4akfhuq351aaxw77c5iercqhuodq X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: B7D3F40001DE Received-SPF: none (flex--andreyknvl.bounces.google.com>: No applicable sender policy available) receiver=imf17; identity=mailfrom; envelope-from="<3rXlLYAoKCNY2F5J6QCFND8GG8D6.4GEDAFMP-EECN24C.GJ8@flex--andreyknvl.bounces.google.com>"; helo=mail-wm1-f74.google.com; client-ip=209.85.128.74 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615559085-766346 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: Update the "Error reports" section in KASAN documentation: - Mention that bug titles are best-effort. - Move and reword the part about auxiliary stacks from "Implementation details". - Punctuation, readability, and other minor clean-ups. Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver --- Documentation/dev-tools/kasan.rst | 46 +++++++++++++++++-------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/Documentation/dev-tools/kasan.rst b/Documentation/dev-tools/kasan.rst index 46f4e9680805..cd12c890b888 100644 --- a/Documentation/dev-tools/kasan.rst +++ b/Documentation/dev-tools/kasan.rst @@ -60,7 +60,7 @@ physical pages, enable ``CONFIG_PAGE_OWNER`` and boot with ``page_owner=on``. Error reports ~~~~~~~~~~~~~ -A typical out-of-bounds access generic KASAN report looks like this:: +A typical KASAN report looks like this:: ================================================================== BUG: KASAN: slab-out-of-bounds in kmalloc_oob_right+0xa8/0xbc [test_kasan] @@ -133,33 +133,43 @@ A typical out-of-bounds access generic KASAN report looks like this:: ffff8801f44ec400: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc ================================================================== -The header of the report provides a short summary of what kind of bug happened -and what kind of access caused it. It's followed by a stack trace of the bad -access, a stack trace of where the accessed memory was allocated (in case bad -access happens on a slab object), and a stack trace of where the object was -freed (in case of a use-after-free bug report). Next comes a description of -the accessed slab object and information about the accessed memory page. +The report header summarizes what kind of bug happened and what kind of access +caused it. It is followed by a stack trace of the bad access, a stack trace of +where the accessed memory was allocated (in case a slab object was accessed), +and a stack trace of where the object was freed (in case of a use-after-free +bug report). Next comes a description of the accessed slab object and the +information about the accessed memory page. -In the last section the report shows memory state around the accessed address. -Internally KASAN tracks memory state separately for each memory granule, which +In the end, the report shows the memory state around the accessed address. +Internally, KASAN tracks memory state separately for each memory granule, which is either 8 or 16 aligned bytes depending on KASAN mode. Each number in the memory state section of the report shows the state of one of the memory granules that surround the accessed address. -For generic KASAN the size of each memory granule is 8. The state of each +For generic KASAN, the size of each memory granule is 8. The state of each granule is encoded in one shadow byte. Those 8 bytes can be accessible, -partially accessible, freed or be a part of a redzone. KASAN uses the following -encoding for each shadow byte: 0 means that all 8 bytes of the corresponding +partially accessible, freed, or be a part of a redzone. KASAN uses the following +encoding for each shadow byte: 00 means that all 8 bytes of the corresponding memory region are accessible; number N (1 <= N <= 7) means that the first N bytes are accessible, and other (8 - N) bytes are not; any negative value indicates that the entire 8-byte word is inaccessible. KASAN uses different negative values to distinguish between different kinds of inaccessible memory like redzones or freed memory (see mm/kasan/kasan.h). -In the report above the arrows point to the shadow byte 03, which means that -the accessed address is partially accessible. For tag-based KASAN modes this -last report section shows the memory tags around the accessed address -(see the `Implementation details`_ section). +In the report above, the arrow points to the shadow byte ``03``, which means +that the accessed address is partially accessible. + +For tag-based KASAN modes, this last report section shows the memory tags around +the accessed address (see the `Implementation details`_ section). + +Note that KASAN bug titles (like ``slab-out-of-bounds`` or ``use-after-free``) +are best-effort: KASAN prints the most probable bug type based on the limited +information it has. The actual type of the bug might be different. + +Generic KASAN also reports up to two auxiliary call stack traces. These stack +traces point to places in code that interacted with the object but that are not +directly present in the bad access stack trace. Currently, this includes +call_rcu() and workqueue queuing. Boot parameters ~~~~~~~~~~~~~~~ @@ -214,10 +224,6 @@ function calls GCC directly inserts the code to check the shadow memory. This option significantly enlarges kernel but it gives x1.1-x2 performance boost over outline instrumented kernel. -Generic KASAN also reports the last 2 call stacks to creation of work that -potentially has access to an object. Call stacks for the following are shown: -call_rcu() and workqueue queuing. - Generic KASAN is the only mode that delays the reuse of freed object via quarantine (see mm/kasan/quarantine.c for implementation). From patchwork Fri Mar 12 14:24:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12134793 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=-26.3 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, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL 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 66C70C433E6 for ; Fri, 12 Mar 2021 14:24:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 02A7B64FAD for ; Fri, 12 Mar 2021 14:24:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 02A7B64FAD 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 5F6558D035E; Fri, 12 Mar 2021 09:24:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5CBF68D0346; Fri, 12 Mar 2021 09:24:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 382C08D0360; Fri, 12 Mar 2021 09:24:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0116.hostedemail.com [216.40.44.116]) by kanga.kvack.org (Postfix) with ESMTP id 1E85E8D0346 for ; Fri, 12 Mar 2021 09:24:49 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id A61318784 for ; Fri, 12 Mar 2021 14:24:48 +0000 (UTC) X-FDA: 77911443456.07.CF1E34E Received: from mail-qv1-f73.google.com (mail-qv1-f73.google.com [209.85.219.73]) by imf28.hostedemail.com (Postfix) with ESMTP id 83F2420003A1 for ; Fri, 12 Mar 2021 14:24:49 +0000 (UTC) Received: by mail-qv1-f73.google.com with SMTP id i1so17662999qvu.12 for ; Fri, 12 Mar 2021 06:24:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=JZTsOk7rsE4y13QJJB2MKSWKMrX5Hi5qHr1bAz5AyQ0=; b=hTQLmWZFaN/2EBaaI1leaS+J+FqsNZbjnWkVy379obcmHmGy4TQ2Qbw+Y7mvRXWIOi aFMAit90SAHGfQvCfuLLb1QQIkmF2K3wiDzHPkHBtIgwtWRMrjV8BpwlSXV5K+R9LF7Y JqlKASAtwLSGMb1Xf+nxvRmQbuukKW23nwcI6FsgqoPDYyeGMj0l2+9+3OESihxuNoRV hGV0SpTMfQTwvi9S3K1Q+splEsfmPHDbYJouBLP6t1DXCggHaXMnKHuO6dh7/h7H08Gg jjlRbOXFzrTqOunGygqBtdhDs9ZbTwGVikayQ6Wx6EIDDOssRaphq6B5Z4yZv2bNLeI1 IKFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=JZTsOk7rsE4y13QJJB2MKSWKMrX5Hi5qHr1bAz5AyQ0=; b=fqUQfugz1E+W2R9AMaFTftiC/QBk5FstABnqzZEa0pDYtYexIAOQMJKC0IUF6S+TIj HamByjGBx7ArdWYZ4IGDtiZNjt6jnpbZm24IYAXDAY9JyPAWV7S6/PAGa7ynIDBDGZr5 YRoGInSDXacZhVvNKnOQUWGLo4j918ZZvBdQ5yGP2QrclRKo3nf0MFJhxXX+ET4T3/te tn5MGWLgPlPTG92SSGezBx1rQBkAg5/x7vWYO72fcnZGzeOSvK7ScWPpLN1nxK4JEILl c501qUYNe/gdFpX8r1thiLLLS5Ue4iONHvLTKRJcn+AEWHWv7YpE7d7VmKT7h2xD7HNq Y1Tg== X-Gm-Message-State: AOAM532zBmkbUkgx0YQJZKDoHNEerrcKoWCKmH5Yf3FofFs3nP/OFapA BGNNmOpvbbcdWmyX9pppYrDA7j2uRKOM75Zk X-Google-Smtp-Source: ABdhPJx1bwhGX9ABp6J/tmttc6zDPEbbnnDx7Uu8xLNlXSBuRHDH9zhu1klIP97uHVF7sDyQHYaVpjPHUSBTP3uw X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:95a:d8a8:4925:42be]) (user=andreyknvl job=sendgmr) by 2002:ad4:51c1:: with SMTP id p1mr12931323qvq.39.1615559087508; Fri, 12 Mar 2021 06:24:47 -0800 (PST) Date: Fri, 12 Mar 2021 15:24:28 +0100 In-Reply-To: Message-Id: <01364952f15789948f0627d6733b5cdf5209f83a.1615559068.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog Subject: [PATCH v2 05/11] kasan: docs: update boot parameters section From: Andrey Konovalov To: Andrew Morton , Alexander Potapenko , Marco Elver Cc: Andrey Ryabinin , Dmitry Vyukov , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 83F2420003A1 X-Stat-Signature: phih35bpxbf6qfmgp3r888dxxs94iew3 Received-SPF: none (flex--andreyknvl.bounces.google.com>: No applicable sender policy available) receiver=imf28; identity=mailfrom; envelope-from="<3r3lLYAoKCNg4H7L8SEHPFAIIAF8.6IGFCHOR-GGEP46E.ILA@flex--andreyknvl.bounces.google.com>"; helo=mail-qv1-f73.google.com; client-ip=209.85.219.73 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615559089-571815 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: Update the "Boot parameters" section in KASAN documentation: - Mention panic_on_warn. - Mention kasan_multi_shot and its interaction with panic_on_warn. - Clarify kasan.fault=panic interaction with panic_on_warn. - A readability clean-up. Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver --- Documentation/dev-tools/kasan.rst | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Documentation/dev-tools/kasan.rst b/Documentation/dev-tools/kasan.rst index cd12c890b888..1189be9b4cb5 100644 --- a/Documentation/dev-tools/kasan.rst +++ b/Documentation/dev-tools/kasan.rst @@ -174,10 +174,16 @@ call_rcu() and workqueue queuing. Boot parameters ~~~~~~~~~~~~~~~ +KASAN is affected by the generic ``panic_on_warn`` command line parameter. +When it is enabled, KASAN panics the kernel after printing a bug report. + +By default, KASAN prints a bug report only for the first invalid memory access. +With ``kasan_multi_shot``, KASAN prints a report on every invalid access. This +effectively disables ``panic_on_warn`` for KASAN reports. + Hardware tag-based KASAN mode (see the section about various modes below) is intended for use in production as a security mitigation. Therefore, it supports -boot parameters that allow to disable KASAN competely or otherwise control -particular KASAN features. +boot parameters that allow disabling KASAN or controlling its features. - ``kasan=off`` or ``=on`` controls whether KASAN is enabled (default: ``on``). @@ -185,8 +191,8 @@ particular KASAN features. traces collection (default: ``on``). - ``kasan.fault=report`` or ``=panic`` controls whether to only print a KASAN - report or also panic the kernel (default: ``report``). Note, that tag - checking gets disabled after the first reported bug. + report or also panic the kernel (default: ``report``). The panic happens even + if ``kasan_multi_shot`` is enabled. Implementation details ---------------------- From patchwork Fri Mar 12 14:24:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12134799 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=-26.3 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, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL 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 C5BAAC433E6 for ; Fri, 12 Mar 2021 14:24:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 783A164FAD for ; Fri, 12 Mar 2021 14:24:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 783A164FAD 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 5F6008D0360; Fri, 12 Mar 2021 09:24:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5CDCD8D0361; Fri, 12 Mar 2021 09:24:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 46BFE8D0360; Fri, 12 Mar 2021 09:24:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0096.hostedemail.com [216.40.44.96]) by kanga.kvack.org (Postfix) with ESMTP id 126AD8D0361 for ; Fri, 12 Mar 2021 09:24:57 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id C32648248047 for ; Fri, 12 Mar 2021 14:24:56 +0000 (UTC) X-FDA: 77911443792.07.C4C968F Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf17.hostedemail.com (Postfix) with ESMTP id 877C1407F8DB for ; Fri, 12 Mar 2021 14:24:50 +0000 (UTC) Received: by mail-wm1-f74.google.com with SMTP id r18so5393320wmq.5 for ; Fri, 12 Mar 2021 06:24:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Ma9yDdtcKZ7wj/wPd+7FYcq2cw0HWN/l0auDvo6fPoI=; b=JVujzVqwjIYG5j1fOwr25Xh074MUoX63HHSyCm4wfG799oatexCqqAEE2xXAea9aKV Sjra9aPL3ppOOBgD48RZymsvzU9nFwGbIzQLilkW1cfVorxpDqi0v7/8Odj/B6raoZCe Scw/ef0F/cvt2H5lL+6GV463RBcGceF6rjhHt7rF54QQGq0Kk7/drKuZW58sz4h9DO7S V0enC41jV+KCMwRg7y1Sp9HhExnZsVSWQgstR99ieSIHLgg3+KoyRngQTkQNfet5LrtD WzrSev9UUXZRVjf4Xsf4sh0x01A29B6HUcXQD6dui2WloqW/laJ5aDsrP3yYaH8LJMmH UnsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Ma9yDdtcKZ7wj/wPd+7FYcq2cw0HWN/l0auDvo6fPoI=; b=HauAWa1MGwW7paftaHqr8rD0EUSc8ypsQct2LvbgSxMPPqeQ2KXr7kvoJXvMfWiHzN izPuBWZx4eFG45JBxjN4xY+lUOyyoKDbfSe5OipfD4f0Mm7ZYYFT5A54PdEiRO24Rw4X 5WW724H/vyhnCEvON86CPaAfzechLYAx1ei9HFFHT9t1EjzOzhuHNJNZLVoG/D/N0pc5 wZiO13+GwgG2eAy5/v5y8LY3S1z1SLJv54SqgtaT3izV+nHAP44cgaOQzNWrNtB5YJdP 1DomrjHnHeEvaOikQ9GUvRJrJsIp8pyHUtCPCWX290mgDMnV4HYJR/yevB65Z38mIvRY b29w== X-Gm-Message-State: AOAM532/G6h4ywA2BmQaH3q/iqxY2P+g6a1slJrxctP6/0qf99AMEdl8 h6xhT32M2O5AoClaN+IXmiWKRbIHnyaDszL7 X-Google-Smtp-Source: ABdhPJwaKyRxEHXnKrGDm4FLh1hRB4szO2CA0EyxO4FBmwgHO0zof9NcJRq+qtcFPr9FhhMMmwpZJhu4/UhptLB9 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:95a:d8a8:4925:42be]) (user=andreyknvl job=sendgmr) by 2002:a7b:c18e:: with SMTP id y14mr2248623wmi.1.1615559089958; Fri, 12 Mar 2021 06:24:49 -0800 (PST) Date: Fri, 12 Mar 2021 15:24:29 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog Subject: [PATCH v2 06/11] kasan: docs: update GENERIC implementation details section From: Andrey Konovalov To: Andrew Morton , Alexander Potapenko , Marco Elver Cc: Andrey Ryabinin , Dmitry Vyukov , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Stat-Signature: 77dngb3mq6z6fhkkijufktqjnsmoopyh X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 877C1407F8DB Received-SPF: none (flex--andreyknvl.bounces.google.com>: No applicable sender policy available) receiver=imf17; identity=mailfrom; envelope-from="<3sXlLYAoKCNo6J9NAUGJRHCKKCHA.8KIHEJQT-IIGR68G.KNC@flex--andreyknvl.bounces.google.com>"; helo=mail-wm1-f74.google.com; client-ip=209.85.128.74 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615559090-105795 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: Update the "Implementation details" section for generic KASAN: - Don't mention kmemcheck, it's not present in the kernel anymore. - Don't mention GCC as the only supported compiler. - Update kasan_mem_to_shadow() definition to match actual code. - Punctuation, readability, and other minor clean-ups. Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver --- Documentation/dev-tools/kasan.rst | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/Documentation/dev-tools/kasan.rst b/Documentation/dev-tools/kasan.rst index 1189be9b4cb5..986410bf269f 100644 --- a/Documentation/dev-tools/kasan.rst +++ b/Documentation/dev-tools/kasan.rst @@ -200,12 +200,11 @@ Implementation details Generic KASAN ~~~~~~~~~~~~~ -From a high level perspective, KASAN's approach to memory error detection is -similar to that of kmemcheck: use shadow memory to record whether each byte of -memory is safe to access, and use compile-time instrumentation to insert checks -of shadow memory on each memory access. +Software KASAN modes use shadow memory to record whether each byte of memory is +safe to access and use compile-time instrumentation to insert shadow memory +checks before each memory access. -Generic KASAN dedicates 1/8th of kernel memory to its shadow memory (e.g. 16TB +Generic KASAN dedicates 1/8th of kernel memory to its shadow memory (16TB to cover 128TB on x86_64) and uses direct mapping with a scale and offset to translate a memory address to its corresponding shadow address. @@ -214,23 +213,23 @@ address:: static inline void *kasan_mem_to_shadow(const void *addr) { - return ((unsigned long)addr >> KASAN_SHADOW_SCALE_SHIFT) + return (void *)((unsigned long)addr >> KASAN_SHADOW_SCALE_SHIFT) + KASAN_SHADOW_OFFSET; } where ``KASAN_SHADOW_SCALE_SHIFT = 3``. Compile-time instrumentation is used to insert memory access checks. Compiler -inserts function calls (__asan_load*(addr), __asan_store*(addr)) before each -memory access of size 1, 2, 4, 8 or 16. These functions check whether memory -access is valid or not by checking corresponding shadow memory. +inserts function calls (``__asan_load*(addr)``, ``__asan_store*(addr)``) before +each memory access of size 1, 2, 4, 8, or 16. These functions check whether +memory accesses are valid or not by checking corresponding shadow memory. -GCC 5.0 has possibility to perform inline instrumentation. Instead of making -function calls GCC directly inserts the code to check the shadow memory. -This option significantly enlarges kernel but it gives x1.1-x2 performance -boost over outline instrumented kernel. +With inline instrumentation, instead of making function calls, the compiler +directly inserts the code to check shadow memory. This option significantly +enlarges the kernel, but it gives an x1.1-x2 performance boost over the +outline-instrumented kernel. -Generic KASAN is the only mode that delays the reuse of freed object via +Generic KASAN is the only mode that delays the reuse of freed objects via quarantine (see mm/kasan/quarantine.c for implementation). Software tag-based KASAN From patchwork Fri Mar 12 14:24:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12134795 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=-26.3 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, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL 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 96087C433E0 for ; Fri, 12 Mar 2021 14:24:54 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4790364FB2 for ; Fri, 12 Mar 2021 14:24:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4790364FB2 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 DE4478D0346; Fri, 12 Mar 2021 09:24:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DBBB28D0360; Fri, 12 Mar 2021 09:24:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C8F8A8D0346; Fri, 12 Mar 2021 09:24:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0053.hostedemail.com [216.40.44.53]) by kanga.kvack.org (Postfix) with ESMTP id AE0A08D0346 for ; Fri, 12 Mar 2021 09:24:53 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 6E288181CBC29 for ; Fri, 12 Mar 2021 14:24:53 +0000 (UTC) X-FDA: 77911443666.14.FF3D219 Received: from mail-qv1-f74.google.com (mail-qv1-f74.google.com [209.85.219.74]) by imf17.hostedemail.com (Postfix) with ESMTP id 2A3014080F45 for ; Fri, 12 Mar 2021 14:24:52 +0000 (UTC) Received: by mail-qv1-f74.google.com with SMTP id i1so17663104qvu.12 for ; Fri, 12 Mar 2021 06:24:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=VB+ZOM8lapdi+RHL0OEgOVW/Ip9OH5XFkGtr1r4Q8HI=; b=uWDK3QcUxzcXn0PrMjJgoILZW+lLMhmo2tzHSZsYKl2ch8lC3FXnh/zZ351EHfhY1s P87pKmZ1eifIqPh7Vi7zhmDDqxk9gXvznG8RIWGenKV8k71VCASv3jQjfwfwksjODLpv 5+vKtJOikS1lNVbKK3wAR4tu0Qg0pyjuR/FWVfTUAIi2TiTulnphGS4+vOVNaEKNWpbh Biocc2dbahtqtsgd5kADS2ZCApKGYUMoj5Q53ueOuyXTrlBcwuISU6Np4OlUq1ghLK06 kru5vo0RbxesE3Riq6FEUaklKg/oUV0hb6PdggzkEZbO6+Am/TeaVY55Uu+LHD606kLl AiwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=VB+ZOM8lapdi+RHL0OEgOVW/Ip9OH5XFkGtr1r4Q8HI=; b=Yo2ST3Mo8nYUb9/QZHtgqaeASMYnmlpmClfVAiC28rZjqpX/SX1BtCvtxncQSpzKhE +HwNf/OFk5DAkjBTr7GHE5022w3wdhDyW5AzoEG9lJfXuRrorWnkowBJghse9G4emS0V Z3LEtIdWvG1hNg9pxRMPh6ViN1JkTVf5a1Zh3C0TINrgd8QkAuxbKPbNhpi76MofX3HR kGQa+33PlXd7/VIiEhNxI/lGGCp+eaNQhlYwVDvIYcZJwsjOaELcjkLC5EIY3nU2Z0B1 xbz9aJy6fETDuGFMIPtU2+bZLWYAJsP3pRfmoqz2KqbvUPKb3huKyF9Q0zr34g97Wmji vnow== X-Gm-Message-State: AOAM533+mWPLiFh/fK8Kajj/T2J/2t3bRS0Ugv4s46UssCCJr/MqlN4+ trVVqP3f6xjC51rD0LAygv28a6C0K5mcfal/ X-Google-Smtp-Source: ABdhPJyBtbAk8TcFiX/VIGUhKGiXocxsQgpKLyfaMJwJYGYH+w9IqoQu0ZX31MySwZtsbV34QLPP6DkszPW0GkxK X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:95a:d8a8:4925:42be]) (user=andreyknvl job=sendgmr) by 2002:a05:6214:c8a:: with SMTP id r10mr12774809qvr.13.1615559092223; Fri, 12 Mar 2021 06:24:52 -0800 (PST) Date: Fri, 12 Mar 2021 15:24:30 +0100 In-Reply-To: Message-Id: <69b9b2e49d8cf789358fa24558be3fc0ce4ee32c.1615559068.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog Subject: [PATCH v2 07/11] kasan: docs: update SW_TAGS implementation details section From: Andrey Konovalov To: Andrew Morton , Alexander Potapenko , Marco Elver Cc: Andrey Ryabinin , Dmitry Vyukov , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Stat-Signature: zmwtbaunacchnfe1x643uhbko979tr76 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 2A3014080F45 Received-SPF: none (flex--andreyknvl.bounces.google.com>: No applicable sender policy available) receiver=imf17; identity=mailfrom; envelope-from="<3tHlLYAoKCN09MCQDXJMUKFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--andreyknvl.bounces.google.com>"; helo=mail-qv1-f74.google.com; client-ip=209.85.219.74 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615559092-530372 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: Update the "Implementation details" section for SW_TAGS KASAN: - Clarify the introduction sentence. - Punctuation, readability, and other minor clean-ups. Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver --- Documentation/dev-tools/kasan.rst | 39 +++++++++++++++---------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/Documentation/dev-tools/kasan.rst b/Documentation/dev-tools/kasan.rst index 986410bf269f..5873d80cc1fd 100644 --- a/Documentation/dev-tools/kasan.rst +++ b/Documentation/dev-tools/kasan.rst @@ -235,38 +235,37 @@ quarantine (see mm/kasan/quarantine.c for implementation). Software tag-based KASAN ~~~~~~~~~~~~~~~~~~~~~~~~ -Software tag-based KASAN requires software memory tagging support in the form -of HWASan-like compiler instrumentation (see HWASan documentation for details). - -Software tag-based KASAN is currently only implemented for arm64 architecture. +Software tag-based KASAN uses a software memory tagging approach to checking +access validity. It is currently only implemented for the arm64 architecture. Software tag-based KASAN uses the Top Byte Ignore (TBI) feature of arm64 CPUs -to store a pointer tag in the top byte of kernel pointers. Like generic KASAN -it uses shadow memory to store memory tags associated with each 16-byte memory -cell (therefore it dedicates 1/16th of the kernel memory for shadow memory). +to store a pointer tag in the top byte of kernel pointers. It uses shadow memory +to store memory tags associated with each 16-byte memory cell (therefore, it +dedicates 1/16th of the kernel memory for shadow memory). -On each memory allocation software tag-based KASAN generates a random tag, tags -the allocated memory with this tag, and embeds this tag into the returned +On each memory allocation, software tag-based KASAN generates a random tag, tags +the allocated memory with this tag, and embeds the same tag into the returned pointer. Software tag-based KASAN uses compile-time instrumentation to insert checks -before each memory access. These checks make sure that tag of the memory that -is being accessed is equal to tag of the pointer that is used to access this -memory. In case of a tag mismatch software tag-based KASAN prints a bug report. +before each memory access. These checks make sure that the tag of the memory +that is being accessed is equal to the tag of the pointer that is used to access +this memory. In case of a tag mismatch, software tag-based KASAN prints a bug +report. -Software tag-based KASAN also has two instrumentation modes (outline, that -emits callbacks to check memory accesses; and inline, that performs the shadow +Software tag-based KASAN also has two instrumentation modes (outline, which +emits callbacks to check memory accesses; and inline, which performs the shadow memory checks inline). With outline instrumentation mode, a bug report is -simply printed from the function that performs the access check. With inline -instrumentation a brk instruction is emitted by the compiler, and a dedicated -brk handler is used to print bug reports. +printed from the function that performs the access check. With inline +instrumentation, a ``brk`` instruction is emitted by the compiler, and a +dedicated ``brk`` handler is used to print bug reports. Software tag-based KASAN uses 0xFF as a match-all pointer tag (accesses through -pointers with 0xFF pointer tag aren't checked). The value 0xFE is currently +pointers with the 0xFF pointer tag are not checked). The value 0xFE is currently reserved to tag freed memory regions. -Software tag-based KASAN currently only supports tagging of -kmem_cache_alloc/kmalloc and page_alloc memory. +Software tag-based KASAN currently only supports tagging of slab and page_alloc +memory. Hardware tag-based KASAN ~~~~~~~~~~~~~~~~~~~~~~~~ From patchwork Fri Mar 12 14:24:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12134797 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=-26.3 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, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL 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 CDBECC433DB for ; Fri, 12 Mar 2021 14:24:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 77E2D64FB2 for ; Fri, 12 Mar 2021 14:24:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 77E2D64FB2 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 161B18D0362; Fri, 12 Mar 2021 09:24:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0EAE98D0360; Fri, 12 Mar 2021 09:24:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ECFEA8D0361; Fri, 12 Mar 2021 09:24:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0216.hostedemail.com [216.40.44.216]) by kanga.kvack.org (Postfix) with ESMTP id CB14D8D0360 for ; Fri, 12 Mar 2021 09:24:56 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 7FD5C181D7EC4 for ; Fri, 12 Mar 2021 14:24:56 +0000 (UTC) X-FDA: 77911443792.08.1FEAA03 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) by imf26.hostedemail.com (Postfix) with ESMTP id 2A0EC407F8FA for ; Fri, 12 Mar 2021 14:24:53 +0000 (UTC) Received: by mail-wm1-f73.google.com with SMTP id o9so2104754wmq.9 for ; Fri, 12 Mar 2021 06:24:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=AADxbeoNuphnMvdgMWHUkUamhVrmAjoCfQWWs7Kvkug=; b=jCrEWQlY9zh5WxZDht/sPXYdkvCCWmhovQqVcz4wxPAIINp3noeg/Ihbr62XzpFxFx 9TYtNPkjrHs7tvLdJ3y5I9Vrob6rePF0RDb9H9nE4TPYRuvSClb1iifQL88/87f7bIb5 ggwioZgT6VUHk45puUhqCYPW4UDzSrQbxaj0YeCQUghMA9v4C0XLY76L1+lre1JkSqWF nB1rQ1XmQBC3/zjODsXnoVRLrXlsxQiNrqdUZ0hQu2bom5QIj76rhRFPTqzBNPbn/Kpa uzVxicMes2Yq9IIU0ovEugsTH2BRhouJbMjo7aw+hgmXAoxp+pEdOFd8RVeD3RLTJKyu pYdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=AADxbeoNuphnMvdgMWHUkUamhVrmAjoCfQWWs7Kvkug=; b=JDqHhBoleK1IL/Sp1chYPMomoTcCLk6K/v5lyhWct9QjqdiG0RUyKDQJUyQbzmQl0k 13nDVA6MpuYksC+qUk81H5OC0Q/D0b3i/eMG3i3qssyAToFl9diOQxKvdlgJcdUQxkvS cfvzUKXpmjKY5Gmn4Rr5D8n04ziiqRFarzXNpiZwGaOG4jP4qou+8gICHs/aQVll1mQ3 eedmE66mxSX9Cjv8PKCLDTCB6W3rLniciPPVwRSGhnKJLsJ+oHzgq6JucYZf001vfj/c yOr5b21DpQOP61D5Iev7SgG/G5kh7J4dwJpqrjiwJPt+/X7KNNCkO63NSdzZdYy4qbye QPNg== X-Gm-Message-State: AOAM533VJfiTKaDluvhe9aymFhW1M7AaXoey//dCX9n0VdBTnC/LwzEW EU3uzYK8Vq2QK8sf6p2Bl2QJqT9cOBH1Xh11 X-Google-Smtp-Source: ABdhPJyexprf1NyGf3J69SnjE5FHdNd0neUkuvSB9iYVeSIHY/h0QFTzjgPmZ58G1l053wwEm4PTcv2OZl8ePB9E X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:95a:d8a8:4925:42be]) (user=andreyknvl job=sendgmr) by 2002:a5d:4688:: with SMTP id u8mr14154024wrq.39.1615559094829; Fri, 12 Mar 2021 06:24:54 -0800 (PST) Date: Fri, 12 Mar 2021 15:24:31 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog Subject: [PATCH v2 08/11] kasan: docs: update HW_TAGS implementation details section From: Andrey Konovalov To: Andrew Morton , Alexander Potapenko , Marco Elver Cc: Andrey Ryabinin , Dmitry Vyukov , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Stat-Signature: hmke3f8iakq8xa34j1iutzh15e6uxiq6 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 2A0EC407F8FA Received-SPF: none (flex--andreyknvl.bounces.google.com>: No applicable sender policy available) receiver=imf26; identity=mailfrom; envelope-from="<3tnlLYAoKCN8BOESFZLOWMHPPHMF.DPNMJOVY-NNLWBDL.PSH@flex--andreyknvl.bounces.google.com>"; helo=mail-wm1-f73.google.com; client-ip=209.85.128.73 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615559093-222376 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: Update the "Implementation details" section for HW_TAGS KASAN: - Punctuation, readability, and other minor clean-ups. Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver --- Documentation/dev-tools/kasan.rst | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Documentation/dev-tools/kasan.rst b/Documentation/dev-tools/kasan.rst index 5873d80cc1fd..2744ae6347c6 100644 --- a/Documentation/dev-tools/kasan.rst +++ b/Documentation/dev-tools/kasan.rst @@ -270,35 +270,35 @@ memory. Hardware tag-based KASAN ~~~~~~~~~~~~~~~~~~~~~~~~ -Hardware tag-based KASAN is similar to the software mode in concept, but uses +Hardware tag-based KASAN is similar to the software mode in concept but uses hardware memory tagging support instead of compiler instrumentation and shadow memory. Hardware tag-based KASAN is currently only implemented for arm64 architecture and based on both arm64 Memory Tagging Extension (MTE) introduced in ARMv8.5 -Instruction Set Architecture, and Top Byte Ignore (TBI). +Instruction Set Architecture and Top Byte Ignore (TBI). Special arm64 instructions are used to assign memory tags for each allocation. Same tags are assigned to pointers to those allocations. On every memory -access, hardware makes sure that tag of the memory that is being accessed is -equal to tag of the pointer that is used to access this memory. In case of a -tag mismatch a fault is generated and a report is printed. +access, hardware makes sure that the tag of the memory that is being accessed is +equal to the tag of the pointer that is used to access this memory. In case of a +tag mismatch, a fault is generated, and a report is printed. Hardware tag-based KASAN uses 0xFF as a match-all pointer tag (accesses through -pointers with 0xFF pointer tag aren't checked). The value 0xFE is currently +pointers with the 0xFF pointer tag are not checked). The value 0xFE is currently reserved to tag freed memory regions. -Hardware tag-based KASAN currently only supports tagging of -kmem_cache_alloc/kmalloc and page_alloc memory. +Hardware tag-based KASAN currently only supports tagging of slab and page_alloc +memory. -If the hardware doesn't support MTE (pre ARMv8.5), hardware tag-based KASAN -won't be enabled. In this case all boot parameters are ignored. +If the hardware does not support MTE (pre ARMv8.5), hardware tag-based KASAN +will not be enabled. In this case, all KASAN boot parameters are ignored. -Note, that enabling CONFIG_KASAN_HW_TAGS always results in in-kernel TBI being -enabled. Even when kasan.mode=off is provided, or when the hardware doesn't +Note that enabling CONFIG_KASAN_HW_TAGS always results in in-kernel TBI being +enabled. Even when ``kasan.mode=off`` is provided or when the hardware does not support MTE (but supports TBI). -Hardware tag-based KASAN only reports the first found bug. After that MTE tag +Hardware tag-based KASAN only reports the first found bug. After that, MTE tag checking gets disabled. Shadow memory From patchwork Fri Mar 12 14:24:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12134801 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=-26.3 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, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL 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 0D348C433E0 for ; Fri, 12 Mar 2021 14:25:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AD75D64FAD for ; Fri, 12 Mar 2021 14:25:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AD75D64FAD 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 CD2978D0363; Fri, 12 Mar 2021 09:24:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CACA78D0361; Fri, 12 Mar 2021 09:24:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AB40F8D0363; Fri, 12 Mar 2021 09:24:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0181.hostedemail.com [216.40.44.181]) by kanga.kvack.org (Postfix) with ESMTP id 873E08D0361 for ; Fri, 12 Mar 2021 09:24:59 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 4A0D98248047 for ; Fri, 12 Mar 2021 14:24:59 +0000 (UTC) X-FDA: 77911443918.20.EE5B61F Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) by imf05.hostedemail.com (Postfix) with ESMTP id 43DAAE0011F1 for ; Fri, 12 Mar 2021 14:24:58 +0000 (UTC) Received: by mail-wr1-f74.google.com with SMTP id x9so11128346wro.9 for ; Fri, 12 Mar 2021 06:24:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=hsoBR6E8KwmiptK80mQJVFHGCa6Vkbo97hvfJKQe5xQ=; b=nXr9UV9/9WyaC3EuPXvNItYFgOiSTCllvCD62KSIp5FuIWKW2sehJhoVxOzJHwG0nM HBvRceqCBfxy5QZQ8RhSJZStHtOCO5xFbRirjQD5la/YLw9YNoyHYoX/5RHAcnnB05i8 hwoJG4k8syFN3DX6r9GGeUdwDKgBTVIjZFQfXSdsmKouxKEm2gt3/p1VDjKC2n5/PaKi peeT2zCt8NU8nDHv/SQm83n2z0M7vI7igfgOfh3DP0nSJbcsjocnofOhglvTKhu/puwI e2SS3RL7DKdVfWtlWlRLg3SXrDzNN2sLem82/rAYCCNcIAJjbtLJr6Hp6OWM0to4U5E9 Y5UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=hsoBR6E8KwmiptK80mQJVFHGCa6Vkbo97hvfJKQe5xQ=; b=Y6DsG4kA5hpBwm3jyPkMZ0cw7ndFpXo3Kga0nzPEsRQWuYSt+pDcUPdXBpPRBSGA1W isBhB+bCr1N5IjSA1oLb1u4pCNkD4zVi5S0dRGDdqvETeoLITcWZm1ycjYg23OmzYAI2 IsarUphwe9S8WbP0PITzzmrvTPthCQ5MazTK61Z0TupqrqbXrtvbxEHYR55BXRvyRatG X65nOsqXXE8qhgQhwoJpc3kGWaDF89q383ZM2cIHgqUyaVXB1JXl50/yFVtAYE48VPpt 2BpOlrMEk7T2bo1sffBdWrxXNW7x8luU5MUDeMi7HvTWD0iXfIzf4YYypCzorsiKaRaJ WfFQ== X-Gm-Message-State: AOAM533G+XQXu4d9hEHSA7adfackyp2bzIHptBv9pH6XNg0gK5dOplXS n62/bdqpR/k+iPIhw6L6B+dQdMyBOHgxnas1 X-Google-Smtp-Source: ABdhPJyEhPq1Wz4x+ftqnbQ2CgJ1RQOONDh7PhI/3hzsY1YVuFsBuC/M2n6BPRMzRPBwd+DmE1BUthENEHm+4VyD X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:95a:d8a8:4925:42be]) (user=andreyknvl job=sendgmr) by 2002:a1c:6243:: with SMTP id w64mr2250680wmb.0.1615559097271; Fri, 12 Mar 2021 06:24:57 -0800 (PST) Date: Fri, 12 Mar 2021 15:24:32 +0100 In-Reply-To: Message-Id: <00f8c38b0fd5290a3f4dced04eaba41383e67e14.1615559068.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog Subject: [PATCH v2 09/11] kasan: docs: update shadow memory section From: Andrey Konovalov To: Andrew Morton , Alexander Potapenko , Marco Elver Cc: Andrey Ryabinin , Dmitry Vyukov , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Stat-Signature: zozk39y176hgod449y775n6f93jjr6p9 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 43DAAE0011F1 Received-SPF: none (flex--andreyknvl.bounces.google.com>: No applicable sender policy available) receiver=imf05; identity=mailfrom; envelope-from="<3uXlLYAoKCOIERHVIcORZPKSSKPI.GSQPMRYb-QQOZEGO.SVK@flex--andreyknvl.bounces.google.com>"; helo=mail-wr1-f74.google.com; client-ip=209.85.221.74 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615559098-791962 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: Update the "Shadow memory" section in KASAN documentation: - Rearrange the introduction paragraph do it doesn't give a "KASAN has an issue" impression. - Update the list of architectures with vmalloc support. - Punctuation, readability, and other minor clean-ups. Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver --- Documentation/dev-tools/kasan.rst | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/Documentation/dev-tools/kasan.rst b/Documentation/dev-tools/kasan.rst index 2744ae6347c6..d0c1796122df 100644 --- a/Documentation/dev-tools/kasan.rst +++ b/Documentation/dev-tools/kasan.rst @@ -304,14 +304,11 @@ checking gets disabled. Shadow memory ------------- -The kernel maps memory in a number of different parts of the address -space. This poses something of a problem for KASAN, which requires -that all addresses accessed by instrumented code have a valid shadow -region. - -The range of kernel virtual addresses is large: there is not enough -real memory to support a real shadow region for every address that -could be accessed by the kernel. +The kernel maps memory in several different parts of the address space. +The range of kernel virtual addresses is large: there is not enough real +memory to support a real shadow region for every address that could be +accessed by the kernel. Therefore, KASAN only maps real shadow for certain +parts of the address space. Default behaviour ~~~~~~~~~~~~~~~~~ @@ -323,10 +320,9 @@ page is mapped over the shadow area. This read-only shadow page declares all memory accesses as permitted. This presents a problem for modules: they do not live in the linear -mapping, but in a dedicated module space. By hooking in to the module -allocator, KASAN can temporarily map real shadow memory to cover -them. This allows detection of invalid accesses to module globals, for -example. +mapping but in a dedicated module space. By hooking into the module +allocator, KASAN temporarily maps real shadow memory to cover them. +This allows detection of invalid accesses to module globals, for example. This also creates an incompatibility with ``VMAP_STACK``: if the stack lives in vmalloc space, it will be shadowed by the read-only page, and @@ -337,9 +333,10 @@ CONFIG_KASAN_VMALLOC ~~~~~~~~~~~~~~~~~~~~ With ``CONFIG_KASAN_VMALLOC``, KASAN can cover vmalloc space at the -cost of greater memory usage. Currently this is only supported on x86. +cost of greater memory usage. Currently, this is supported on x86, +riscv, s390, and powerpc. -This works by hooking into vmalloc and vmap, and dynamically +This works by hooking into vmalloc and vmap and dynamically allocating real shadow memory to back the mappings. Most mappings in vmalloc space are small, requiring less than a full @@ -358,10 +355,10 @@ memory. To avoid the difficulties around swapping mappings around, KASAN expects that the part of the shadow region that covers the vmalloc space will -not be covered by the early shadow page, but will be left -unmapped. This will require changes in arch-specific code. +not be covered by the early shadow page but will be left unmapped. +This will require changes in arch-specific code. -This allows ``VMAP_STACK`` support on x86, and can simplify support of +This allows ``VMAP_STACK`` support on x86 and can simplify support of architectures that do not have a fixed module region. For developers From patchwork Fri Mar 12 14:24:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12134803 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=-26.3 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, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL 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 5A49AC433DB for ; Fri, 12 Mar 2021 14:25:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 080AD64FDD for ; Fri, 12 Mar 2021 14:25:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 080AD64FDD 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 B4EFC8D0364; Fri, 12 Mar 2021 09:25:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B23488D0361; Fri, 12 Mar 2021 09:25:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9C5118D0364; Fri, 12 Mar 2021 09:25:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0044.hostedemail.com [216.40.44.44]) by kanga.kvack.org (Postfix) with ESMTP id 79A998D0361 for ; Fri, 12 Mar 2021 09:25:01 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 3207183FF for ; Fri, 12 Mar 2021 14:25:01 +0000 (UTC) X-FDA: 77911444002.07.4ACCF70 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf25.hostedemail.com (Postfix) with ESMTP id D1C336000100 for ; Fri, 12 Mar 2021 14:24:58 +0000 (UTC) Received: by mail-wm1-f74.google.com with SMTP id s192so5408932wme.6 for ; Fri, 12 Mar 2021 06:25:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Ygfy34R30Ir5P43bAuVWD7PsEpaVeYrJUsfKdxJOhKs=; b=rC5oeVOtwW4j37sI8e0pI6DstMXXrDhg66shdjo/HdwFQuJql7l9XihT1b74K7zfvu +LMZjin/QNQW1inNez0NvU7o976i056UEY83jBhxXulKZh6DQMsHam+O+rTQLzLGCzmr tN3mgw7nzkn9DE5HZ+CQpqrDn1rVhghN3essH34emvOhlYdE9vQ115ZaFgV0UC7h4urG 39CWaz23zdSYXKZZzs7gNqzSk1aKHKyw1XCLtRuu/NJeiNRw/SEJDhBh0MZ5Vxp+J0GM JZnpHWL8trHR2Z8bs3OeGJoXIJqxcVqem5ARckJOk1XY3jW1rOk0XuSPTY++Y+xTm5+P J3jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Ygfy34R30Ir5P43bAuVWD7PsEpaVeYrJUsfKdxJOhKs=; b=JaiJJ+1YGg/y7PomnBgQQ6RQ49yUEpBzYqouGzezPBjaPBEfDivJ9Gt3Mk7jH64AIx 9n+YpvrvG8r9Af7J6FYi8It9DYbqv4gzthUcGW4GRnRfNZ2w586DzOTa/mUiSItGqxyl pOcd/67MQXFAQNySsxFGY+V0R2d71Dmrk6EbmFexN4961B5men65ujfTYdhsPfE6xBAr s9YwRUM2S5ur+p/OFmW/Fr3T5gI1lN2WcccHr+6FZedlEKxcWQpYOmKqEoOa27Y22xia jPI/XxNScu0gp4w8WkWcfEc0a3nJXTRkUVJ6xfBM2q1sDjqcXb39QnhbQ9PkAXjMRP8i udmg== X-Gm-Message-State: AOAM531tItWPUqFnH5X7u/Z/1whdk+TSS0mq05nMBBlbt2hsxVZQ5lDv wLx4/B8Db4HRfiTm5oIOVuxtfxM8i1wkUbaO X-Google-Smtp-Source: ABdhPJzH5ceh4zLI0fc9g5fS021UsKjJ3ZXNJjpWRuf5c3Y6bxgUMjDEdZwoLCR2U8J2ymtATr4A6hag3hjCMNcT X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:95a:d8a8:4925:42be]) (user=andreyknvl job=sendgmr) by 2002:a1c:5416:: with SMTP id i22mr13379263wmb.146.1615559099696; Fri, 12 Mar 2021 06:24:59 -0800 (PST) Date: Fri, 12 Mar 2021 15:24:33 +0100 In-Reply-To: Message-Id: <4531ba5f3eca61f6aade863c136778cc8c807a64.1615559068.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog Subject: [PATCH v2 10/11] kasan: docs: update ignoring accesses section From: Andrey Konovalov To: Andrew Morton , Alexander Potapenko , Marco Elver Cc: Andrey Ryabinin , Dmitry Vyukov , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Stat-Signature: fchq76xecgqfr1p1u57g4sqz5wrej6ek X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: D1C336000100 Received-SPF: none (flex--andreyknvl.bounces.google.com>: No applicable sender policy available) receiver=imf25; identity=mailfrom; envelope-from="<3u3lLYAoKCOQGTJXKeQTbRMUUMRK.IUSROTad-SSQbGIQ.UXM@flex--andreyknvl.bounces.google.com>"; helo=mail-wm1-f74.google.com; client-ip=209.85.128.74 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615559098-106414 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: Update the "Ignoring accesses" section in KASAN documentation: - Mention __no_sanitize_address/noinstr. - Mention kasan_disable/enable_current(). - Mention kasan_reset_tag()/page_kasan_tag_reset(). - Readability and punctuation clean-ups. Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver --- Changes in v1->v2: - Mention __no_sanitize_address/noinstr. - Reword the whole section to make it clear which method works for which mode. --- Documentation/dev-tools/kasan.rst | 34 +++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/Documentation/dev-tools/kasan.rst b/Documentation/dev-tools/kasan.rst index d0c1796122df..5749c14b38d0 100644 --- a/Documentation/dev-tools/kasan.rst +++ b/Documentation/dev-tools/kasan.rst @@ -368,12 +368,18 @@ Ignoring accesses ~~~~~~~~~~~~~~~~~ Software KASAN modes use compiler instrumentation to insert validity checks. -Such instrumentation might be incompatible with some part of the kernel, and -therefore needs to be disabled. To disable instrumentation for specific files -or directories, add a line similar to the following to the respective kernel +Such instrumentation might be incompatible with some parts of the kernel, and +therefore needs to be disabled. + +Other parts of the kernel might access metadata for allocated objects. +Normally, KASAN detects and reports such accesses, but in some cases (e.g., +in memory allocators), these accesses are valid. + +For software KASAN modes, to disable instrumentation for a specific file or +directory, add a ``KASAN_SANITIZE`` annotation to the respective kernel Makefile: -- For a single file (e.g. main.o):: +- For a single file (e.g., main.o):: KASAN_SANITIZE_main.o := n @@ -381,6 +387,26 @@ Makefile: KASAN_SANITIZE := n +For software KASAN modes, to disable instrumentation on a per-function basis, +use the KASAN-specific ``__no_sanitize_address`` function attribute or the +generic ``noinstr`` one. + +Note that disabling compiler instrumentation (either on a per-file or a +per-function basis) makes KASAN ignore the accesses that happen directly in +that code for software KASAN modes. It does not help when the accesses happen +indirectly (through calls to instrumented functions) or with the hardware +tag-based mode that does not use compiler instrumentation. + +For software KASAN modes, to disable KASAN reports in a part of the kernel code +for the current task, annotate this part of the code with a +``kasan_disable_current()``/``kasan_enable_current()`` section. This also +disables the reports for indirect accesses that happen through function calls. + +For tag-based KASAN modes (include the hardware one), to disable access +checking, use ``kasan_reset_tag()`` or ``page_kasan_tag_reset()``. Note that +temporarily disabling access checking via ``page_kasan_tag_reset()`` requires +saving and restoring the per-page KASAN tag via +``page_kasan_tag``/``page_kasan_tag_set``. Tests ~~~~~ From patchwork Fri Mar 12 14:24:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12134805 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=-26.3 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, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL 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 CC962C433E0 for ; Fri, 12 Mar 2021 14:25:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 74C0464FD6 for ; Fri, 12 Mar 2021 14:25:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 74C0464FD6 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 CF9448D0365; Fri, 12 Mar 2021 09:25:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CABEF8D0361; Fri, 12 Mar 2021 09:25:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B244D8D0365; Fri, 12 Mar 2021 09:25:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0059.hostedemail.com [216.40.44.59]) by kanga.kvack.org (Postfix) with ESMTP id 562C28D0361 for ; Fri, 12 Mar 2021 09:25:04 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 148C85010 for ; Fri, 12 Mar 2021 14:25:04 +0000 (UTC) X-FDA: 77911444128.25.05444C8 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) by imf15.hostedemail.com (Postfix) with ESMTP id CE86BA0000FD for ; Fri, 12 Mar 2021 14:25:02 +0000 (UTC) Received: by mail-wr1-f74.google.com with SMTP id m23so6212066wrh.7 for ; Fri, 12 Mar 2021 06:25:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Bw5uCei/catF+EzOEmfCcRCFyREJER0Q0h8plWDwOtQ=; b=Xnhtd3gvW2K8u2WiuCaZNvtsoyWO9DSXU+9u6yVJZ4RbQh7xRFDPPX1TkZXDu2ZUGc vBkGtX3S8Jq5LetjXUH0b+2csT0PMYHsU2T0hLUWe5RLQ67/II10RAKEsIGTO9Rg5nj5 uyQPdUribEsObu00cvEGjydTSBi2d2qvyX1zkl+7Us81ZrgAbZUQVj17EMzIMQuiGmEa Wai+muui+UNGInCH5JrDeQWuus39Oez87A9DPVxkdClfs2Z6MS0mhRNl8dMnlLXappbW yXYhJ1d21mG1S90SgjQx9wBSLQ/VsQhFTo0iyj1XWheORUnb1eGCiEa7GIUA//kZ2DO3 RkXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Bw5uCei/catF+EzOEmfCcRCFyREJER0Q0h8plWDwOtQ=; b=hlmEaF0MFsKhwziJzqjZw8YtJdbBgAfr3i4quQZf4QA656Ldpd6r9MAndG4CfUoYMS lX7x4oywgKCY9PTYbB4iT0glZdXKFFaYQjDGq4vo5i7T3Ev/8g8LjN5oXX0s/chHYcbS fEE2JHYer2aOCKaAYQ2Tby1CFfnPkws7VcAbjKSnw1XFHIk/3F1o0S3Fb3u+l5NvCBjz N7DizILY5HHNSzQZMplA/z9zsOAy0/tYCvY1lbP638LRfNPBhw8YOtJEwKi8CBvW1Yqb +uByaI9qsBaZ4j8IbHIqgzS/ZsTQeSaRvxJaJ3RJPNU1p7XvMhhfmBtogjMTa1RKRaro ZvoQ== X-Gm-Message-State: AOAM532skpwytUTTif42CxzhzVix1xCnt6gmCxsuYEHA56G5btto2Udj aAnXwTZ7pF2zFrU2CMeueI0s1HvlATu3SSol X-Google-Smtp-Source: ABdhPJzx/wOW6+gWN/8am6G2R3KojRCf27zV3DUYoC42P07d36RS26M31dlU0mkAElkJQD/Bs1CkPM2pjAu6wwFv X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:95a:d8a8:4925:42be]) (user=andreyknvl job=sendgmr) by 2002:a7b:c18e:: with SMTP id y14mr2248712wmi.1.1615559101927; Fri, 12 Mar 2021 06:25:01 -0800 (PST) Date: Fri, 12 Mar 2021 15:24:34 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog Subject: [PATCH v2 11/11] kasan: docs: update tests section From: Andrey Konovalov To: Andrew Morton , Alexander Potapenko , Marco Elver Cc: Andrey Ryabinin , Dmitry Vyukov , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Stat-Signature: 4tsz7mn1aeec879tadoxmu8wfa7i5h19 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: CE86BA0000FD Received-SPF: none (flex--andreyknvl.bounces.google.com>: No applicable sender policy available) receiver=imf15; identity=mailfrom; envelope-from="<3vXlLYAoKCOYIVLZMgSVdTOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--andreyknvl.bounces.google.com>"; helo=mail-wr1-f74.google.com; client-ip=209.85.221.74 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615559102-594406 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: Update the "Tests" section in KASAN documentation: - Add an introductory sentence. - Add proper indentation for the list of ways to run KUnit tests. - Punctuation, readability, and other minor clean-ups. Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver --- Changes v1->v2: - Fix missing snippet delimeter around "test_kasan.ko". - Drop "the" before "test_kasan.ko". --- Documentation/dev-tools/kasan.rst | 32 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/Documentation/dev-tools/kasan.rst b/Documentation/dev-tools/kasan.rst index 5749c14b38d0..a8c3e0cff88d 100644 --- a/Documentation/dev-tools/kasan.rst +++ b/Documentation/dev-tools/kasan.rst @@ -411,19 +411,20 @@ saving and restoring the per-page KASAN tag via Tests ~~~~~ -KASAN tests consist of two parts: +There are KASAN tests that allow verifying that KASAN works and can detect +certain types of memory corruptions. The tests consist of two parts: 1. Tests that are integrated with the KUnit Test Framework. Enabled with ``CONFIG_KASAN_KUNIT_TEST``. These tests can be run and partially verified -automatically in a few different ways, see the instructions below. +automatically in a few different ways; see the instructions below. 2. Tests that are currently incompatible with KUnit. Enabled with ``CONFIG_KASAN_MODULE_TEST`` and can only be run as a module. These tests can -only be verified manually, by loading the kernel module and inspecting the +only be verified manually by loading the kernel module and inspecting the kernel log for KASAN reports. -Each KUnit-compatible KASAN test prints a KASAN report if an error is detected. -Then the test prints its number and status. +Each KUnit-compatible KASAN test prints one of multiple KASAN reports if an +error is detected. Then the test prints its number and status. When a test passes:: @@ -451,27 +452,24 @@ Or, if one of the tests failed:: not ok 1 - kasan - There are a few ways to run KUnit-compatible KASAN tests. 1. Loadable module -With ``CONFIG_KUNIT`` enabled, ``CONFIG_KASAN_KUNIT_TEST`` can be built as -a loadable module and run on any architecture that supports KASAN by loading -the module with insmod or modprobe. The module is called ``test_kasan``. + With ``CONFIG_KUNIT`` enabled, KASAN-KUnit tests can be built as a loadable + module and run by loading ``test_kasan.ko`` with ``insmod`` or ``modprobe``. 2. Built-In -With ``CONFIG_KUNIT`` built-in, ``CONFIG_KASAN_KUNIT_TEST`` can be built-in -on any architecure that supports KASAN. These and any other KUnit tests enabled -will run and print the results at boot as a late-init call. + With ``CONFIG_KUNIT`` built-in, KASAN-KUnit tests can be built-in as well. + In this case, the tests will run at boot as a late-init call. 3. Using kunit_tool -With ``CONFIG_KUNIT`` and ``CONFIG_KASAN_KUNIT_TEST`` built-in, it's also -possible use ``kunit_tool`` to see the results of these and other KUnit tests -in a more readable way. This will not print the KASAN reports of the tests that -passed. Use `KUnit documentation `_ -for more up-to-date information on ``kunit_tool``. + With ``CONFIG_KUNIT`` and ``CONFIG_KASAN_KUNIT_TEST`` built-in, it is also + possible to use ``kunit_tool`` to see the results of KUnit tests in a more + readable way. This will not print the KASAN reports of the tests that passed. + See `KUnit documentation `_ + for more up-to-date information on ``kunit_tool``. .. _KUnit: https://www.kernel.org/doc/html/latest/dev-tools/kunit/index.html