From mboxrd@z Thu Jan 1 00:00:00 1970 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=unavailable 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 1FE5CC433E6 for ; Thu, 11 Mar 2021 21:38:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CE07764F89 for ; Thu, 11 Mar 2021 21:38:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231264AbhCKViO (ORCPT ); Thu, 11 Mar 2021 16:38:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229688AbhCKVhl (ORCPT ); Thu, 11 Mar 2021 16:37:41 -0500 Received: from mail-wm1-x349.google.com (mail-wm1-x349.google.com [IPv6:2a00:1450:4864:20::349]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21FA6C061574 for ; Thu, 11 Mar 2021 13:37:41 -0800 (PST) Received: by mail-wm1-x349.google.com with SMTP id f9so4580121wml.0 for ; Thu, 11 Mar 2021 13:37:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=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=aa1fGoTmO1EQ2j775pfepcc9tWKBlE5ON1VuOorrP80LQEDNTe/g/gdi5iy3rVAWO8 kXmSn/ZSk4aqlAY2HIdQ4ssFc2NXoOiI9TJRaGVy79ds1N+GQ+Hp0Qnf5J67aM7wGnlJ 7963ZX2NeGGZKOrdd6uLhP5Yisre1x0mAv5dZj3uQ5Mq2Z9xZzefKdqFr7GgFH1Nxy+t jQBUWPQr9p1eqvA9fTL8p+nZkAMIJsOu2y6C/DryaXUmRtMNEhLda6nah2dPQqWJt2qI 9hRvCHbwIezNn1uWLMRa0smEjt/vtc416SCdNrq06ErxvaA5/S7PIlNqQJlJHpp9rd3y yLHg== X-Gm-Message-State: AOAM532gQ9gS7sWMxndhz0blywz2cJDkLNXH4gfXEyZmk1rHRELgbBcW Wcf3ezBg/pqDxrHW6cipOyck7yGiA6z21xFo 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 -- 2.31.0.rc2.261.g7f71774620-goog