From patchwork Fri Mar 12 14:24:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12134801 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D348C433E0 for ; Fri, 12 Mar 2021 14:25:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AD75D64FAD for ; Fri, 12 Mar 2021 14:25:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AD75D64FAD Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id CD2978D0363; Fri, 12 Mar 2021 09:24:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CACA78D0361; Fri, 12 Mar 2021 09:24:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AB40F8D0363; Fri, 12 Mar 2021 09:24:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0181.hostedemail.com [216.40.44.181]) by kanga.kvack.org (Postfix) with ESMTP id 873E08D0361 for ; Fri, 12 Mar 2021 09:24:59 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 4A0D98248047 for ; Fri, 12 Mar 2021 14:24:59 +0000 (UTC) X-FDA: 77911443918.20.EE5B61F Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) by imf05.hostedemail.com (Postfix) with ESMTP id 43DAAE0011F1 for ; Fri, 12 Mar 2021 14:24:58 +0000 (UTC) Received: by mail-wr1-f74.google.com with SMTP id x9so11128346wro.9 for ; Fri, 12 Mar 2021 06:24:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=hsoBR6E8KwmiptK80mQJVFHGCa6Vkbo97hvfJKQe5xQ=; b=nXr9UV9/9WyaC3EuPXvNItYFgOiSTCllvCD62KSIp5FuIWKW2sehJhoVxOzJHwG0nM HBvRceqCBfxy5QZQ8RhSJZStHtOCO5xFbRirjQD5la/YLw9YNoyHYoX/5RHAcnnB05i8 hwoJG4k8syFN3DX6r9GGeUdwDKgBTVIjZFQfXSdsmKouxKEm2gt3/p1VDjKC2n5/PaKi peeT2zCt8NU8nDHv/SQm83n2z0M7vI7igfgOfh3DP0nSJbcsjocnofOhglvTKhu/puwI e2SS3RL7DKdVfWtlWlRLg3SXrDzNN2sLem82/rAYCCNcIAJjbtLJr6Hp6OWM0to4U5E9 Y5UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=hsoBR6E8KwmiptK80mQJVFHGCa6Vkbo97hvfJKQe5xQ=; b=Y6DsG4kA5hpBwm3jyPkMZ0cw7ndFpXo3Kga0nzPEsRQWuYSt+pDcUPdXBpPRBSGA1W isBhB+bCr1N5IjSA1oLb1u4pCNkD4zVi5S0dRGDdqvETeoLITcWZm1ycjYg23OmzYAI2 IsarUphwe9S8WbP0PITzzmrvTPthCQ5MazTK61Z0TupqrqbXrtvbxEHYR55BXRvyRatG X65nOsqXXE8qhgQhwoJpc3kGWaDF89q383ZM2cIHgqUyaVXB1JXl50/yFVtAYE48VPpt 2BpOlrMEk7T2bo1sffBdWrxXNW7x8luU5MUDeMi7HvTWD0iXfIzf4YYypCzorsiKaRaJ WfFQ== X-Gm-Message-State: AOAM533G+XQXu4d9hEHSA7adfackyp2bzIHptBv9pH6XNg0gK5dOplXS n62/bdqpR/k+iPIhw6L6B+dQdMyBOHgxnas1 X-Google-Smtp-Source: ABdhPJyEhPq1Wz4x+ftqnbQ2CgJ1RQOONDh7PhI/3hzsY1YVuFsBuC/M2n6BPRMzRPBwd+DmE1BUthENEHm+4VyD X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:95a:d8a8:4925:42be]) (user=andreyknvl job=sendgmr) by 2002:a1c:6243:: with SMTP id w64mr2250680wmb.0.1615559097271; Fri, 12 Mar 2021 06:24:57 -0800 (PST) Date: Fri, 12 Mar 2021 15:24:32 +0100 In-Reply-To: Message-Id: <00f8c38b0fd5290a3f4dced04eaba41383e67e14.1615559068.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog Subject: [PATCH v2 09/11] kasan: docs: update shadow memory section From: Andrey Konovalov To: Andrew Morton , Alexander Potapenko , Marco Elver Cc: Andrey Ryabinin , Dmitry Vyukov , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Stat-Signature: zozk39y176hgod449y775n6f93jjr6p9 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 43DAAE0011F1 Received-SPF: none (flex--andreyknvl.bounces.google.com>: No applicable sender policy available) receiver=imf05; identity=mailfrom; envelope-from="<3uXlLYAoKCOIERHVIcORZPKSSKPI.GSQPMRYb-QQOZEGO.SVK@flex--andreyknvl.bounces.google.com>"; helo=mail-wr1-f74.google.com; client-ip=209.85.221.74 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615559098-791962 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Update the "Shadow memory" section in KASAN documentation: - Rearrange the introduction paragraph do it doesn't give a "KASAN has an issue" impression. - Update the list of architectures with vmalloc support. - Punctuation, readability, and other minor clean-ups. Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver --- Documentation/dev-tools/kasan.rst | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/Documentation/dev-tools/kasan.rst b/Documentation/dev-tools/kasan.rst index 2744ae6347c6..d0c1796122df 100644 --- a/Documentation/dev-tools/kasan.rst +++ b/Documentation/dev-tools/kasan.rst @@ -304,14 +304,11 @@ checking gets disabled. Shadow memory ------------- -The kernel maps memory in a number of different parts of the address -space. This poses something of a problem for KASAN, which requires -that all addresses accessed by instrumented code have a valid shadow -region. - -The range of kernel virtual addresses is large: there is not enough -real memory to support a real shadow region for every address that -could be accessed by the kernel. +The kernel maps memory in several different parts of the address space. +The range of kernel virtual addresses is large: there is not enough real +memory to support a real shadow region for every address that could be +accessed by the kernel. Therefore, KASAN only maps real shadow for certain +parts of the address space. Default behaviour ~~~~~~~~~~~~~~~~~ @@ -323,10 +320,9 @@ page is mapped over the shadow area. This read-only shadow page declares all memory accesses as permitted. This presents a problem for modules: they do not live in the linear -mapping, but in a dedicated module space. By hooking in to the module -allocator, KASAN can temporarily map real shadow memory to cover -them. This allows detection of invalid accesses to module globals, for -example. +mapping but in a dedicated module space. By hooking into the module +allocator, KASAN temporarily maps real shadow memory to cover them. +This allows detection of invalid accesses to module globals, for example. This also creates an incompatibility with ``VMAP_STACK``: if the stack lives in vmalloc space, it will be shadowed by the read-only page, and @@ -337,9 +333,10 @@ CONFIG_KASAN_VMALLOC ~~~~~~~~~~~~~~~~~~~~ With ``CONFIG_KASAN_VMALLOC``, KASAN can cover vmalloc space at the -cost of greater memory usage. Currently this is only supported on x86. +cost of greater memory usage. Currently, this is supported on x86, +riscv, s390, and powerpc. -This works by hooking into vmalloc and vmap, and dynamically +This works by hooking into vmalloc and vmap and dynamically allocating real shadow memory to back the mappings. Most mappings in vmalloc space are small, requiring less than a full @@ -358,10 +355,10 @@ memory. To avoid the difficulties around swapping mappings around, KASAN expects that the part of the shadow region that covers the vmalloc space will -not be covered by the early shadow page, but will be left -unmapped. This will require changes in arch-specific code. +not be covered by the early shadow page but will be left unmapped. +This will require changes in arch-specific code. -This allows ``VMAP_STACK`` support on x86, and can simplify support of +This allows ``VMAP_STACK`` support on x86 and can simplify support of architectures that do not have a fixed module region. For developers