Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp3589080rwb; Mon, 5 Sep 2022 14:50:06 -0700 (PDT) X-Google-Smtp-Source: AA6agR4pGY+3xbGVreb/obN72iWr1Q4AiJw78cYA5ZOxIm/i5lP4vQl3VgH052ARR5mt01P8U63A X-Received: by 2002:a63:2fc7:0:b0:42c:3683:7e50 with SMTP id v190-20020a632fc7000000b0042c36837e50mr33149560pgv.534.1662414606252; Mon, 05 Sep 2022 14:50:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662414606; cv=none; d=google.com; s=arc-20160816; b=LWY6RcEwZ1YRP20lWgPfJUoepFI4tkES0XVLjEmY71djUs4JsbaDuB18Ctxlr+ErZX mzDUXwJn/3yU7G3rMzcKiimRIS8bIl4lIxNBDvX5Ai6RmamiilvFxzqVPkAWTqKzaPgr CiwVtM9vPThnlTaEQ6ou9quwqASI01wFn35oVectUxddF/bk/FTHpqXNJl2G7spBKavp 7/5hynCytak09UxElrpNfHWT8tV/Wj0cVOUahxsAIHbe2RzONxFbTjcx/a/QJFdE4yqu 3bZvMAugEgRxwNbqOqYx3EPlEGISITruZ0jezDnKPK+ZULpYxPnU025eKfvTHskBbAfz kZNQ== 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=zEfgbyod9TAfDmSVR8FRbZx2ES7CDMUEPsx9DLtb/Fc=; b=aShZLUr2kP35r2QQ1tMLpQtDxCp4glHMO5w+M1iLr10WMSY9tSr/NeeP9QbNrOIIP7 MGsxvqeFPKGMxmzPi6wFyFa6uO7hEcg01jePqrLw9sZphNjwxHZrFuRaSPDAQLe9pntl lC7vBP5IJR4irjEUDiQnGCHj5+SfiwVPY62YEw3JwQWxxVG3rdyqL/7RVnRffnWe491n 88+eWuBVKUo0/Uu0uBYQeKntg31SQ2vvzz51g9nxHdPGnzFxNQE44OzPWcetw6krfCcF ahs3kx+07tUc/0jGgDsEpgBeUloi17AU1XtiXqJC6htANA5U57zEJ52lrvbgbAvixNU5 eQvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=HXM9rl7H; 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 l13-20020a170903244d00b001751d0ac52asi8852622pls.435.2022.09.05.14.49.54; Mon, 05 Sep 2022 14:50:06 -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=HXM9rl7H; 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 S237992AbiIEVL2 (ORCPT + 99 others); Mon, 5 Sep 2022 17:11:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237585AbiIEVLD (ORCPT ); Mon, 5 Sep 2022 17:11:03 -0400 Received: from out1.migadu.com (out1.migadu.com [91.121.223.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA49469F73 for ; Mon, 5 Sep 2022 14:10:25 -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=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 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 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) -- 2.25.1