From patchwork Mon Jun 13 20:14:12 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: 12880096 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 4FE0FC433EF for ; Mon, 13 Jun 2022 20:18:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 665ED8D01D5; Mon, 13 Jun 2022 16:18:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 59E1D8D01CC; Mon, 13 Jun 2022 16:18:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 466078D01D5; Mon, 13 Jun 2022 16:18:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 2AB958D01CC for ; Mon, 13 Jun 2022 16:18:42 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 0C0A560EEC for ; Mon, 13 Jun 2022 20:18:42 +0000 (UTC) X-FDA: 79574325684.03.0E55F2B Received: from out0.migadu.com (out0.migadu.com [94.23.1.103]) by imf14.hostedemail.com (Postfix) with ESMTP id 7DE73100072 for ; Mon, 13 Jun 2022 20:18:41 +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=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 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655151521; 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=7UlP4rgYEeC4zjzJGZ6kC7jJ637whgBTqafUFs9KdFM=; b=fP9pTvqGql+4Gqm49iEK3WMSCoxDoJZ9xgyR4ChMh1Ih98AfybBLpyt1+UNMMaICHG6Afd 5N3crYPOL/+sRbPoPfX7/udkCCO9Xkuhisda8L0LTlCXy4PZUR+65zI8H2QmWPlS//CKqK Iz2yqqhuink25n/Q50QrDvx+Dcs+Prc= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=JefL7G+u; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf14.hostedemail.com: domain of andrey.konovalov@linux.dev designates 94.23.1.103 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655151521; a=rsa-sha256; cv=none; b=xnsg9R97G0qt/vecKTx5/LXpuQ/W8basn5/hgvqiFTwBu0uR2TuxQzPYh+D5l2A9Fn+deG 9w7mdmNwaqbRMRTfM56fQwOqY0RUKjHczGL4b3HDK4NE5nH3UTFAwz5RgutSmZ7HGrkf2s BnD5n7ZPt4AXVeLJFW8r2u46vXLjud0= X-Rspamd-Queue-Id: 7DE73100072 X-Rspam-User: X-Stat-Signature: ddma5mnnaxyqo5turj15qoapfhmzhh5b Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=JefL7G+u; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf14.hostedemail.com: domain of andrey.konovalov@linux.dev designates 94.23.1.103 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev X-Rspamd-Server: rspam04 X-HE-Tag: 1655151521-518358 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 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);