From patchwork Thu Mar 11 21:37:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12132943 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 D4A69C433E0 for ; Thu, 11 Mar 2021 21:37:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5204A64F8E for ; Thu, 11 Mar 2021 21:37:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5204A64F8E 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 C42A08D02F9; Thu, 11 Mar 2021 16:37:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BF2588D02B2; Thu, 11 Mar 2021 16:37:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A945A8D02F9; Thu, 11 Mar 2021 16:37:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0105.hostedemail.com [216.40.44.105]) by kanga.kvack.org (Postfix) with ESMTP id 884D88D02B2 for ; Thu, 11 Mar 2021 16:37:29 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 41D378249980 for ; Thu, 11 Mar 2021 21:37:29 +0000 (UTC) X-FDA: 77908905018.15.C99432D Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) by imf04.hostedemail.com (Postfix) with ESMTP id E03BC138 for ; Thu, 11 Mar 2021 21:37:27 +0000 (UTC) Received: by mail-wr1-f74.google.com with SMTP id l10so10139994wry.16 for ; Thu, 11 Mar 2021 13:37:28 -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=+0bSxqm3N16pi4DLzYVkzAZIIL0GOgjjdGwFbbf/d6g=; b=nG+j8ZjKWJHc0pWl0HEWnV5szaRgEoGqQZAqlugEgOCqWeoxKf+eOEgQ7GtX9f3rpG i//Khh4s46yYKi9ia+gYNZnqaWCjtHpXqxy/ZcUTMQyVTt3GLlVqcEy8qglz3lMxMaIS fsiAaKa9PfdRoR2qpcmZ0kfyN0MgY6/pecoPIhdtnPqgaTrImvBJT87toUBYiWZm7oB5 tmR62qDRAGWhmkVheLXp7x+2VIZisul9o/bh/MKFtt3SJqp4vBQP+PQoayaPchChtdSW aMlD3xxQiT23Etg6lerRBN4cuqOtH7J3Z2AY8K2aUCgdBr7iuUGwBE7S1OZ6QTyL4KL8 Talw== 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=+0bSxqm3N16pi4DLzYVkzAZIIL0GOgjjdGwFbbf/d6g=; b=JdPmudsJHeVtWy2ZSS74dux+MhnYrFpDdREmqzprcmup3BjC39PUsOqtZVhxpI4UxZ kAUvmP2ZTarW6pT0Iu+fMYEk+9Oegru0GvOP7bXB5iwWiTnLOyj6Y/S46ZBgbtsO/oaW oBZljmsfwlsFtEScrgHfIG3KW9d7RaPICHShIH4YTFsNSS+eidb+OUmc0AFPjKyJmvZr ZRcvjLWIToT07fH1BX/6KjZwd3B+T2snCOE57EVVwSUIlM/8o2HZrxn6aBqfcMoqTFcD tCvIq/CbadymPoca2TINjl6SuvDDpAswROhUr2rvyOpmacoscbp9a9xWz/CHeObV3N8v k1lg== X-Gm-Message-State: AOAM533+xwaxdh3r4+huI0FwvaoNE9acB+3tq7tvsILiOFn2CcH4MTi6 WoReB7WTxm/+iGKeDX3BWo5lbIMgZ8p6acVH X-Google-Smtp-Source: ABdhPJzpngoBsnxjuh5T3WV1Q4rDy2G/NhYnnXiurKZVByyvDTixZR0+zyVt3uiDvASjAsjfW6bZLh3MxsQqfiap X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:95a:d8a8:4925:42be]) (user=andreyknvl job=sendgmr) by 2002:a5d:638f:: with SMTP id p15mr10637565wru.220.1615498647343; Thu, 11 Mar 2021 13:37:27 -0800 (PST) Date: Thu, 11 Mar 2021 22:37:13 +0100 Message-Id: Mime-Version: 1.0 X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog Subject: [PATCH 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: 8nye7pn3kkwcd74eedgr7a9zocgwtbqn X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: E03BC138 Received-SPF: none (flex--andreyknvl.bounces.google.com>: No applicable sender policy available) receiver=imf04; identity=mailfrom; envelope-from="<3l41KYAoKCOQGTJXKeQTbRMUUMRK.IUSROTad-SSQbGIQ.UXM@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: 1615498647-530262 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 --- Documentation/dev-tools/kasan.rst | 50 +++++++++++++++---------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/Documentation/dev-tools/kasan.rst b/Documentation/dev-tools/kasan.rst index ddf4239a5890..c9484f34da2a 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 @@ -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 Thu Mar 11 21:37:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12132945 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 68B73C433DB for ; Thu, 11 Mar 2021 21:37:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D1AEF64F19 for ; Thu, 11 Mar 2021 21:37:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D1AEF64F19 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 5DB308D02FA; Thu, 11 Mar 2021 16:37:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 58AB58D02B2; Thu, 11 Mar 2021 16:37:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 42BC58D02FA; Thu, 11 Mar 2021 16:37:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0222.hostedemail.com [216.40.44.222]) by kanga.kvack.org (Postfix) with ESMTP id 200488D02B2 for ; Thu, 11 Mar 2021 16:37:32 -0500 (EST) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id CC9576D6D for ; Thu, 11 Mar 2021 21:37:31 +0000 (UTC) X-FDA: 77908905102.04.8F5FD62 Received: from mail-ej1-f73.google.com (mail-ej1-f73.google.com [209.85.218.73]) by imf19.hostedemail.com (Postfix) with ESMTP id 6979A90009F3 for ; Thu, 11 Mar 2021 21:37:29 +0000 (UTC) Received: by mail-ej1-f73.google.com with SMTP id fy8so9228137ejb.19 for ; Thu, 11 Mar 2021 13:37:31 -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=bDwYzUcq1HRoRYrIwl703QQ3e7+1Dgb9ijuIXOFbJHo=; b=AN4kaYWMwgLyNq9/I2+MxoRvyGdu5wrRA0oy9puCLntFIfitARVxBAREcjxAZTPB6G ILX8K3mtmmvfngnASSchXJ7vleDurUCocGbi4ou5uRB8sBewWhKoQmwU4l723uGTwv0i IOYQNbSuPtJupX70JfyQzfetrlZbE91wTbGJD3QCvuI8cqtl2BAtd9bpnEactwFhZEwm Y3BsGpb4rA5jPvbVKm1Q62RZF7uTg2jxPjqvDirsJGKliWAZ91n1rHUiNBi32ImW3IIP jYwQnl13fF1UnBnX5lD+DmCoHYVwhur1LzpCYfKjcHZGVn44dUBo8N4ElCCtQlI4ovce STng== 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=bDwYzUcq1HRoRYrIwl703QQ3e7+1Dgb9ijuIXOFbJHo=; b=lC0wnB6LTbQuyolfnm3zprm7J5hlv+ds3c9dj5CJu3Cbj9Nod93I0mxrSuyJybpwD0 2tbDpd7M5Twd87FLqJcd6/+Sgh5Vpzd45tisDKUv+lSQMixlyAb/bQoVNOjTgO439ezo aV76WoaedKRq3Wj4oaS8RdoDLNuTecD0o711JfYY/CuuHbdslsU0Ap9nCxZUoEBiXGvY D5fT4hPPCXHT93xnCLYDCdc5naasaIDQofmqg6qMxRJIYFDRjf9YtGNYM4KhSMQxc9u4 ryHSqRKyI+OJylDEBFrgiL2qNp7qJBRnuQDJMwLoe9YMqQC/xFlqS4qcUZgYHKQKF709 aRTA== X-Gm-Message-State: AOAM533onHjogVj/6JRdPRq57ysKV9yCps5HvCaq7ECep5cV4dlhYii3 vVj8+q1WARWxRnA1G1FutI7D59hFZVRZNWOO X-Google-Smtp-Source: ABdhPJzMo+eA7a6fuh+dXZsnTOZaNB7TB8P9v/TP9gl7+G9QurdFlRfLnemsNIzMnIgQfGWArKpJYiTpxeF0yhpH X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:95a:d8a8:4925:42be]) (user=andreyknvl job=sendgmr) by 2002:a17:906:bccc:: with SMTP id lw12mr5043065ejb.268.1615498649994; Thu, 11 Mar 2021 13:37:29 -0800 (PST) Date: Thu, 11 Mar 2021 22:37:14 +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 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: m4diemczas6fhzcrxkts85r77oxqbhka X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 6979A90009F3 Received-SPF: none (flex--andreyknvl.bounces.google.com>: No applicable sender policy available) receiver=imf19; identity=mailfrom; envelope-from="<3mY1KYAoKCOYIVLZMgSVdTOWWOTM.KWUTQVcf-UUSdIKS.WZO@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: 1615498649-993580 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 --- 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 c9484f34da2a..343a683d0520 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 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 Thu Mar 11 21:37:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12132947 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 323FAC433E0 for ; Thu, 11 Mar 2021 21:37:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B1C2D64F8E for ; Thu, 11 Mar 2021 21:37:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B1C2D64F8E 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 4A27C8D02FB; Thu, 11 Mar 2021 16:37:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 42D8F8D02B2; Thu, 11 Mar 2021 16:37:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2A5C18D02FB; Thu, 11 Mar 2021 16:37:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0129.hostedemail.com [216.40.44.129]) by kanga.kvack.org (Postfix) with ESMTP id 088AC8D02B2 for ; Thu, 11 Mar 2021 16:37:34 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id C00DE1811E9FC for ; Thu, 11 Mar 2021 21:37:33 +0000 (UTC) X-FDA: 77908905186.25.12EA556 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf16.hostedemail.com (Postfix) with ESMTP id 2DAD8801914B for ; Thu, 11 Mar 2021 21:37:33 +0000 (UTC) Received: by mail-wm1-f74.google.com with SMTP id a3so1738726wmm.0 for ; Thu, 11 Mar 2021 13:37:33 -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=DMCAKfggtb6XfOnfwXa7RpunfAY3u5vebHv4cftZQZg=; b=lAknWDT57GMBZODmPOA3/KuMa4ZkSrhXnTUgJ6a06+kB7RCuX7vEyP/HYTI2iFEHYr tRYwSAWB4gOUKYIkZjpFVMAxvyQHnGrFeRjhb2MUfkjqEoOoTTLxwgPOTVpqGk1L/5Wb Z+7W3Rg/ud0G75onwXNeU+rNZVbJh5RlKsUt/zwT16LQ8Vsek1D4dmkjrjZuUlL9lRPz kl9IYW3uS5g89A3Yjomce78lVVpH/iqzycard8tq6M45iR4xktsUyqy2UfGCLNETFG7U x1HeQsm29MO4UDAzqzb+RkgfN4C5w/00mhJXSZ26HFHLWwiN2cadZx02FIWTmOg8y9Ym A21A== 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=DMCAKfggtb6XfOnfwXa7RpunfAY3u5vebHv4cftZQZg=; b=Auf6EF2WvhGCa1c7Ytb7vhIqiZgikrmKPqtGaCdIPLBRn1c9ddVVlzGTzcQEbclFbO 7HiChphBh/aQO7JtY3KuJH6JLStQIJd8kaznKLH2/TupY23aAkYk+rJY5HP0mYTtUEc+ ZhmoOC+62Z2mbklYrq+Z1Pbk84SxpqmvFq2cLcKXtvVDLZFMGnyvQoE5tdKkYZehVl5i 4TuN+DpjwFmLyBceI1C3szBKuBEDzLCZ4O62nFKaU8RtCPtTONqeO4VXZplfxXeRWhv5 sD7wmDn+hL9XAZzmoxDhvgBTX0PwG18rCDkqYiYO6I8RSP3oAyMyTO0Hx4AWpgW0I7Cl X+lg== X-Gm-Message-State: AOAM533mH72wZRYYLWJcYMHd6LhE+kZ99dN1faft9D6XSqj22duBqmM0 N/cRqPGV1P3L6XRCTr9322ydFjL1nbRc+h/Q X-Google-Smtp-Source: ABdhPJyWd3HUCuSoQo0Mxee3WuZNPsz7ZPqsHHWGnOpmKuhO+0BOfpBqFvna4ZwLsNDHoBx5JOpGD8EZcQoaaFD9 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:95a:d8a8:4925:42be]) (user=andreyknvl job=sendgmr) by 2002:a05:600c:35cd:: with SMTP id r13mr10155047wmq.186.1615498652153; Thu, 11 Mar 2021 13:37:32 -0800 (PST) Date: Thu, 11 Mar 2021 22:37:15 +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 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: 2DAD8801914B X-Stat-Signature: 5o4e9cd6ru13idy3iqc1ytajszpc8u76 Received-SPF: none (flex--andreyknvl.bounces.google.com>: No applicable sender policy available) receiver=imf16; identity=mailfrom; envelope-from="<3nI1KYAoKCOkLYOcPjVYgWRZZRWP.NZXWTYfi-XXVgLNV.ZcR@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: 1615498653-425297 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 --- 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 343a683d0520..f21c0cbebcb3 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 Thu Mar 11 21:37:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12132949 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 5E72CC433DB for ; Thu, 11 Mar 2021 21:37:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E2F1F64F8F for ; Thu, 11 Mar 2021 21:37:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E2F1F64F8F 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 73C798D02FC; Thu, 11 Mar 2021 16:37:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6EB638D02B2; Thu, 11 Mar 2021 16:37:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4F0E38D02FC; Thu, 11 Mar 2021 16:37:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0246.hostedemail.com [216.40.44.246]) by kanga.kvack.org (Postfix) with ESMTP id 2792C8D02B2 for ; Thu, 11 Mar 2021 16:37:36 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id C735D824999B for ; Thu, 11 Mar 2021 21:37:35 +0000 (UTC) X-FDA: 77908905270.30.CAA954B Received: from mail-qt1-f201.google.com (mail-qt1-f201.google.com [209.85.160.201]) by imf01.hostedemail.com (Postfix) with ESMTP id AEC18200038A for ; Thu, 11 Mar 2021 21:37:35 +0000 (UTC) Received: by mail-qt1-f201.google.com with SMTP id k4so16582188qtd.20 for ; Thu, 11 Mar 2021 13:37:35 -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=Z5eOirVQs3kFMVVYLPwNbYTFfp7Ms1nJ3eBbZNg7oSE=; b=ss9oJe0pM2ElU/I3jSTTIlzmBUFKVJwse1lMSmfbJC3heqvzN6V6cu3CVowDOoIys7 rHMW8ZRVxkgSQlriCc4puO8sQCLF4m52Eo7IvUY49QDarKLJYOtK6OA4Ulvgcrs5jMLJ 0frkrdx99oF6gVY8/+c6aadOP0Sm5IPEodDeKW00DgiskPb06OwXLLcaGoFCFAFb02We 4RaGm9dQxKxdpEJ5Smlg67KHtZJ4/ZGTU/9xSWGC5mt8nD8ct0o6fNh5RoUkDWOBFMxZ 4HacTXoIMjA7mgORYCvPh35ywI0iWSlVW8T1j1N8iEmg+PCR69tuDedRH8+TrZPo3mMi Z8nQ== 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=Z5eOirVQs3kFMVVYLPwNbYTFfp7Ms1nJ3eBbZNg7oSE=; b=f6vGavx0TLzp4Vg6bGLFmmXn+VmaJCuMkU4kOMc32TeK3OeSByH94ceev4HgSzHlGX IUklbtqkH34r99o0C4VmwhVUFym7uGR52eNHPh+vXks+9mWC+BQ2nYWUpfcxJbzte9v7 RTa+4wEi4xDTGeZtZ/v9/w6Ky/7T3oKX33Hu791z430SGYqthz1QFHac2Hrsrx1dYZfD TWgiBy8zdubqfqIFOtOnC08Iwsju6fbPTiaeYA6PZ6ysqot+9Lvj2PKWHq06y7XW478u ++Kjq4lp4ykA3JdLBYgpmFvNv9xzf+YM00zdiI4itgXzKxoZnFfMNFccEhrA+2f1VNPa aETw== X-Gm-Message-State: AOAM532XXLehziwH71n36I0e7IaspgRpxil0GYZESPnvfmUnG9a3Gps7 xny5gnJHGewEIg5CN0ObntchSY0ZnHNhsl7B X-Google-Smtp-Source: ABdhPJwtC+4faGTKQmjBS8T6FlPpbYJS3wpQopaKe7j5nNJcKaN9acXfERXOjuleqJBSaw58Zbaz0cv45QLzR4Fs X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:95a:d8a8:4925:42be]) (user=andreyknvl job=sendgmr) by 2002:a0c:c248:: with SMTP id w8mr9669098qvh.58.1615498654537; Thu, 11 Mar 2021 13:37:34 -0800 (PST) Date: Thu, 11 Mar 2021 22:37:16 +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 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-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: AEC18200038A X-Stat-Signature: r3pfqk9aqtphxc1hzjspqwntoob3k1n9 Received-SPF: none (flex--andreyknvl.bounces.google.com>: No applicable sender policy available) receiver=imf01; identity=mailfrom; envelope-from="<3no1KYAoKCOsNaQeRlXaiYTbbTYR.PbZYVahk-ZZXiNPX.beT@flex--andreyknvl.bounces.google.com>"; helo=mail-qt1-f201.google.com; client-ip=209.85.160.201 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615498655-860747 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 --- 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 f21c0cbebcb3..5fe43489e94e 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 Thu Mar 11 21:37:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12132951 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 207A9C433DB for ; Thu, 11 Mar 2021 21:37:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B88D864F19 for ; Thu, 11 Mar 2021 21:37:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B88D864F19 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 4A1AA8D02FD; Thu, 11 Mar 2021 16:37:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 479008D02B2; Thu, 11 Mar 2021 16:37:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 31C3A8D02FD; Thu, 11 Mar 2021 16:37:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0159.hostedemail.com [216.40.44.159]) by kanga.kvack.org (Postfix) with ESMTP id 0E1AD8D02B2 for ; Thu, 11 Mar 2021 16:37:39 -0500 (EST) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id A394D2839 for ; Thu, 11 Mar 2021 21:37:38 +0000 (UTC) X-FDA: 77908905396.03.6EB64E1 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf12.hostedemail.com (Postfix) with ESMTP id 4AD31EF for ; Thu, 11 Mar 2021 21:37:34 +0000 (UTC) Received: by mail-wm1-f74.google.com with SMTP id r18so4555623wmq.5 for ; Thu, 11 Mar 2021 13:37:37 -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=5DZPocqARvJ2VhBFUP59zWFPA2pzWUkM0o/y8pYmFsA=; b=ACyAQPWmvq+dZylG5VI/jRYY6sQl1IZ6N4PT9Rdc/yzYMPJCYHuZdkYZh48JjAoggg WDUsxkJTRWWxF21I/IBkPZ5PFV/REw+wSsHkD1LGe7hRMZBxYxoEr8OrauLf2u9Xunvo mWYL3QzNGQ4lwNk8hGnYa8o1ZQ0KfaSGux4X1KxyyJgWv1lny7dQ5U7GhTHrQ8bK6fwZ Qrvwfh2ATxJNUa2nH7Heg88Q8APRejiLmsfyaKEU8xL69rIZNGSzM/Zwig7d6nGC8FTM EXEV0MFip+6ZHsabX/6RgRI+uIYIxcvjUVg/3RP6XP7c+BTrMZI9U4ZINfu0RMNHfdfy c9qQ== 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=5DZPocqARvJ2VhBFUP59zWFPA2pzWUkM0o/y8pYmFsA=; b=TLh4//HpVwY3wzt3eNdxCEexmy+a1GbG3K8IyFeYv64JCzNqyvZyNwGWe4WBfK6ER1 WGxDdi0KTUxfQ7NXllMILqYloAkkwisrzR2n4sewEbkvY0RO8Ylq8I5DcI6CmCtpPYMQ bop4Rt5Q4Q/UNR1X0uRFC3kasMZTPcsgaxToSMUYOM5UcNMZ1AkuTTauj1pY5SzfzJ1y GStIKFSLFKbyl5qYRCTzlUgKtGFdg7YOnAchXWyejO8TWll7eTrq3pY5OVMuA3peMNYK jHAF70wHrEGfih74Ca89eCG/cBwWhzLhQ8YWbkIiV+2qhAN765ei/cx1am0kWYgYIUTJ +B8g== X-Gm-Message-State: AOAM5311ExSKcXxBwJQC8BX0gyf/jcR+VwVrkdcfU1zmbrazgfMsa4zg BitM79jLcel/lVroc+fJHPkDxIlpdppnGLct X-Google-Smtp-Source: ABdhPJzrOToWEZY02T05UeRMCgcgQkkWvheRBtD+HjN401dMUC2SAN/NS8E97IDpd+hPV/fER6amECyXFjDeYS3F X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:95a:d8a8:4925:42be]) (user=andreyknvl job=sendgmr) by 2002:a5d:58ce:: with SMTP id o14mr5622327wrf.4.1615498657160; Thu, 11 Mar 2021 13:37:37 -0800 (PST) Date: Thu, 11 Mar 2021 22:37:17 +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 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-Stat-Signature: fn73nz3o91as8huxkkcjry84ycpgj3aj X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 4AD31EF Received-SPF: none (flex--andreyknvl.bounces.google.com>: No applicable sender policy available) receiver=imf12; identity=mailfrom; envelope-from="<3oY1KYAoKCO4QdThUoadlbWeeWbU.SecbYdkn-ccalQSa.ehW@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: 1615498654-582448 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 --- 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 5fe43489e94e..2f939241349d 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 Thu Mar 11 21:37:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12132953 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 CC1ADC433E0 for ; Thu, 11 Mar 2021 21:37:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6007664F8E for ; Thu, 11 Mar 2021 21:37:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6007664F8E 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 DF1D28D02FE; Thu, 11 Mar 2021 16:37:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DC9608D02B2; Thu, 11 Mar 2021 16:37:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C43BD8D02FE; Thu, 11 Mar 2021 16:37:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0175.hostedemail.com [216.40.44.175]) by kanga.kvack.org (Postfix) with ESMTP id 9DEA88D02B2 for ; Thu, 11 Mar 2021 16:37:41 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 545F25851 for ; Thu, 11 Mar 2021 21:37:41 +0000 (UTC) X-FDA: 77908905522.30.1CEB0EF Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf02.hostedemail.com (Postfix) with ESMTP id C426640001DE for ; Thu, 11 Mar 2021 21:37:31 +0000 (UTC) Received: by mail-wm1-f74.google.com with SMTP id z26so4572271wml.4 for ; Thu, 11 Mar 2021 13:37:40 -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=ftGAVPrWTX9D2SBgeD8/b0SYzBSEeTxAmVx9TpiZW0k=; b=uBQHfFhzm2iDu+GWPgLOfKqLJ0KYNn8BgixPIYHzI+DCU3dW9BounceIQ1AFuguIOG SU+Ya+w1ZMyLFw1BxUOqpkZySUt9tCHLZn2II04xfYxr8r2HdGMIspLfJskm0QdbDlM1 Wj4fJOVOZ10KEpQCSbm2eM0tdwjzEQZjL6Ej20gZuP2cDLbrVaPafbhkDCEzV+ffkFTv tY63gum3mg0FZWDmjjVpY2OXKIITHddpc5oaimHtaDHmtGF9phxr3mBX42ms5o/WgHe+ jw1J6o2/MR1IVhKBsMRH6m1qOMFU2g8pe+MW3OtT3diOUng1hMU8AOTpY51qZp8AYhJF Hgeg== 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=ftGAVPrWTX9D2SBgeD8/b0SYzBSEeTxAmVx9TpiZW0k=; b=VBWWxcEfBwi6xRg1tvIrXAuJlkpUwJR2tQvoKPc63jHf6y1qAyVYWJHpoIZdKfxAXG gYCYIiCDFbUB3OLjHRT2RjZJJvXzDqsaKXn5plTiUxQjhrOSuh6RmghDJRkgGZ9XSQ2w Ynr2hqW84YCiRHQU7HfRrskICSBsCy9ya//VybgHq3FzPRIJGYxXD/8T5/PxElPAWXB7 4rDWQbqYeP64JXaS7A578waHVyKoRT4XrrXwLPndDwGGXx/z9+H2DsVaq9SgtZF76HIh N7aj2m8zeWlvgpCi3bl3XHtJ0SXgWoko9fUex7AbBmTGM1tBaTEGQ4c4Vlwjmbchpjb3 2oxQ== X-Gm-Message-State: AOAM532g0stGSwQsAbMh/22uLSXWdCVCtFj3wWuJZWrX0FVGQISaXpdB CZx1ZC1jC+icsUVQ86ADC3D5VNL4Crgk5X/g X-Google-Smtp-Source: ABdhPJzw9BhfuLqjp9sF6FO9Ynb/tSWRnTFWIgUse0QUUiQD+MKS1Qw68XULVhuXxVxKD/fDwHS6rNaFDv13AAFT 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 w64mr1904993wmb.0.1615498659400; Thu, 11 Mar 2021 13:37:39 -0800 (PST) Date: Thu, 11 Mar 2021 22:37:18 +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 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: edoez4zxrbahn16xe83t7orc3udwgfhp X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: C426640001DE Received-SPF: none (flex--andreyknvl.bounces.google.com>: No applicable sender policy available) receiver=imf02; identity=mailfrom; envelope-from="<3o41KYAoKCPASfVjWqcfndYggYdW.Ugedafmp-eecnSUc.gjY@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: 1615498651-837538 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 --- 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 2f939241349d..1fb4b715a3ce 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 Thu Mar 11 21:37:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12132955 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 02276C433E0 for ; Thu, 11 Mar 2021 21:37:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7B4BE64F19 for ; Thu, 11 Mar 2021 21:37:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7B4BE64F19 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 0AA018D02FF; Thu, 11 Mar 2021 16:37:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0872D8D02B2; Thu, 11 Mar 2021 16:37:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E3DD78D02FF; Thu, 11 Mar 2021 16:37:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0145.hostedemail.com [216.40.44.145]) by kanga.kvack.org (Postfix) with ESMTP id C63738D02B2 for ; Thu, 11 Mar 2021 16:37:43 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 843654DD9 for ; Thu, 11 Mar 2021 21:37:43 +0000 (UTC) X-FDA: 77908905606.06.4F9DE03 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) by imf24.hostedemail.com (Postfix) with ESMTP id E1A02A0009CE for ; Thu, 11 Mar 2021 21:37:38 +0000 (UTC) Received: by mail-wr1-f74.google.com with SMTP id s10so10129276wre.0 for ; Thu, 11 Mar 2021 13:37:42 -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=gThu0TE1qL9hnbQQaxSk/qxvpsDDtC1CzspsMmD08OE=; b=SwiE2He5npvJprt4/ga+llX7ojAaiSnGKufJo3KbwrKI0MdyKm/xmoaT5N75+/BdU9 WC+y1cqw+sVbpHcx5n4ctV0zVSX/DIrtsaYoLK/pm2iQV5lB693Aar8uRhFpxZx++ik9 S7aCiEApckhoJfIMNlPJHjiigMU46WdgOGiIV1p6qPCXW3IhaBGLhblGHqAdyKqxZxYQ aOJH1yCva5uRQHxKvUrRU2yBMEdW1LYdohvTOnq9dkdphiaIGN7RJjNkH0Vc7q4hposB +GXH4NSOCvv2pOX1uJGUVZR4gmWDyxxMYbd5ip6L0RcVRrWEwcdfG+Z4XsdOv9fBFg7n 29BA== 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=gThu0TE1qL9hnbQQaxSk/qxvpsDDtC1CzspsMmD08OE=; b=ZHkvxkp3ZOr6RnIH1PIKbrkIgUEeDfnlJMziy6baBe2ycfriHeVZwGvuT2jBEp51CQ BvWjS86sX92N9F4jCBI5YNaQygealOoZM4LQLL0h9I4B+Vv616r+bBnv0VWQOCgiNvgk KyHuFGeBs9CC3B/H4Qx1DYqy1OSpTxyuMqW2QU11b6tvi5Pcuia3+U+NeAAVYeMyLJYq kUO2DBvf6yLrqBDNuPQNTFWAoP0wdvcxh8f5xlzViOr5mU9NpxYswlLoCMJpD69TPYpG vo+8EfhZI6eW/jBO3MpU0Lfbpj3MeVwR3duq4il1ki/z6ZBwZfB98xLSlvNtcJw0o9oq bi6w== X-Gm-Message-State: AOAM530EkkON7t2BRKjVqBNRRaDFRo0qyPMA7urNeMmEpkkFj8lwi3+L SgU1Km17SuSx6p8nJPOq6hIC2UdycFhHQkAk X-Google-Smtp-Source: ABdhPJzT6Acki3u676PB0Tv/dBARyH8t1RaPBLvxeQVuHtvcC5rv/V0863W+inBzbIKsqJ8x8rC70h3o60/IqeXf X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:95a:d8a8:4925:42be]) (user=andreyknvl job=sendgmr) by 2002:a1c:f614:: with SMTP id w20mr9884303wmc.70.1615498661923; Thu, 11 Mar 2021 13:37:41 -0800 (PST) Date: Thu, 11 Mar 2021 22:37:19 +0100 In-Reply-To: Message-Id: <3ec89a4e0783ff3d345310343d7ef10d46c8adb2.1615498565.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog Subject: [PATCH 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: kuitdi1ucpx3c419g8w8nzszrh5mdqbf X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: E1A02A0009CE Received-SPF: none (flex--andreyknvl.bounces.google.com>: No applicable sender policy available) receiver=imf24; identity=mailfrom; envelope-from="<3pY1KYAoKCPIUhXlYsehpfaiiafY.Wigfchor-ggepUWe.ila@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: 1615498658-207562 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 --- 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 1fb4b715a3ce..dff18e180120 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 Thu Mar 11 21:37:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12132957 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 E3F20C433E6 for ; Thu, 11 Mar 2021 21:37:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 84BED64F8E for ; Thu, 11 Mar 2021 21:37:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 84BED64F8E 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 16EA18D0300; Thu, 11 Mar 2021 16:37:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0FBBE8D02B2; Thu, 11 Mar 2021 16:37:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EDA658D0300; Thu, 11 Mar 2021 16:37:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0254.hostedemail.com [216.40.44.254]) by kanga.kvack.org (Postfix) with ESMTP id CE3FC8D02B2 for ; Thu, 11 Mar 2021 16:37:45 -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 8DC695DC1 for ; Thu, 11 Mar 2021 21:37:45 +0000 (UTC) X-FDA: 77908905690.18.09A6FB4 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) by imf21.hostedemail.com (Postfix) with ESMTP id 34035E0011DD for ; Thu, 11 Mar 2021 21:37:43 +0000 (UTC) Received: by mail-wr1-f73.google.com with SMTP id z17so10116108wrv.23 for ; Thu, 11 Mar 2021 13:37:44 -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=jCUwUXSRYRP2LJ367pVG9mu783jEZOVPApZYYYorTcY=; b=Plz1xq3SLytyAFVQRIdDqpfeMoVJQVQnjL8v5eLWlHpRU3ZXHwZ7nNYQwGHB8jkEl0 oec/CqXdexSMPCB/xEQc8lqn+4mP/LOkm0oqY//jnkP3wzYEtNThi7FOfPPphX4RmoFE ao0BmeAMJqqGLTJkM09Ht/ur6e2pTnhYW0cyFZmYZTeP54Hg1c8nULI2bpOngYV9skI4 nlX9Ks5TI8iw8G6P5wTshuA2NBNFjML5xjZ2/0seUMwzVpI2lSb/a5NuFtLu1Z6COWrK /Zj1Uzg5xBCAF7rntkf4bj4+xzxSqLYPE/b+KjqGXV1+z3P9U99E669EFLETrkPaiJWQ MQug== 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=jCUwUXSRYRP2LJ367pVG9mu783jEZOVPApZYYYorTcY=; b=MfD6uIFO9TGg3AXkAOOc5IzA/HHqOX6I5s8YqQdumELqUhuC6p4/dus1DjHkRTks60 p7zW9oNqmhlXFx4hPGnLoLVF2yCwRzWat/Yml2w0AArVeTU4zVeE3Zgwark+84/VLdwT vQ9eyFyu6T5KRzxySNQBJ6khO7d4KJ5on2L14byNtpLaNf9A+KWTfwI58zwCtOyjAUv7 /a9/1Infy1cYEoxzPGFZS1MjhPnHevAj59DknRs4xL6nn39YeBUm0k8dZvlg8iUeyEOY P/UFK2AejuutadnTcbHZtuW42KRmBkzLYvCh03xbOAsJ0+aTTJVCJeoeiQO2q5PNmVgh hCkQ== X-Gm-Message-State: AOAM5305sqTsmD7mZk5Jyl7eRrlBJ+RmuaznKcU14ctbelwL2nS8AA7k Cshavjc0tQx2xPsh/iRyFhBD+E5xbc39Aaj2 X-Google-Smtp-Source: ABdhPJy84LzHn4mR19rjSQ67/EMk7xl1CZfA7JzaPJm1mLIqYkbPLMRC4CDyeZ6DR1cH6gpwHsKjcZ2idgfZSv0y X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:95a:d8a8:4925:42be]) (user=andreyknvl job=sendgmr) by 2002:a7b:c0c4:: with SMTP id s4mr10327657wmh.9.1615498664022; Thu, 11 Mar 2021 13:37:44 -0800 (PST) Date: Thu, 11 Mar 2021 22:37:20 +0100 In-Reply-To: Message-Id: <318ca25e3e3d32482c0155b662ce4057e436f9cd.1615498565.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog Subject: [PATCH 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: uoyyr11s36abo6fa7kgqxwtdrob4tda7 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 34035E0011DD Received-SPF: none (flex--andreyknvl.bounces.google.com>: No applicable sender policy available) receiver=imf21; identity=mailfrom; envelope-from="<3qI1KYAoKCPUXkaobvhksidlldib.Zljifkru-jjhsXZh.lod@flex--andreyknvl.bounces.google.com>"; helo=mail-wr1-f73.google.com; client-ip=209.85.221.73 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615498663-646996 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 --- 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 dff18e180120..f5c746a475c1 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 Thu Mar 11 21:37:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12132959 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 0E260C433DB for ; Thu, 11 Mar 2021 21:37:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9FA6664F8E for ; Thu, 11 Mar 2021 21:37:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9FA6664F8E 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 2327A8D0301; Thu, 11 Mar 2021 16:37:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1E3678D02B2; Thu, 11 Mar 2021 16:37:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F29DF8D0301; Thu, 11 Mar 2021 16:37:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0047.hostedemail.com [216.40.44.47]) by kanga.kvack.org (Postfix) with ESMTP id C67878D02B2 for ; Thu, 11 Mar 2021 16:37:47 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 7EBC54DD9 for ; Thu, 11 Mar 2021 21:37:47 +0000 (UTC) X-FDA: 77908905774.09.D04BE35 Received: from mail-qk1-f202.google.com (mail-qk1-f202.google.com [209.85.222.202]) by imf11.hostedemail.com (Postfix) with ESMTP id 25159200039B for ; Thu, 11 Mar 2021 21:37:41 +0000 (UTC) Received: by mail-qk1-f202.google.com with SMTP id v136so16710976qkb.9 for ; Thu, 11 Mar 2021 13:37: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=ftjCjXXHVhB6VMD5t3OFCFAtHdmXgYbSUPbbr/Gj6M0=; b=ESbdDH1dGDyJVOngrIaGau1OqUj/sBoi5iMhooMRu0pkICXzAdcFpDb2Ul/KLNFn99 lZofYcZStifebLYgoQqfyIDIDZPygmK4tKz809cgrrLgeaEFORYIMtasnVGJEyJjHkEa E/K8ivFsvqiyEa4HwIB6Mh9BfTO+xCkQwFnZciD1y6y3RDdaejO3SsIpy7ww3zplxkd+ 4Wgy/It2jaGw6T7SoFg+2X2fAIar9JEXkV+lEzvZvRf/69TJ2BhSbH7NeIqQD0PmVu7j M7miv5kkKHtosvttGtJ9aFfUacFCA102qbBPhQO2Ciwz4rvUYeRTH2j682GaHq76n11H IwSw== 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=ftjCjXXHVhB6VMD5t3OFCFAtHdmXgYbSUPbbr/Gj6M0=; b=HO6jltnyz7mGnV3q0pwfuVQRqg8uuVeu+ET6WKbcqgKAE3VEif/GQQSYYQdukf69k9 Q3FCFy3KO+b+nZhnLPxpgPGDm2KawD0LWub1+Vx4xTwhf8zE1RZ6jrfbiIcfgyomAJjS XHCmcKBnt/WZ1DbwSEVhPMqSi67kiCoHkqlDMuZdgDJAlSCu4bbaFGh/JAYkj6iFErVt YEeGUyuAJlmigYm3s+Z/5vwnjXs7XIiqDt4mP+eMt66EkBZDTkAG/091OMGh8WmQmjkM HXY7Z5cQ1iFvYo+nXZ8WJa0/qzdmYI0btkTw/UN9pXZxk6pNv7JFSgbOiQIQlMWG8GVv vbyw== X-Gm-Message-State: AOAM531nU3SluylqBC4yffjwCt7OtJ/S/YO022bNRcCqNSlZj/YIGvlr +McUgDorLyLscjuDX3gFp5wxt/fj3xa4k8Om X-Google-Smtp-Source: ABdhPJwFsJ/N2kQI02XbYli6/SkAk6ET46Rz0VOBGBv3Tz8ry16DmHWricMbKll1+JUskKpcAbZIV5B73rdZviTd X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:95a:d8a8:4925:42be]) (user=andreyknvl job=sendgmr) by 2002:a0c:f541:: with SMTP id p1mr9682518qvm.14.1615498666324; Thu, 11 Mar 2021 13:37:46 -0800 (PST) Date: Thu, 11 Mar 2021 22:37:21 +0100 In-Reply-To: Message-Id: <6cb4988a241f086be7e7df3eea79416a53377ade.1615498565.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog Subject: [PATCH 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: jqs7wbdbuzky8qyw1ahwjf71zzwdw97o X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 25159200039B Received-SPF: none (flex--andreyknvl.bounces.google.com>: No applicable sender policy available) receiver=imf11; identity=mailfrom; envelope-from="<3qo1KYAoKCPcZmcqdxjmukfnnfkd.bnlkhmtw-lljuZbj.nqf@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: 1615498661-832285 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 --- 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 f5c746a475c1..2b61d90e136f 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. By default ~~~~~~~~~~ @@ -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 Thu Mar 11 21:37:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12132961 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 37304C433E6 for ; Thu, 11 Mar 2021 21:37:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C187964F19 for ; Thu, 11 Mar 2021 21:37:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C187964F19 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 53EEA8D0302; Thu, 11 Mar 2021 16:37:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4EFB68D02B2; Thu, 11 Mar 2021 16:37:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3681F8D0302; Thu, 11 Mar 2021 16:37:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0231.hostedemail.com [216.40.44.231]) by kanga.kvack.org (Postfix) with ESMTP id 15A1C8D02B2 for ; Thu, 11 Mar 2021 16:37:50 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id C793F1806913E for ; Thu, 11 Mar 2021 21:37:49 +0000 (UTC) X-FDA: 77908905858.21.D278274 Received: from mail-qk1-f201.google.com (mail-qk1-f201.google.com [209.85.222.201]) by imf13.hostedemail.com (Postfix) with ESMTP id 39568E0011E1 for ; Thu, 11 Mar 2021 21:37:47 +0000 (UTC) Received: by mail-qk1-f201.google.com with SMTP id o70so16661934qke.16 for ; Thu, 11 Mar 2021 13:37:49 -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=d9MD7r+sgefmh6olz506jW43mtPrrCIc3sAEHbrSzj8=; b=ax/rWBbWgfFBi82AU51k9wa1iavqd4Vuv9RUjEWuwWfeWHXtSnX5LFRCyJqlXJfA+W hm1ViC5eQNv6WM0R5WEHJWm1s+Ffj+2G2yuaPXOQny71MI+E7RKHxtVS3De7jyJgvPb1 zBCFJM8tCCXPX/qoWnKZ6FsBO/dnl6Bhc4xLB6jKSvLRtzrTs4djQiwD/8TUzNKrG3j8 gTgtdYh83bQOReTyQLwntQqCzVCikVRaETyy20dw1nOiXapJ5sD0BVRrRr1sCoM+5KVH A5y9ja1C+hbayglpaYIVouChO09VKiH6xoX3Anq/06nYhdxGkt+Xc1XAlrRDvWfHct3N P/Ug== 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=d9MD7r+sgefmh6olz506jW43mtPrrCIc3sAEHbrSzj8=; b=pJ84Uc8MdDEeDKUUilTkf2TNHgtDXWVQDMsdZsVeB9LMJ8918E3dikaXP7wxDCGmZK pv7x6ZE2tB7JdwK7/yIBZVzN85CQ2IgZ6q/qErqKaWkRB1VY5FHg/IrCmZwLW7KJgCbV TwoAgyb3BujdPKPAgYwfrxot+Pl250NoUXJBU0vQyac7QVn4t2olnpqAUCYL+JqA+a6b NKaHJndnzUrjDIURVq23HfoYRdCKJlZI8Aggy4S/P5a6pfJfSHOniCUUrXTfOA2gdiR+ yKco6YPcAlMIxPRTWZQIB3fnJpgJdt7Uyk1W5n0xCRAcIvK06D49IOgDKmgTLXCuI5HF wtWg== X-Gm-Message-State: AOAM531UPzMvIRowcrHz7qwUOnaX2xAwMOfyQXgEGHGyF1Umu4a5W1E3 ZUeg9l3lRE/g+TkJIfet0PPVyctL//3sHdlk X-Google-Smtp-Source: ABdhPJzpQZgOsi+fHQ89WFEZlxVp3IMtBdkjlpY0sJb25JmmNWaJDjP0pxKw0uMn7urnS6/1TroiVIGrltIjMgy0 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:95a:d8a8:4925:42be]) (user=andreyknvl job=sendgmr) by 2002:a0c:9cc2:: with SMTP id j2mr6061470qvf.2.1615498668637; Thu, 11 Mar 2021 13:37:48 -0800 (PST) Date: Thu, 11 Mar 2021 22:37:22 +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 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-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 39568E0011E1 X-Stat-Signature: fsg8e6asp7yb8ctzfibnnc6gy5i1zimb Received-SPF: none (flex--andreyknvl.bounces.google.com>: No applicable sender policy available) receiver=imf13; identity=mailfrom; envelope-from="<3rI1KYAoKCPkboesfzlowmhpphmf.dpnmjovy-nnlwbdl.psh@flex--andreyknvl.bounces.google.com>"; helo=mail-qk1-f201.google.com; client-ip=209.85.222.201 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615498667-28848 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 kasan_disable/enable_current(). - Mention kasan_reset_tag()/page_kasan_tag_reset(). - A punctuation clean-up. Signed-off-by: Andrey Konovalov --- Documentation/dev-tools/kasan.rst | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Documentation/dev-tools/kasan.rst b/Documentation/dev-tools/kasan.rst index 2b61d90e136f..6628b133c9ad 100644 --- a/Documentation/dev-tools/kasan.rst +++ b/Documentation/dev-tools/kasan.rst @@ -368,7 +368,7 @@ Ignoring accesses ~~~~~~~~~~~~~~~~~ Software KASAN modes use compiler instrumentation to insert validity checks. -Such instrumentation might be incompatible with some part of the kernel, and +Such instrumentation might be incompatible with some parts 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: @@ -381,6 +381,19 @@ Makefile: KASAN_SANITIZE := n +Other parts of the kernel might access metadata for allocated objects. Normally, +KASAN detects and reports such accesses, but in certain cases (e.g., in memory +allocators) these accesses are valid. Disabling instrumentation for memory +allocators files helps with accesses that happen directly in that code for +software KASAN modes. But it does not help when the accesses happen indirectly +(through generic function calls) or with the hardware tag-based mode that does +not use compiler instrumentation. + +To disable KASAN reports in a certain part of the kernel code: + +- For software modes, add a + ``kasan_disable_current()``/``kasan_enable_current()`` critical section. +- For tag-based modes, use ``kasan_reset_tag()`` or ``page_kasan_tag_reset()``. Tests ~~~~~ From patchwork Thu Mar 11 21:37:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12132963 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 33151C433DB for ; Thu, 11 Mar 2021 21:37:54 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BB6B364F86 for ; Thu, 11 Mar 2021 21:37:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BB6B364F86 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 479FC8D0303; Thu, 11 Mar 2021 16:37:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 450368D02B2; Thu, 11 Mar 2021 16:37:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2F2FD8D0303; Thu, 11 Mar 2021 16:37:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0170.hostedemail.com [216.40.44.170]) by kanga.kvack.org (Postfix) with ESMTP id 0C08E8D02B2 for ; Thu, 11 Mar 2021 16:37:53 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id B3CE3181200EF for ; Thu, 11 Mar 2021 21:37:52 +0000 (UTC) X-FDA: 77908905984.26.95CC68B Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf26.hostedemail.com (Postfix) with ESMTP id 89254407F8F8 for ; Thu, 11 Mar 2021 21:37:49 +0000 (UTC) Received: by mail-wm1-f74.google.com with SMTP id i14so4547375wmq.7 for ; Thu, 11 Mar 2021 13:37: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=KqyiEXFZVlJ5WAkVIpzRsNvJDBTABYowTYxavN0wmPI=; b=vUKUWADTysn9YczPlnO53jYKYuLAG9pNDM0DXT3f6YdB5w4mlKOmJqqd/tGTFSDvdz FmsShTL8D6d0ayHAepOJQVXj6AG/O2j0fCohJgEu2atXg3/J7rnfGbzdfZsoaBK3bZxi z5M3Ow0kLuVo2gzEXn+ojysuZqAr8xxsoV2+0IBsNpSKpkaX2/LXzYoZmELq3zE/kcDI 5O0eoEngZSfqEs8uWMaNzHom/AdhnIyjGWxB05yQPbAUUauSNqVHffFtOZ82AOwuXlPj uCOuEZkmUGrmqVaQDNPBWHyTL/ZYjJzMyeWMp3VVc0ywHL5DEVEM8Z1FYSOtQBykGMlU HZAg== 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=KqyiEXFZVlJ5WAkVIpzRsNvJDBTABYowTYxavN0wmPI=; b=P3cEoT18cUuSceOsGtkp67pgbnrCS0pfgfSQoeBSXYncjqzHdqmy62V4ynXzFxJ2Il eEGi8m/0PY7wv/S0WhnQ3MNVS718H8laZCerH4gbqMdgS9JQ+2aFGb9/grCYrhz8yXeV 9zRcXSWgDO8Kj0jneWER28Ma0AYqFhfZEMwPQ91uFyQkL0tJ4/EuWOE71yTE+8UwYcyT mYocFw8DF8y6TNNRuYRhxiW46v/raYVcJGKJGLSwUus6lGPBkUV6TO3EsQmHwgWrP2kA 7KxmKo7ClNknraETO1HV82/mklyPUZMnqNuNsz/cA+zNqLg8cOf9yX+Jm0nkfHyhfYBR 1OlA== X-Gm-Message-State: AOAM530Kh1G4uTOsr+QG3iZ7wxikdUCkj/Epa8vmSdPdQctgIwnF5DYv b04aFp9WkVTmeN2eyQFSdrhUonEe/gzGGPEY X-Google-Smtp-Source: ABdhPJwPI7MXwIggsu0PIhpFTdjlAk8f4pD+e/W64RlEyitc321VCJDbT5aPSUC15RhN1r5iSJ07BSbs/d8EUiHp X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:95a:d8a8:4925:42be]) (user=andreyknvl job=sendgmr) by 2002:a7b:cc84:: with SMTP id p4mr10172254wma.10.1615498671258; Thu, 11 Mar 2021 13:37:51 -0800 (PST) Date: Thu, 11 Mar 2021 22:37:23 +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 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: t93razzbffs8h9x6i1dsqxzsf836cp9r X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 89254407F8F8 Received-SPF: none (flex--andreyknvl.bounces.google.com>: No applicable sender policy available) receiver=imf26; identity=mailfrom; envelope-from="<3r41KYAoKCPwerhvi2orzpksskpi.gsqpmry1-qqozego.svk@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: 1615498669-55129 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 --- Documentation/dev-tools/kasan.rst | 33 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/Documentation/dev-tools/kasan.rst b/Documentation/dev-tools/kasan.rst index 6628b133c9ad..c4a3c8a9fe71 100644 --- a/Documentation/dev-tools/kasan.rst +++ b/Documentation/dev-tools/kasan.rst @@ -398,19 +398,20 @@ To disable KASAN reports in a certain part of the kernel code: 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:: @@ -438,27 +439,25 @@ 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 the `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