Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp3591855rwb; Mon, 5 Sep 2022 14:54:00 -0700 (PDT) X-Google-Smtp-Source: AA6agR7jWz+zrc2tPLzvUiAX27Il9iX5nUvsX1dajRoO+ai2/Em5KagrCTX6tQrr+gnTYRhj5B2j X-Received: by 2002:a63:5221:0:b0:434:37b4:17f5 with SMTP id g33-20020a635221000000b0043437b417f5mr8280868pgb.479.1662414840239; Mon, 05 Sep 2022 14:54:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662414840; cv=none; d=google.com; s=arc-20160816; b=bkF4m+HtH8bhLaa3JLLDh64GtxJoTmCaVOIlOg4n28Nxfsby9E2W0eRk8NfStbDye+ izE+6FLjazz95VfXi7I8QAVu7wKxaSoSkF9P6ZjZtyNZ4Z8uqu+gTyPl3si7nVbSj8Xn f2AXNYvJGtpALpD123450mOO9GuV0h5n2xJYdTNvG+vCpfUPgSIMJw6MyDhkd9xyDHCU +i9+ElScBmTauGZvDr7JJW+zqeLGioH/QpEC8/gUlwdUZtxDi30GaRAdA4mzB7DT5981 i9MRKiBMWdPCNxvrSpatCJ1c2BEvfzMWPnS4eKY1i3tKcdMOkP5TmwjxwkfJoYwvVxfI 31EA== 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=T0DFoi3F6F/yHkLbxOafy4/ej0Np4BxwTKaKbEY2PpY=; b=lGQC8gbl9GEciJduZSiOpM3MokwJdV7IXZoFF9HB0+myMqwXpciIpAvkS0EY9YRM5a jIMHDCz2Qx1Y/SOOwYMjBv45iggy9Nz3/uNGh5czbicVrfk7bRBFNfiIiKQ23tIWJ/8k fkoxCvpQnmN32FE5RRhVB/ypDV+CO8bstn4aGE62zDGFNkq7D6l+BpEUhot5+/H7n7Hj L/3PTMchJKzLdlZOdh/eA5fvIgyv5luLlDA1w96vxOQj/yT4/v+yGN6O2/AJTlzhtGkX EwaAsn2Vrxz0av0S48RJkq/ZMpEOkZYPpKq8ShKau76OPpnS6sKWXUW8KCricQfgi8gA 1NfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ZeoiyJr1; 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 pf6-20020a17090b1d8600b001fd8713170csi20306299pjb.179.2022.09.05.14.53.49; Mon, 05 Sep 2022 14:54:00 -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=ZeoiyJr1; 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 S238167AbiIEVM1 (ORCPT + 99 others); Mon, 5 Sep 2022 17:12:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236817AbiIEVLy (ORCPT ); Mon, 5 Sep 2022 17:11:54 -0400 Received: from out2.migadu.com (out2.migadu.com [IPv6:2001:41d0:2:aacc::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 469311A3B6 for ; Mon, 5 Sep 2022 14:11:23 -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=1662412281; 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=T0DFoi3F6F/yHkLbxOafy4/ej0Np4BxwTKaKbEY2PpY=; b=ZeoiyJr1jjpFNmkmG/13VDVsI2zwOCkgFnqbQoY0OmxGj7kDqkXITogtKnu2Vk/FQ6NTK2 RkCbHeSiCmGLbaA5/1yTvKbzKFMXrMg51IqxLvGvzMHaDaqIfF0JIYg1OYxXcSs+eq5wEV xCIucEo3Idwt/50BmiT7fZfQh8iRf1c= From: andrey.konovalov@linux.dev To: Andrew Morton Cc: Andrey Konovalov , Marco Elver , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Peter Collingbourne , Evgenii Stepanov , Florian Mayer , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm v3 33/34] kasan: better identify bug types for tag-based modes Date: Mon, 5 Sep 2022 23:05:48 +0200 Message-Id: <13ce7fa07d9d995caedd1439dfae4d51401842f2.1662411800.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.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 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. Reviewed-by: Marco Elver Signed-off-by: Andrey Konovalov --- mm/kasan/report_tags.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/mm/kasan/report_tags.c b/mm/kasan/report_tags.c index 57f7355377f1..d3510424d29b 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 @@ -37,9 +37,8 @@ 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; } @@ -84,6 +83,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) @@ -92,8 +98,19 @@ 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"; } } write_unlock_irqrestore(&stack_ring.lock, flags); + + /* 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