Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp4081829rwn; Sun, 11 Sep 2022 04:58:45 -0700 (PDT) X-Google-Smtp-Source: AA6agR7rRJ/aqTfoptCtDMG+y+Qht0EKJjwePpptRoI93uo+OVlMDKsfbEixRblR/FKrDJHGcq4L X-Received: by 2002:a17:90a:70c7:b0:200:8b98:9afc with SMTP id a7-20020a17090a70c700b002008b989afcmr18985439pjm.236.1662897524944; Sun, 11 Sep 2022 04:58:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662897524; cv=none; d=google.com; s=arc-20160816; b=pRzlPWSsHmN1idO/DuKc3jA4Vj76ZWn1WiJjBWFC8E4/Y35vaaoW0JdvW8nAVx8QH/ PsRpq4b1RucJBnskxqwjCvng8mz+X2Sz/hqnWWAug3253ibKMoCCoqfrNjBpXEOLFRkW /ctPMllyuUiV7YHjxfZN2jrZDMkT0itSjrc1YHnOIarkNqtKIVF2kVObFp/vCgAljy2S Q3JeCs3Q4Zl1iyOgh1k/yeRx5tQM/fueIzU3nRW8h4Y229zVNMV6dtxG7ndxl9iMYckq qm5ouWbGyPZ2mPClZyw5JYaJIRAo1zu2byOQ91XHt7lj31hrDP5CD0RWN4KxN4t8oM3l K2Xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=f3KWsKgAEFkYsTG0akgEuS+HAh1aYxDAn4WpE5Ns8zA=; b=cB4NqQRJ/qex4zqI3pNaI6cIrwJv56P90jvu/WGG5t5ne9d5Mw+x/EIVFlu44i2j4T h39zBt6G6XMXknk+cz+d9nnbpLA9gjXKBgRSGp+9P8zbYffZWV1sSR7IljlZZPjEHS/J asMKE2qZDnt9Wcr+vKI+Dq4ZZdIn/qhIlRafcpkz0TUwa2U2eOc/446vNLeoWEXNIIxi Apt7LJhiiGTKb2Sqnqvqp+lKQwfj/VFyk6LmaWjseWJz3YQu+cdHVm9CE6ux2JhlIfuN hQ3/BKyqz+hQq/GXwoH71YIpzSF8lkOA5vPxHRWNoJIawtOYIbhLPJHaWMPaw/uRV070 TPkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GQyUfzr0; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e22-20020a633716000000b0042fa7bc7f00si6653636pga.860.2022.09.11.04.58.33; Sun, 11 Sep 2022 04:58:44 -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=@gmail.com header.s=20210112 header.b=GQyUfzr0; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230128AbiIKLs6 (ORCPT + 99 others); Sun, 11 Sep 2022 07:48:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229895AbiIKLs5 (ORCPT ); Sun, 11 Sep 2022 07:48:57 -0400 Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74D7C22BF5 for ; Sun, 11 Sep 2022 04:48:56 -0700 (PDT) Received: by mail-qt1-x830.google.com with SMTP id y2so4417109qtv.5 for ; Sun, 11 Sep 2022 04:48:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=f3KWsKgAEFkYsTG0akgEuS+HAh1aYxDAn4WpE5Ns8zA=; b=GQyUfzr0qn9l1B1gRLnzR/F5Sfuss4HGg93KeBu84RPSKCiIyCcVDuQRbpIOqnHRNa 7hgdkmoeEqbUWdIz19LnGbiwUqIt5BI8W7agKxfK6pGYJA4M2xknml4+zgLGRbTxWhfu I75iEIyLleW5WuRS85vFNXDOXvhbSTaF39AT7/TTp2Iox1+mSecUjqqWGWcK9D8Eo89I SA/CAl+LOC1QCQKhguDtWN9jv4y4PVo4SXclU+OgpAJaMpQHl6Pim9gbso+mO5zH28nS jLAKvVWrmi82/Sirnrnz78R6NuhwbhVA999GWRscIaHu/mol4/GPc7A9UyrNzsE0O8JZ mmPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=f3KWsKgAEFkYsTG0akgEuS+HAh1aYxDAn4WpE5Ns8zA=; b=Vf7XkpOp2pmcpN7I1FowkOdzpMJqg2jmFbIVIVocANXNPGl6A4Y0KHVrNXhWhZCBaE O2K9XnbcnL5BfLAxa6QNx1Dsox9FHuwoJV7nV1Fk0fsGfK59wtkWUL/Ha1R8cij9O/Sm MvN4p2dU2e9+Is53V1L2+yIH4ruyxslU0wIljGM2oKCtyyvQucKiiySueob0seeORvbQ zujJ3RJqhXA1PDaftsaDZnwsJYrGjlcIWdTy1WPa7eCcDXhEICK15hja74v+MmBm6h8m ZtNq9B1AxdGV1z0cxaWoa7bKn0ACksNtDqS0+LcTrSShlzf5stz8/cwR+RRYXAWOyfUl B6mw== X-Gm-Message-State: ACgBeo0EcCCoterBEtxQPDShl34kULXz+jgDAj8HsB16SNR2zUVC3/Xd mBy6dDrMixzkkEcpnhbtzwwowVH0Khk/t8+yxfg= X-Received: by 2002:ac8:7d85:0:b0:35b:acfc:f3a1 with SMTP id c5-20020ac87d85000000b0035bacfcf3a1mr4031933qtd.106.1662896935625; Sun, 11 Sep 2022 04:48:55 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Andrey Konovalov Date: Sun, 11 Sep 2022 13:48:45 +0200 Message-ID: Subject: Re: [PATCH] kasan: better invalid/double-free report header To: andrey.konovalov@linux.dev Cc: Marco Elver , Alexander Potapenko , Andrew Morton , Dmitry Vyukov , Andrey Ryabinin , kasan-dev , Linux Memory Management List , LKML , Andrey Konovalov Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,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 On Sun, Sep 11, 2022 at 1:25 AM wrote: > > From: Andrey Konovalov > > Update the report header for invalid- and double-free bugs to contain > the address being freed: > > BUG: KASAN: invalid-free in kfree+0x280/0x2a8 > Free of addr ffff00000beac001 by task kunit_try_catch/99 > > Signed-off-by: Andrey Konovalov Forgot to mention: this goes on top of the "kasan: switch tag-based modes to stack ring from per-object metadata" series. > --- > mm/kasan/report.c | 23 ++++++++++++++++------- > mm/kasan/report_generic.c | 3 ++- > mm/kasan/report_tags.c | 2 +- > 3 files changed, 19 insertions(+), 9 deletions(-) > > diff --git a/mm/kasan/report.c b/mm/kasan/report.c > index 39e8e5a80b82..df3602062bfd 100644 > --- a/mm/kasan/report.c > +++ b/mm/kasan/report.c > @@ -175,17 +175,14 @@ 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: invalid-free in %pS\n", (void *)info->ip); > - return; > - } > + pr_err("BUG: KASAN: %s in %pS\n", info->bug_type, (void *)info->ip); > > - if (info->type == KASAN_REPORT_DOUBLE_FREE) { > - pr_err("BUG: KASAN: double-free in %pS\n", (void *)info->ip); > + if (info->type != KASAN_REPORT_ACCESS) { > + pr_err("Free of addr %px by task %s/%d\n", > + info->access_addr, current->comm, task_pid_nr(current)); > return; > } > > - pr_err("BUG: KASAN: %s in %pS\n", info->bug_type, (void *)info->ip); > 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, > @@ -420,6 +417,18 @@ static void complete_report_info(struct kasan_report_info *info) > } else > info->cache = info->object = NULL; > > + switch (info->type) { > + case KASAN_REPORT_INVALID_FREE: > + info->bug_type = "invalid-free"; > + break; > + case KASAN_REPORT_DOUBLE_FREE: > + info->bug_type = "double-free"; > + break; > + default: > + /* bug_type filled in by kasan_complete_mode_report_info. */ > + break; > + } > + > /* Fill in mode-specific report info fields. */ > kasan_complete_mode_report_info(info); > } > diff --git a/mm/kasan/report_generic.c b/mm/kasan/report_generic.c > index 087c1d8c8145..043c94b04605 100644 > --- a/mm/kasan/report_generic.c > +++ b/mm/kasan/report_generic.c > @@ -132,7 +132,8 @@ void kasan_complete_mode_report_info(struct kasan_report_info *info) > struct kasan_alloc_meta *alloc_meta; > struct kasan_free_meta *free_meta; > > - info->bug_type = get_bug_type(info); > + if (!info->bug_type) > + info->bug_type = get_bug_type(info); > > if (!info->cache || !info->object) > return; > diff --git a/mm/kasan/report_tags.c b/mm/kasan/report_tags.c > index d3510424d29b..ecede06ef374 100644 > --- a/mm/kasan/report_tags.c > +++ b/mm/kasan/report_tags.c > @@ -37,7 +37,7 @@ void kasan_complete_mode_report_info(struct kasan_report_info *info) > bool is_free; > bool alloc_found = false, free_found = false; > > - if (!info->cache || !info->object) { > + if ((!info->cache || !info->object) && !info->bug_type) { > info->bug_type = get_common_bug_type(info); > return; > } > -- > 2.25.1 >