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