From patchwork Mon Jun 13 20:14:23 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: 12880107 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 5831CCCA47B for ; Mon, 13 Jun 2022 20:20:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 776C88D01E0; Mon, 13 Jun 2022 16:20:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6B0728D01DD; Mon, 13 Jun 2022 16:20:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4DC4E8D01E0; Mon, 13 Jun 2022 16:20:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 2B1FC8D01DD for ; Mon, 13 Jun 2022 16:20:51 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 08DB231EB7 for ; Mon, 13 Jun 2022 20:20:51 +0000 (UTC) X-FDA: 79574331102.12.0AB1728 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf13.hostedemail.com (Postfix) with ESMTP id 1E1C220099 for ; Mon, 13 Jun 2022 20:20:49 +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=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 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655151650; a=rsa-sha256; cv=none; b=4WxCeQuBJ1MHOlhk5l2HKNK3CdPo4g/W9sqd1x+3gcLt/jJsxvwFskHyq4URsC+S3dmP79 1QODgs8D9TqRRDr81ubNMlVnVIuqvoymULZTVo03Aa759dVgX3ts5VRS4DUIw56ejU+bc2 naPmoYrdLd8pUR9vu9l/0gfpGU6JAxY= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Hws0kYch; spf=pass (imf13.hostedemail.com: domain of andrey.konovalov@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655151650; 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=GpOGtaNQnKD78CBtw46te33KktguHzhzP5BMdoXtyCA=; b=s2kKPF85qyl1eyq9mvVVHseUgxrezpntUCtdT0RQoVofGXbhg1zBdfIGavaJkhK5l9mw8e jB7GpLi9yeSsS05eMD4RMEcRJBh+5wGBKyGt90PgWO4MnhS5vRtUul4BHFuxxSxcbHonAs +Rk5Tsvs5sVgORHmNOP/Cz6M6V7XrU0= X-Stat-Signature: gfwek6emthesbas73rhn9coe7mpo8mrk X-Rspamd-Queue-Id: 1E1C220099 Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Hws0kYch; spf=pass (imf13.hostedemail.com: domain of andrey.konovalov@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Rspamd-Server: rspam07 X-Rspam-User: X-HE-Tag: 1655151649-724600 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 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); }