Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp842519iog; Mon, 13 Jun 2022 14:15:44 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sJYCiQYlGGSXIYxgYRFAWKXlyGz6/JoX7afOY4HqNNcyqbjnzQBz1zKEryXf0/LHLUw9u0 X-Received: by 2002:a17:90b:3c87:b0:1ea:95be:6b7d with SMTP id pv7-20020a17090b3c8700b001ea95be6b7dmr670339pjb.203.1655154944063; Mon, 13 Jun 2022 14:15:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655154944; cv=none; d=google.com; s=arc-20160816; b=gVcmvl2SuKPoHNl3YlVEe/SLd8jK0M1mUHLo6s1JYiLnyfCTI71q8xYpgn0A1X7ldQ K0kcgHPi7h7uNZfoU+W7e7UMtlBIv56FleJWOBik97Vf1P5+NgogNGAN5/M/nFxTiyjK tChWnlY/SV7BJn26++3drK4e333bCLwxTHsU7CJEMfBKJAVa+RoL0ZKr1tuR2Fg099Gu Fu+mM3+YAk1ptOU0Pibcl1rwDfsNbAh6LNTjhx7hofYbNXUK1NPXpMHKw+W3HqiNAkLQ hR8BqYeS6BqCkDaqpmhEa/VFA8el/m6qJ6KXFPAQ0+Z9bQObmgeo00xU85YqFAJtl9/z j0eA== 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=GpOGtaNQnKD78CBtw46te33KktguHzhzP5BMdoXtyCA=; b=DfqajRRIrprVPnVhxclqkSDC33dBlg8g9+i9asVXfwAp+ylW6K1FHhbxx0/T9LFtul oSDPyE7w3GCmjdcqh2E6TUPXv6RbUd0bdTKP/I9ULzRtfuQMuOelIATjAY9297IF1Na3 L1NYmvhP0GSrXfD5gF5Qu/J6TSS09Fw1+ndzmkqRha6XNxy2+LX4rq2pxmgBjnrphqMZ FMnSaNMhwf6XiD9GvIKDTAFk6QBRfQz5nDi4Zx8lazJVh9wbVbp5uroUWQQ5Ym28JAXi g84aZafnsfqrabxiv015kc0qe/U5lgJGroIWACSkE+xS+1wSM8yME6t2jdFBiwqQz41J M4mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Hws0kYch; 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 b7-20020a056a000cc700b0050a5da0cd2csi652140pfv.30.2022.06.13.14.15.31; Mon, 13 Jun 2022 14:15: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=@linux.dev header.s=key1 header.b=Hws0kYch; 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 S1352091AbiFMU6z (ORCPT + 99 others); Mon, 13 Jun 2022 16:58:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352191AbiFMUyQ (ORCPT ); Mon, 13 Jun 2022 16:54:16 -0400 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F5DE22BCD for ; Mon, 13 Jun 2022 13:20:50 -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=1655151648; 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=GpOGtaNQnKD78CBtw46te33KktguHzhzP5BMdoXtyCA=; b=Hws0kYchyYiIC/oyq7RBnW0zfkZrmMqOeGChdK9on6KahEz6fkeC5f1RRXnVjNJFsNNSDn 8/NXzEfKEDNr1bA1GKoydEx4OBVdy6AOBxSbf1NtLaCa+xsXaEM4qDBNZ3ENSVeH3ugimI NSB02I298DwQrdmyc6VOdATnCsCpQbQ= 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 32/32] kasan: better identify bug types for tag-based modes Date: Mon, 13 Jun 2022 22:14:23 +0200 Message-Id: <89492159bd43c01f7b13a72b050ff15f35e04973.1655150842.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, 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 Identify the bug type for the tag-based modes based on the stack trace entries found in the stack ring. If a free entry is found first (meaning that it was added last), mark the bug as use-after-free. If an alloc entry is found first, mark the bug as slab-out-of-bounds. Otherwise, assign the common bug type. This change returns the functionalify of the previously dropped CONFIG_KASAN_TAGS_IDENTIFY. Signed-off-by: Andrey Konovalov --- mm/kasan/report_tags.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/mm/kasan/report_tags.c b/mm/kasan/report_tags.c index 21911d1883d3..dc1f8fc0327f 100644 --- a/mm/kasan/report_tags.c +++ b/mm/kasan/report_tags.c @@ -10,7 +10,7 @@ extern struct kasan_stack_ring stack_ring; -static const char *get_bug_type(struct kasan_report_info *info) +static const char *get_common_bug_type(struct kasan_report_info *info) { /* * If access_size is a negative number, then it has reason to be @@ -36,10 +36,10 @@ void kasan_complete_mode_report_info(struct kasan_report_info *info) bool is_free; bool alloc_found = false, free_found = false; - info->bug_type = get_bug_type(info); - - if (!info->cache || !info->object) + if (!info->cache || !info->object) { + info->bug_type = get_common_bug_type(info); return; + } pos = atomic64_read(&stack_ring.pos); @@ -76,6 +76,13 @@ void kasan_complete_mode_report_info(struct kasan_report_info *info) info->free_track.pid = pid; info->free_track.stack = stack; free_found = true; + + /* + * If a free entry is found first, the bug is likely + * a use-after-free. + */ + if (!info->bug_type) + info->bug_type = "use-after-free"; } else { /* Second alloc of the same object. Give up. */ if (alloc_found) @@ -84,6 +91,17 @@ void kasan_complete_mode_report_info(struct kasan_report_info *info) info->alloc_track.pid = pid; info->alloc_track.stack = stack; alloc_found = true; + + /* + * If an alloc entry is found first, the bug is likely + * an out-of-bounds. + */ + if (!info->bug_type) + info->bug_type = "slab-out-of-bounds"; } } + + /* Assign the common bug type if no entries were found. */ + if (!info->bug_type) + info->bug_type = get_common_bug_type(info); } -- 2.25.1