Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3933528imw; Mon, 18 Jul 2022 17:48:56 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tLzIu2Y5qXEISnJBRwlCL4XRSlxDdalQZMzjYVLS18xsQg2t329JwtoPUaTWpGtBW+Fj0D X-Received: by 2002:aa7:c597:0:b0:43a:473b:8bae with SMTP id g23-20020aa7c597000000b0043a473b8baemr40454815edq.384.1658191735934; Mon, 18 Jul 2022 17:48:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658191735; cv=none; d=google.com; s=arc-20160816; b=QNDGI1ReNlvCIIWc4iPYv9H0yNnc+DEpq1ky3MTinPMOgqvxUqfWhoQT5qVQIKnvKk UtYtwqySTZpGvy5lwO2NrJLm1NdPK040Q8kT5Dh4fd45IuIoEJXicqGOPcqUwS6HcMYT fxbQhSl9/HOYQqBpS1l+HFmjFCGsibnq0gjMQAZ5dJjePGoRdKaXq0YKiMzp6hCNluuR ISlIUEVJnpa2wA9k0UqWH7Km1Ovey2OGrwqzsNjqQUupucHwh26umecYGDKCX2JzvOyJ 4GeA/sYOTvvTQ39yQ5YHxvmxhi28Xgk7qrc84o5mW+FI2zGyU1hGve34JX8x7qzi9ZW6 +1MQ== 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=wlDL8UWCNOAUa7xc7DhMAdKP5Ju8o15uIhriUX+aQyY=; b=otrBRUJ+xlLc4GHWIcVgqO59nGnV2InbRKHZUSHzWS+5YX+mKMAAmoVn4WFqpEXShf qRdHqg8bE91RERUc8U2Ak1fYRrr63pSFBGhGqZWWm49sbDOCY95/gk5VyTdRpeAUqdDB +/cVhc0JT8bzARzR3xTFn+nMNSWISHUKNJvv9ryH5FWrfKCXSjDaQhGBmBmYlJJMabyE 9HZk4WTOfIOpyGg9WbfVggWmu30TVSXIpziQ9VgJA9dLI9USAYks256uQSccTbk7ZTj2 iy8vd5fwyllB9YS7rpZ6vAlvLxN9oexhI7XCDkNloQLoJt8R4UBSQUUzFHq5v1CKvSq/ bgrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=PsMkFHXX; 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 p1-20020a056402154100b0043aad2d4f73si15515611edx.444.2022.07.18.17.48.30; Mon, 18 Jul 2022 17:48:55 -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=PsMkFHXX; 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 S236695AbiGSAOu (ORCPT + 99 others); Mon, 18 Jul 2022 20:14:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236646AbiGSAOn (ORCPT ); Mon, 18 Jul 2022 20:14:43 -0400 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD066DB for ; Mon, 18 Jul 2022 17:14:42 -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=1658189681; 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=wlDL8UWCNOAUa7xc7DhMAdKP5Ju8o15uIhriUX+aQyY=; b=PsMkFHXXLnWmMypFxsAkjP2DbAIMEVOHLVabnFSqAv1Preh/rNfnD5s3lrIJak0d7GWaJG x5G1uDH8a40K9xm+Bo69DoB8k0gAMRqBZKz6bdc/XOgZSorqHjsnYAwXJiPR3Gtw546E+F u+IA/wu8UJA67Rl+tisNaBqDtZGnbxc= 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 mm v2 27/33] kasan: fill in cache and object in complete_report_info Date: Tue, 19 Jul 2022 02:10:07 +0200 Message-Id: <83156bb0ec6d790b0e7ea0002b3490a70bc5c481.1658189199.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 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 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) -- 2.25.1