Message ID | cover.1658189199.git.andreyknvl@google.com (mailing list archive) |
---|---|
Headers | show
Return-Path: <owner-linux-mm@kvack.org> X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9BFAEC43334 for <linux-mm@archiver.kernel.org>; Tue, 19 Jul 2022 00:10:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 071848E0001; Mon, 18 Jul 2022 20:10:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F3A716B0074; Mon, 18 Jul 2022 20:10:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DDB078E0001; Mon, 18 Jul 2022 20:10:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C583F6B0074 for <linux-mm@kvack.org>; Mon, 18 Jul 2022 20:10:21 -0400 (EDT) Received: from smtpin31.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 76CDE35B55 for <linux-mm@kvack.org>; Tue, 19 Jul 2022 00:10:21 +0000 (UTC) X-FDA: 79701917442.31.5DEABFF Received: from out0.migadu.com (out0.migadu.com [94.23.1.103]) by imf26.hostedemail.com (Postfix) with ESMTP id E86F714006C for <linux-mm@kvack.org>; Tue, 19 Jul 2022 00:10:20 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1658189418; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=W6bMOfDQQrC3t+AXklBVrLreFIQ/eHKpGdhG0Mq/jjQ=; b=AQGV5pN45heU2T6zsptJT5C1mLwWrRpLzz28LXm/+CmeDIuYqJPxhE3ar/ksSw1TkJyY8j rNtgQzNn9yS76nfo43MZTcQmccklJx3U6n2lbpDnTc/I8MRCVj2EjZ27e5d0jkad72/k9U 8XmN00hx3iPcZWZw6r49iGUPyVkAvJk= From: andrey.konovalov@linux.dev To: Marco Elver <elver@google.com>, Alexander Potapenko <glider@google.com> Cc: Andrey Konovalov <andreyknvl@gmail.com>, Dmitry Vyukov <dvyukov@google.com>, Andrey Ryabinin <ryabinin.a.a@gmail.com>, kasan-dev@googlegroups.com, Peter Collingbourne <pcc@google.com>, Evgenii Stepanov <eugenis@google.com>, Florian Mayer <fmayer@google.com>, Andrew Morton <akpm@linux-foundation.org>, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov <andreyknvl@google.com> Subject: [PATCH mm v2 00/33] kasan: switch tag-based modes to stack ring from per-object metadata Date: Tue, 19 Jul 2022 02:09:40 +0200 Message-Id: <cover.1658189199.git.andreyknvl@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=AQGV5pN4; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf26.hostedemail.com: domain of andrey.konovalov@linux.dev designates 94.23.1.103 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658189421; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=W6bMOfDQQrC3t+AXklBVrLreFIQ/eHKpGdhG0Mq/jjQ=; b=RYhDj4E5IejsghIdw7T2VVO8IsDWXjg3Dl4AR0pQJEu8Jzi+oYHP0DDf7HR/kKTh8yViLV siU+OaZ58V9mRWX8AZ9jMqPFDrSv5zAROmCSHkJSJVL12oQRscBeEUo6jBzfjgLEBfPHAt +EfrtExZ4WJGnmths3e7ZEatAhpTkqE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658189421; a=rsa-sha256; cv=none; b=QOPYelLKQuVzZpJbhKQ1XjOaBtZbTGu+X3//KbEeyy01c6o2rA6zNXGbjfbGYz/YnQOt78 72adcySNuWVj+IxKm49fy0y1InxCH+c4ww9GlWR5CnQdzl/YexolHuVwMaC3hihzYQcvnn PnYr8Mi66xQKAnJHB6JlJ2oGITBpjPM= X-Rspamd-Queue-Id: E86F714006C Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=AQGV5pN4; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf26.hostedemail.com: domain of andrey.konovalov@linux.dev designates 94.23.1.103 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 7aut4iwitf7qxqoae6mc5f5c416ak4i6 X-HE-Tag: 1658189420-730901 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: <linux-mm.kvack.org> |
Series |
kasan: switch tag-based modes to stack ring from per-object metadata
|
expand
|
From: Andrey Konovalov <andreyknvl@google.com> This series makes the tag-based KASAN modes use a ring buffer for storing stack depot handles for alloc/free stack traces for slab objects instead of per-object metadata. This ring buffer is referred to as the stack ring. On each alloc/free of a slab object, the tagged address of the object and the current stack trace are recorded in the stack ring. On each bug report, if the accessed address belongs to a slab object, the stack ring is scanned for matching entries. The newest entries are used to print the alloc/free stack traces in the report: one entry for alloc and one for free. The advantages of this approach over storing stack trace handles in per-object metadata with the tag-based KASAN modes: - Allows to find relevant stack traces for use-after-free bugs without using quarantine for freed memory. (Currently, if the object was reallocated multiple times, the report contains the latest alloc/free stack traces, not necessarily the ones relevant to the buggy allocation.) - Allows to better identify and mark use-after-free bugs, effectively making the CONFIG_KASAN_TAGS_IDENTIFY functionality always-on. - Has fixed memory overhead. The disadvantage: - If the affected object was allocated/freed long before the bug happened and the stack trace events were purged from the stack ring, the report will have no stack traces. Discussion ========== The proposed implementation of the stack ring uses a single ring buffer for the whole kernel. This might lead to contention due to atomic accesses to the ring buffer index on multicore systems. At this point, it is unknown whether the performance impact from this contention would be significant compared to the slowdown introduced by collecting stack traces due to the planned changes to the latter part, see the section below. For now, the proposed implementation is deemed to be good enough, but this might need to be revisited once the stack collection becomes faster. A considered alternative is to keep a separate ring buffer for each CPU and then iterate over all of them when printing a bug report. This approach requires somehow figuring out which of the stack rings has the freshest stack traces for an object if multiple stack rings have them. Further plans ============= This series is a part of an effort to make KASAN stack trace collection suitable for production. This requires stack trace collection to be fast and memory-bounded. The planned steps are: 1. Speed up stack trace collection (potentially, by using SCS; patches on-hold until steps #2 and #3 are completed). 2. Keep stack trace handles in the stack ring (this series). 3. Add a memory-bounded mode to stack depot or provide an alternative memory-bounded stack storage. 4. Potentially, implement stack trace collection sampling to minimize the performance impact. Thanks! --- Changes v1->v2: - Rework synchronization in the stack ring implementation. - Dynamically allocate stack ring based on the kasan.stack_ring_size command-line parameter. - Multiple less significant changes, see the notes in patches for details. Andrey Konovalov (33): kasan: check KASAN_NO_FREE_META in __kasan_metadata_size kasan: rename kasan_set_*_info to kasan_save_*_info kasan: move is_kmalloc check out of save_alloc_info kasan: split save_alloc_info implementations kasan: drop CONFIG_KASAN_TAGS_IDENTIFY kasan: introduce kasan_print_aux_stacks kasan: introduce kasan_get_alloc_track kasan: introduce kasan_init_object_meta kasan: clear metadata functions for tag-based modes kasan: move kasan_get_*_meta to generic.c kasan: introduce kasan_requires_meta kasan: introduce kasan_init_cache_meta kasan: drop CONFIG_KASAN_GENERIC check from kasan_init_cache_meta kasan: only define kasan_metadata_size for Generic mode kasan: only define kasan_never_merge for Generic mode kasan: only define metadata offsets for Generic mode kasan: only define metadata structs for Generic mode kasan: only define kasan_cache_create for Generic mode kasan: pass tagged pointers to kasan_save_alloc/free_info kasan: move kasan_get_alloc/free_track definitions kasan: cosmetic changes in report.c kasan: use virt_addr_valid in kasan_addr_to_page/slab kasan: use kasan_addr_to_slab in print_address_description kasan: make kasan_addr_to_page static kasan: simplify print_report kasan: introduce complete_report_info kasan: fill in cache and object in complete_report_info kasan: rework function arguments in report.c kasan: introduce kasan_complete_mode_report_info kasan: implement stack ring for tag-based modes kasan: support kasan.stacktrace for SW_TAGS kasan: dynamically allocate stack ring entries kasan: better identify bug types for tag-based modes Documentation/dev-tools/kasan.rst | 15 ++- include/linux/kasan.h | 55 ++++------ include/linux/slab.h | 2 +- lib/Kconfig.kasan | 8 -- mm/kasan/common.c | 175 +++--------------------------- mm/kasan/generic.c | 154 ++++++++++++++++++++++++-- mm/kasan/hw_tags.c | 39 +------ mm/kasan/kasan.h | 173 ++++++++++++++++++++--------- mm/kasan/report.c | 117 +++++++++----------- mm/kasan/report_generic.c | 45 +++++++- mm/kasan/report_tags.c | 128 +++++++++++++++++----- mm/kasan/sw_tags.c | 5 +- mm/kasan/tags.c | 138 ++++++++++++++++++----- 13 files changed, 620 insertions(+), 434 deletions(-)