Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1283713pxf; Fri, 12 Mar 2021 06:26:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJwmZEzuJm3YEoymKOoR03RmUkjrknwtVFDQapk9SaAX6xfNiuox7A1qQeiSH5EVQ8aQvqrK X-Received: by 2002:a05:6402:3550:: with SMTP id f16mr14312924edd.134.1615559205441; Fri, 12 Mar 2021 06:26:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615559205; cv=none; d=google.com; s=arc-20160816; b=hVEPespx6qDbuMC3pNLH4Aqp57Av39xs0tr8pU00hPc6z4kiMQq7qZDGz4EQcGHHRx 5Uj59oL7mCJrWje6oEX9/ZBTePIb2iOhum7Sx4HipAhvLCbJOhDcO0SIB1htLM63sqyL YLukCbjAOeREgqNcUsf0bwNGPdDl8SuwExcbK7yJGjmlIlL6Jgyv0ljM1tEd/oERQqdM 2M2kTzvuvK2G+eR2zoVvHlDIe9ERbVIm8UcwLkfL9SgWHYRp0sroaG/j5IABc/ftdSXK JKqOBXvQW/p48kwxmMf2kcWKEJHmEQ+b4N90VXcsnJ2pL8PeZ36aFsZVTNB73l4kzsvm 2wcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=0tHYzYXuuuKT6r1BbOh9jnZkvIRx4Zusj9wo+yaKFLc=; b=Jx6bxkUd/EPfqXeMBXdFF3xHlz2b6fDYBAqHZitTu4odSvm+0r2VxM/2p6doywxB1g FtvIjAjmPOos7V2ZFtKUKmXUxDWbkBq61fxc83p/hVchaOEMm3K49nk+hsanvho0DG0o D8eiRHKAb0t4NqB3wXhfEis0+K3zWf9SIHbIgujQYgQ03iYoJmSzPcryC7npyb7G/FnI 6JjCwUoH/vjt6sipKc1wg6GnGkXqK4sfVM8VXdT4WKzCHwoq3BWuHG9KkWFT/Nk83prI C7O+fQOi/gD8oKSvBYjHQYUdKuXGqtJ88VmDf+uJGvPBiTnJwnaNjF60xOALdAnufSDe B/hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=sNp2DgDm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p31si4308114edb.526.2021.03.12.06.26.22; Fri, 12 Mar 2021 06:26:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=sNp2DgDm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232213AbhCLOY7 (ORCPT + 99 others); Fri, 12 Mar 2021 09:24:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232217AbhCLOYr (ORCPT ); Fri, 12 Mar 2021 09:24:47 -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 96EABC061574 for ; Fri, 12 Mar 2021 06:24:46 -0800 (PST) Received: by mail-wm1-x349.google.com with SMTP id c9so2104666wme.5 for ; Fri, 12 Mar 2021 06:24:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=0tHYzYXuuuKT6r1BbOh9jnZkvIRx4Zusj9wo+yaKFLc=; b=sNp2DgDmylfnS/Ht/6f++D6EQH9D86XWw0M6iwarW68/F2DW3jJ2h1ksTDPv3+/C87 pHHYdYTwSOZDZjMyEBULBU3suACHGMtTYH+xUFvBQeSNvTX9u3GDd7/iCHmjVjv2oVGP d9ID8wr2BDrtrTAySXF+Y+WnlUlluKg7uZ6kVckHBZmDAAjE7wjwmqulaTSlQTXX7Qnn 2wZltVoSlSUohS/adb26/ByRLH5goLNkjBZYV5ddzvTVOlzN9fb1BYBCDYUUxR0a0ynv cxoDzqrQv+n3qwNxzHuWgzmpGozNfTqC8HnfSYaC7PGEqZ4ZPv1lDOUdpNuzcd9cdWvo jIAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=0tHYzYXuuuKT6r1BbOh9jnZkvIRx4Zusj9wo+yaKFLc=; b=PpWE5VZoOZhKjq9Jt02wPzkpppSbPI6NLw0PplVZH897UWklDy4ZrKsOfa8vmFiPoR CVB3/gOxgcIUW2m61aJW8ZipI8v/CoVrXbtTWL470nHzy0yr78w8/R/Dipe81oA98heR 7PtDb/6cXZ94sZcUgCYjVRm1UVKhRVLU+smJnG0w08w2SpHqJBW6ANlM6a+u3mImzoGS RyJ1oZ1n86h3SsNrwUg+mRB+9VMDZ/D7GVbMmllxHbYzYcjOwwkno19R+Vjanw4LQz2I Q98WSXZ+EOKjxMQh88HLXAotajI8AO0DI3lBferwOMLDEmNot9R7gxxWtqMbnMqzVrFV 1/6Q== X-Gm-Message-State: AOAM530Q7LBysej2mDyBv/YnbjMrIcx5tpgjqsQB4jJfyKPhSebzMM9J J+sHhi1nVR052q6ZM33n4GOSH28rshHLmy5E X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:95a:d8a8:4925:42be]) (user=andreyknvl job=sendgmr) by 2002:a1c:4145:: with SMTP id o66mr8525472wma.68.1615559085218; Fri, 12 Mar 2021 06:24:45 -0800 (PST) Date: Fri, 12 Mar 2021 15:24:27 +0100 In-Reply-To: Message-Id: <3531e8fe6972cf39d1954e3643237b19eb21227e.1615559068.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog Subject: [PATCH v2 04/11] kasan: docs: update error reports section From: Andrey Konovalov To: Andrew Morton , Alexander Potapenko , Marco Elver Cc: Andrey Ryabinin , Dmitry Vyukov , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 46f4e9680805..cd12c890b888 100644 --- a/Documentation/dev-tools/kasan.rst +++ b/Documentation/dev-tools/kasan.rst @@ -60,7 +60,7 @@ physical pages, enable ``CONFIG_PAGE_OWNER`` and boot with ``page_owner=on``. Error reports ~~~~~~~~~~~~~ -A typical out-of-bounds access generic KASAN report looks like this:: +A typical KASAN report looks like this:: ================================================================== BUG: KASAN: slab-out-of-bounds in kmalloc_oob_right+0xa8/0xbc [test_kasan] @@ -133,33 +133,43 @@ A typical out-of-bounds access generic KASAN report looks like this:: ffff8801f44ec400: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc ================================================================== -The header of the report provides a short summary of what kind of bug happened -and what kind of access caused it. It's followed by a stack trace of the bad -access, a stack trace of where the accessed memory was allocated (in case bad -access happens on a slab object), and a stack trace of where the object was -freed (in case of a use-after-free bug report). Next comes a description of -the accessed slab object and information about the accessed memory page. +The report header summarizes what kind of bug happened and what kind of access +caused it. It is followed by a stack trace of the bad access, a stack trace of +where the accessed memory was allocated (in case a slab object was accessed), +and a stack trace of where the object was freed (in case of a use-after-free +bug report). Next comes a description of the accessed slab object and the +information about the accessed memory page. -In the last section the report shows memory state around the accessed address. -Internally KASAN tracks memory state separately for each memory granule, which +In the end, the report shows the memory state around the accessed address. +Internally, KASAN tracks memory state separately for each memory granule, which is either 8 or 16 aligned bytes depending on KASAN mode. Each number in the memory state section of the report shows the state of one of the memory granules that surround the accessed address. -For generic KASAN the size of each memory granule is 8. The state of each +For generic KASAN, the size of each memory granule is 8. The state of each granule is encoded in one shadow byte. Those 8 bytes can be accessible, -partially accessible, freed or be a part of a redzone. KASAN uses the following -encoding for each shadow byte: 0 means that all 8 bytes of the corresponding +partially accessible, freed, or be a part of a redzone. KASAN uses the following +encoding for each shadow byte: 00 means that all 8 bytes of the corresponding memory region are accessible; number N (1 <= N <= 7) means that the first N bytes are accessible, and other (8 - N) bytes are not; any negative value indicates that the entire 8-byte word is inaccessible. KASAN uses different negative values to distinguish between different kinds of inaccessible memory like redzones or freed memory (see mm/kasan/kasan.h). -In the report above the arrows point to the shadow byte 03, which means that -the accessed address is partially accessible. For tag-based KASAN modes this -last report section shows the memory tags around the accessed address -(see the `Implementation details`_ section). +In the report above, the arrow points to the shadow byte ``03``, which means +that the accessed address is partially accessible. + +For tag-based KASAN modes, this last report section shows the memory tags around +the accessed address (see the `Implementation details`_ section). + +Note that KASAN bug titles (like ``slab-out-of-bounds`` or ``use-after-free``) +are best-effort: KASAN prints the most probable bug type based on the limited +information it has. The actual type of the bug might be different. + +Generic KASAN also reports up to two auxiliary call stack traces. These stack +traces point to places in code that interacted with the object but that are not +directly present in the bad access stack trace. Currently, this includes +call_rcu() and workqueue queuing. Boot parameters ~~~~~~~~~~~~~~~ @@ -214,10 +224,6 @@ function calls GCC directly inserts the code to check the shadow memory. This option significantly enlarges kernel but it gives x1.1-x2 performance boost over outline instrumented kernel. -Generic KASAN also reports the last 2 call stacks to creation of work that -potentially has access to an object. Call stacks for the following are shown: -call_rcu() and workqueue queuing. - Generic KASAN is the only mode that delays the reuse of freed object via quarantine (see mm/kasan/quarantine.c for implementation). -- 2.31.0.rc2.261.g7f71774620-goog