Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp848013iog; Mon, 13 Jun 2022 14:24:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyW+53IpHoOnWW2Ofys19chchZjXTmpbKXOt+eGE3M9ofc4fxUS7QDS7GVG4YSUCUhw2dYA X-Received: by 2002:a17:907:1b19:b0:6f0:1022:1430 with SMTP id mp25-20020a1709071b1900b006f010221430mr1497511ejc.13.1655155449346; Mon, 13 Jun 2022 14:24:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655155449; cv=none; d=google.com; s=arc-20160816; b=HIHwgGpJ1nS9l0Wx4ni1mhKdEMnmijG8iXsr942Nsr9KQ4l+FMOl5aGtqrHrPiT+gZ GGal6h0/qRKt/bWyUPpqVdvLgulepbMjKoBG9N/8mmxKVwDiiQIJ2FCnQIzMIZ6NMZji Q6s92looaOheiNqy053JHJAb84V448RROLmz4F+E6BQiNOkhz+qPddO+w0oaeeCHu1UV uWztE/7nkHx/KwhJxNhSV/AMHzJAYzHxij6/J2M3yDyTMBh1OiR/NNnfvVayPwF5k7Vj i3YoLHvSZG33+oLCiuVQHD517eicBMrn5FfCIMluTdGUTwNy6MB0Kb6oRUfu1NAkWzrj ah1g== 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=7UlP4rgYEeC4zjzJGZ6kC7jJ637whgBTqafUFs9KdFM=; b=tnWoLrQjJ9WV1OQZyyciN7jNSTcTWIps6e9BVeWrPmGQeppbsKoLE9n+2N4eHg3u5L o0GvwOxHsB89yV3bdaTdiZeQuTS1MNi9m/aq14BUWg/tRoiwk0VvP2bHLmtXLLmIJ692 oIyHFCvSGcWSB4jJY8vM/lSai5Jk1l3+X+6OFtkycGQcExEF9pVHMZWT9thtOe2NC0xa EhweQaJAPgSVfcqWS7VikK+UWP6D9AAqrKZuWo8bTIpJZuRqXOUFpwCQJx4aepTvORvV RrfxiZ2KrakSsCjMZX780uR2TFwA9WGavYcnj+ke0pFU/axGqnnf3JM9MV1VeTPHsj/9 2aaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=JefL7G+u; 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 qk41-20020a1709077fa900b00718c2c40966si3974034ejc.480.2022.06.13.14.23.44; Mon, 13 Jun 2022 14:24:09 -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=JefL7G+u; 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 S240728AbiFMU4R (ORCPT + 99 others); Mon, 13 Jun 2022 16:56:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351923AbiFMUyC (ORCPT ); Mon, 13 Jun 2022 16:54:02 -0400 Received: from out0.migadu.com (out0.migadu.com [IPv6:2001:41d0:2:267::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C111325C75 for ; Mon, 13 Jun 2022 13:18:41 -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=1655151520; 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=7UlP4rgYEeC4zjzJGZ6kC7jJ637whgBTqafUFs9KdFM=; b=JefL7G+uMUqUoHfYWqpdgoz/IVfPj+68p9IguhAmpQXwywnI1zyQ5WjNpX1CBh3AHwLiXW vyxIhpMNSmc+fBPo6tTB92C9YhdzPz89lbk37knbBj6HEIFOl1Fj4YvvVK2Yf/WNk63+41 DukNNsx5HLFREaWIXGxDjKQqbidMoh8= 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 21/32] kasan: simplify invalid-free reporting Date: Mon, 13 Jun 2022 22:14:12 +0200 Message-Id: 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 Right now, KASAN uses the kasan_report_type enum to describe report types. As this enum only has two options, replace it with a bool variable. Also, unify printing report header for invalid-free and other bug types in print_error_description(). Signed-off-by: Andrey Konovalov --- mm/kasan/kasan.h | 7 +------ mm/kasan/report.c | 16 +++++++--------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index e8329935fbfb..f696d50b09fb 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -146,16 +146,11 @@ static inline bool kasan_requires_meta(void) #define META_MEM_BYTES_PER_ROW (META_BYTES_PER_ROW * KASAN_GRANULE_SIZE) #define META_ROWS_AROUND_ADDR 2 -enum kasan_report_type { - KASAN_REPORT_ACCESS, - KASAN_REPORT_INVALID_FREE, -}; - struct kasan_report_info { - enum kasan_report_type type; void *access_addr; void *first_bad_addr; size_t access_size; + bool is_free; bool is_write; unsigned long ip; }; diff --git a/mm/kasan/report.c b/mm/kasan/report.c index f951fd39db74..7269b6249488 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -175,14 +175,12 @@ static void end_report(unsigned long *flags, void *addr) static void print_error_description(struct kasan_report_info *info) { - if (info->type == KASAN_REPORT_INVALID_FREE) { - pr_err("BUG: KASAN: double-free or invalid-free in %pS\n", - (void *)info->ip); - return; - } + const char *bug_type = info->is_free ? + "double-free or invalid-free" : kasan_get_bug_type(info); - pr_err("BUG: KASAN: %s in %pS\n", - kasan_get_bug_type(info), (void *)info->ip); + pr_err("BUG: KASAN: %s in %pS\n", bug_type, (void *)info->ip); + if (info->is_free) + return; if (info->access_size) pr_err("%s of size %zu at addr %px by task %s/%d\n", info->is_write ? "Write" : "Read", info->access_size, @@ -435,11 +433,11 @@ void kasan_report_invalid_free(void *ptr, unsigned long ip) start_report(&flags, true); - info.type = KASAN_REPORT_INVALID_FREE; info.access_addr = ptr; info.first_bad_addr = kasan_reset_tag(ptr); info.access_size = 0; info.is_write = false; + info.is_free = true; info.ip = ip; print_report(&info); @@ -468,11 +466,11 @@ bool kasan_report(unsigned long addr, size_t size, bool is_write, start_report(&irq_flags, true); - info.type = KASAN_REPORT_ACCESS; info.access_addr = ptr; info.first_bad_addr = kasan_find_first_bad_addr(ptr, size); info.access_size = size; info.is_write = is_write; + info.is_free = false; info.ip = ip; print_report(&info); -- 2.25.1