Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp868068iog; Mon, 13 Jun 2022 14:55:25 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u6jYVkEEMRCAX/K7GAQT8xFH+dwox+IgiZoUFCu+Q9YXW7xUwt03XwmYuGLibfHRfH35aZ X-Received: by 2002:a17:90b:17c6:b0:1e8:2c09:d006 with SMTP id me6-20020a17090b17c600b001e82c09d006mr856446pjb.31.1655157325476; Mon, 13 Jun 2022 14:55:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655157325; cv=none; d=google.com; s=arc-20160816; b=InO2i3bhjizhVQsUWnzelLX9Tx1Mqpf30cTDe/ZTUBRo7dFTs2Q0prMh1k66wIR/6/ sOp0tCYIBzQqt65A6TXgQ1HO6Z1mNqDI2OQqhd7jyEAmW/4SBJMVdt/5oPM2flZu4nVs 7tycAW/uJBH5EdJEYf4PBBTMXK47okM9nQjMa+su7v+SwTFmJ2jrjEWmQoJPtmoqNPA4 IrsOQ7Hh1ZRle9iZtW+vA5yUDkuP75iXRKN7CymNa95M2YurKBlPtwaSpEZlUj9jNNJk ZHvdQU63qKAaaaEmmi+U2I+tNsUAGbE3Ldrdp3PdEAzM4C1EYip7XoVq6GIDzp+pSkx3 GCJQ== 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=4luxyHsp81FOFiUT/6yoqfYUWRQbE1ZGpW4pjt9Mu8s=; b=ZG6U8/p50us2yI52BEoYrC5H+fOq8fOudWf4FJPu5jxSWJhXMyPOsONQGsPa+cA9IK bwJ80qsoLquVp3QF1ZpM4LJtwcORBi08vpllUGXZ0x09PpbCOIkIifT3P6jiXvqhodzf BJA4xaDPFfT2Gu6xPL+7VhcHhZzgeyYCme7TkAfOBOao79TDVZoFD/ZXrfkRNzqLWUZU mcftLv5HESCUfC38SDGqerEBZGU0vFO7AqWCsH4vRip2GxMJrUJTUi+JR1Lw3nrGbQJl K3xoEKGt3K+2UB27CMQWzAW7CLg7hCGicvs5VlWCE+mzrxuXW1UxdlhqT8qc61JAwIba lJgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=wrqv7ohO; 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 r10-20020a63ce4a000000b003fdc5a65a32si11921394pgi.406.2022.06.13.14.55.13; Mon, 13 Jun 2022 14:55:25 -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=wrqv7ohO; 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 S236672AbiFMU5L (ORCPT + 99 others); Mon, 13 Jun 2022 16:57:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352088AbiFMUyK (ORCPT ); Mon, 13 Jun 2022 16:54:10 -0400 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39DBA2A243 for ; Mon, 13 Jun 2022 13:19:47 -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=1655151585; 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=4luxyHsp81FOFiUT/6yoqfYUWRQbE1ZGpW4pjt9Mu8s=; b=wrqv7ohOF96qGiSQuPggQGcjaCvog98ApGuHxDFierBEUu/M31pb0J67CQIkajDOQYJQER YuDnSp2V6YbPoBkcPXwEnEdjyMR+pJGczOFfBWwr4cvGnkAYWCX7vQpjjcSJ9wtyoKpbVh ZPeMiUpOhK1ShOgWWyVcqDCuLD/pVRs= 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 28/32] kasan: fill in cache and object in complete_report_info Date: Mon, 13 Jun 2022 22:14:19 +0200 Message-Id: <1e3e75cbcf4f258701b325dbad8b2a43c2633b7b.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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 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. 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 0261d1530055..b9bd9f1656bf 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -156,6 +156,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 214ba7cb654c..a6b36eb4c33b 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -281,19 +281,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"); } @@ -400,7 +397,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); @@ -410,12 +407,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->is_free) info->first_bad_addr = addr; else info->first_bad_addr = kasan_find_first_bad_addr( info->access_addr, info->access_size); + + 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) -- 2.25.1