From patchwork Mon Sep 5 21:05:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 12966566 Return-Path: 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 9F42AECAAD3 for ; Mon, 5 Sep 2022 21:10:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 370FB80222; Mon, 5 Sep 2022 17:10:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2D1D880214; Mon, 5 Sep 2022 17:10:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 14B8A80222; Mon, 5 Sep 2022 17:10:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id E4EE480214 for ; Mon, 5 Sep 2022 17:10:18 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id C868DA0627 for ; Mon, 5 Sep 2022 21:10:18 +0000 (UTC) X-FDA: 79879274916.20.D30D9FD Received: from out1.migadu.com (out1.migadu.com [91.121.223.63]) by imf15.hostedemail.com (Postfix) with ESMTP id 12F0AA0063 for ; Mon, 5 Sep 2022 21:10:17 +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=1662412217; 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=zEfgbyod9TAfDmSVR8FRbZx2ES7CDMUEPsx9DLtb/Fc=; b=HXM9rl7HBoe458HguBeCJMpud8xnvFvzKLmPxcNwGKPRbJa+5fBcWrLyp7/5mGOpn6JM0W 9GGHaABZtIuxWJZG+PMAY29EALboC7lxUQobOMboGzVwu8Lz4JdX6TEqsY1WC5rWUC5VsQ WSMaC2V3y1JSDhFOzdUlKZFHfPJR5to= From: andrey.konovalov@linux.dev To: Andrew Morton Cc: Andrey Konovalov , Marco Elver , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Peter Collingbourne , Evgenii Stepanov , Florian Mayer , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm v3 27/34] kasan: fill in cache and object in complete_report_info Date: Mon, 5 Sep 2022 23:05:42 +0200 Message-Id: <23264572cb2cbb8f0efbb51509b6757eb3cc1fc9.1662411799.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=HXM9rl7H; spf=pass (imf15.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.121.223.63 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662412218; a=rsa-sha256; cv=none; b=jUPhmeaeny9n5wHMgtkfYguPKwyx1U5p+LNXHMNUm2F22pNFw2A4pMFu0Jhy8SsLFl7jsn LPo1IGH/sKnRiR+aB9jAZgprTlkaZdOfPqPQybhl3AmD89WTULsMcR8hxkc7W27UbCbQWU fj2kNojuOHO4Uy4d1azzbpjDniMcCho= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662412218; 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:in-reply-to:references:references:dkim-signature; bh=zEfgbyod9TAfDmSVR8FRbZx2ES7CDMUEPsx9DLtb/Fc=; b=OCsKCyG0jAGao/9gU0P6gKdxRdBOg7rbwLd74BbCCMlmwehdyDvUoU3FBqr2G7oHTgRhLV WkF6LTeo7f8QjYzTuD0+nA4asgmlYkj97Oz2aGC8mv0yZmG/yz4ALNDpBypq4jjxdHh9kh agxAuw91MsK5sJhXE7gJFgMN9cgbpFM= Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=HXM9rl7H; spf=pass (imf15.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.121.223.63 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Stat-Signature: qo33yoxpabkkrr8q88bu9y6t1gtk8pgd X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 12F0AA0063 X-HE-Tag: 1662412217-817763 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: From: Andrey Konovalov Add cache and object fields to kasan_report_info and fill them in in complete_report_info() instead of fetching them in the middle of the report printing code. This allows the reporting code to get access to the object information before starting printing the report. One of the following patches uses this information to determine the bug type with the tag-based modes. Reviewed-by: Marco Elver Signed-off-by: Andrey Konovalov --- mm/kasan/kasan.h | 2 ++ mm/kasan/report.c | 21 +++++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 7e07115873d3..b8fa1e50f3d4 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -162,6 +162,8 @@ struct kasan_report_info { /* Filled in by the common reporting code. */ void *first_bad_addr; + struct kmem_cache *cache; + void *object; }; /* Do not change the struct layout: compiler ABI. */ diff --git a/mm/kasan/report.c b/mm/kasan/report.c index 0c2e7a58095d..763de8e68887 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -287,19 +287,16 @@ static inline bool init_task_stack_addr(const void *addr) sizeof(init_thread_union.stack)); } -static void print_address_description(void *addr, u8 tag) +static void print_address_description(void *addr, u8 tag, + struct kasan_report_info *info) { struct page *page = addr_to_page(addr); - struct slab *slab = kasan_addr_to_slab(addr); dump_stack_lvl(KERN_ERR); pr_err("\n"); - if (slab) { - struct kmem_cache *cache = slab->slab_cache; - void *object = nearest_obj(cache, slab, addr); - - describe_object(cache, object, addr, tag); + if (info->cache && info->object) { + describe_object(info->cache, info->object, addr, tag); pr_err("\n"); } @@ -406,7 +403,7 @@ static void print_report(struct kasan_report_info *info) pr_err("\n"); if (addr_has_metadata(addr)) { - print_address_description(addr, tag); + print_address_description(addr, tag, info); print_memory_metadata(info->first_bad_addr); } else { dump_stack_lvl(KERN_ERR); @@ -416,12 +413,20 @@ static void print_report(struct kasan_report_info *info) static void complete_report_info(struct kasan_report_info *info) { void *addr = kasan_reset_tag(info->access_addr); + struct slab *slab; if (info->type == KASAN_REPORT_ACCESS) info->first_bad_addr = kasan_find_first_bad_addr( info->access_addr, info->access_size); else info->first_bad_addr = addr; + + slab = kasan_addr_to_slab(addr); + if (slab) { + info->cache = slab->slab_cache; + info->object = nearest_obj(info->cache, slab, addr); + } else + info->cache = info->object = NULL; } void kasan_report_invalid_free(void *ptr, unsigned long ip, enum kasan_report_type type)