Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp871463iog; Mon, 13 Jun 2022 15:01:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKB2Yjzr5puISGyTOCT+o5Vq7Mowq3g1BPhvD1H5H+05eHv3V/Ep4YAxf9+8b7m6MIgaLA X-Received: by 2002:a63:82c1:0:b0:407:65bd:5710 with SMTP id w184-20020a6382c1000000b0040765bd5710mr1513234pgd.76.1655157661522; Mon, 13 Jun 2022 15:01:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655157661; cv=none; d=google.com; s=arc-20160816; b=gItBjRDhuiN3/leTezZUO2xMJAt7MAcQ/GRSsX18qxOq0aW1dHNkOv4BTTMP3Dar6a 0IS/AAKwSL7A1nY3ijz3u1LGL0Znuyizdtn68GCOWiBAIHAEbJhWT6Zuhq2kiMhi9dTB cBUSh9au3gZgKXpoDpqpknM2EPnjG+Gs+iXekMvlGKV1+GJHp1vMlPWdcyvFQQ6XnN2V UulpVJJVhzkEt2BvumivvIzQu5+VYnXBeLesWu87qQEQUrljUVMGGCwxXLGM9cculpi8 iGbU5i+8L0MbWbccVZDqqlynUOsfjk6ZWTw28VlH0FOsJi/gxzEPzJHcQqU416J0N3cM uO7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=JiOjwm2R97mupyKaCc5esPRsyojrd6x1cjK2UXDXXcc=; b=RriLkkSkVK6Ge+bLoFZAHZlNbz+IF11m4EO9bniWCNbCRP30S7aNTeC7hnkL82Bqu4 Hyv+cCsUvv7DAN+8C0pNAGqoW6GhjBAla1dZwjG9yyUiRMVbb/ZzRWUNoXwekIwJWbO3 pUoT9bsHO06Ql9N1jysbxen97b6JWOKnGM4aqN5r1Zxs5lJNwGQzTwlOPhLL3/YxLCsq ILBNXaUofUF0JnTVmM6ZBzqhCJrKIvmz/JDkeFiVjXYVHPDxaOxqHNRQ+9faERwvTYGJ 0udG0Iux4XIFhMW9n88pj8cfgEENf9O1yh1LsSCra0lI08rMfYtBWM+9oB4N9Vg8IKJk SUig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=pbdzxZpr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z11-20020a170902cccb00b00161a5dc2ea8si11704291ple.612.2022.06.13.15.00.48; Mon, 13 Jun 2022 15:01:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=pbdzxZpr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351321AbiFMUzM (ORCPT + 99 others); Mon, 13 Jun 2022 16:55:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351347AbiFMUx3 (ORCPT ); Mon, 13 Jun 2022 16:53:29 -0400 Received: from out0.migadu.com (out0.migadu.com [94.23.1.103]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B8F712AE6 for ; Mon, 13 Jun 2022 13:16:29 -0700 (PDT) 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=1655151388; 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: in-reply-to:in-reply-to:references:references; bh=JiOjwm2R97mupyKaCc5esPRsyojrd6x1cjK2UXDXXcc=; b=pbdzxZprz/NhIwY0P7z/+ttWMraq6KMi7wV6xcx+ASVLPMMbAH+kX5rZH71kDY66kRmnT9 Mu9jFDvTd9hGkhzuBtkY6RMAW9h9wEcOMEOO5t1SNdkQ4YpbsVY6v18z+4klJ61YmFbIo9 995IoX4sfLO/o67NszTjINnAJr8EKPA= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Peter Collingbourne , Evgenii Stepanov , Florian Mayer , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH 06/32] kasan: introduce kasan_print_aux_stacks Date: Mon, 13 Jun 2022 22:13:57 +0200 Message-Id: <11a7bfb5ed5de141b50db8c08e9c6ad37ef3febc.1655150842.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrey Konovalov Add a kasan_print_aux_stacks() helper that prints the auxiliary stack traces for the Generic mode. This change hides references to alloc_meta from the common reporting code. This is desired as only the Generic mode will be using per-object metadata after this series. Signed-off-by: Andrey Konovalov --- mm/kasan/kasan.h | 6 ++++++ mm/kasan/report.c | 15 +-------------- mm/kasan/report_generic.c | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index aa6b43936f8d..bcea5ed15631 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -265,6 +265,12 @@ void kasan_print_address_stack_frame(const void *addr); static inline void kasan_print_address_stack_frame(const void *addr) { } #endif +#ifdef CONFIG_KASAN_GENERIC +void kasan_print_aux_stacks(struct kmem_cache *cache, const void *object); +#else +static inline void kasan_print_aux_stacks(struct kmem_cache *cache, const void *object) { } +#endif + bool kasan_report(unsigned long addr, size_t size, bool is_write, unsigned long ip); void kasan_report_invalid_free(void *object, unsigned long ip); diff --git a/mm/kasan/report.c b/mm/kasan/report.c index b341a191651d..35dd8aeb115c 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -266,20 +266,7 @@ static void describe_object_stacks(struct kmem_cache *cache, void *object, pr_err("\n"); } -#ifdef CONFIG_KASAN_GENERIC - if (!alloc_meta) - return; - if (alloc_meta->aux_stack[0]) { - pr_err("Last potentially related work creation:\n"); - stack_depot_print(alloc_meta->aux_stack[0]); - pr_err("\n"); - } - if (alloc_meta->aux_stack[1]) { - pr_err("Second to last potentially related work creation:\n"); - stack_depot_print(alloc_meta->aux_stack[1]); - pr_err("\n"); - } -#endif + kasan_print_aux_stacks(cache, object); } static void describe_object(struct kmem_cache *cache, void *object, diff --git a/mm/kasan/report_generic.c b/mm/kasan/report_generic.c index 6689fb9a919b..348dc207d462 100644 --- a/mm/kasan/report_generic.c +++ b/mm/kasan/report_generic.c @@ -132,6 +132,26 @@ void kasan_metadata_fetch_row(char *buffer, void *row) memcpy(buffer, kasan_mem_to_shadow(row), META_BYTES_PER_ROW); } +void kasan_print_aux_stacks(struct kmem_cache *cache, const void *object) +{ + struct kasan_alloc_meta *alloc_meta; + + alloc_meta = kasan_get_alloc_meta(cache, object); + if (!alloc_meta) + return; + + if (alloc_meta->aux_stack[0]) { + pr_err("Last potentially related work creation:\n"); + stack_depot_print(alloc_meta->aux_stack[0]); + pr_err("\n"); + } + if (alloc_meta->aux_stack[1]) { + pr_err("Second to last potentially related work creation:\n"); + stack_depot_print(alloc_meta->aux_stack[1]); + pr_err("\n"); + } +} + #ifdef CONFIG_KASAN_STACK static bool __must_check tokenize_frame_descr(const char **frame_descr, char *token, size_t max_tok_len, -- 2.25.1