From patchwork Tue May 19 02:23:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Walter Wu X-Patchwork-Id: 11556779 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1C8D4739 for ; Tue, 19 May 2020 02:23:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DD4F020758 for ; Tue, 19 May 2020 02:23:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="bo4ndfY0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DD4F020758 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=mediatek.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 166FC900003; Mon, 18 May 2020 22:23:33 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 11985900002; Mon, 18 May 2020 22:23:33 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 02E32900003; Mon, 18 May 2020 22:23:32 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0162.hostedemail.com [216.40.44.162]) by kanga.kvack.org (Postfix) with ESMTP id E0BEF900002 for ; Mon, 18 May 2020 22:23:32 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 77E43181AEF10 for ; Tue, 19 May 2020 02:23:32 +0000 (UTC) X-FDA: 76831872264.21.grade10_1a6965807811 X-Spam-Summary: 2,0,0,ad92c315a4ba4aac,d41d8cd98f00b204,walter-zh.wu@mediatek.com,,RULES_HIT:41:69:355:379:421:541:966:967:968:973:988:989:1185:1260:1277:1311:1313:1314:1345:1437:1514:1515:1516:1518:1535:1542:1585:1711:1719:1730:1747:1777:1792:1981:2194:2196:2197:2198:2199:2200:2201:2202:2393:2525:2559:2564:2682:2685:2693:2859:2892:2895:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3353:3653:3865:3866:3867:3868:3870:3871:3872:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4250:4385:4605:5007:6119:6261:6653:7875:7903:8603:8660:8784:9025:10004:10400:10450:10455:10945:11026:11218:11658:11914:12043:12048:12049:12291:12296:12297:12438:12521:12555:12679:12683:12698:12737:13148:13161:13200:13229:13230:14095:14096:14181:14394:14721:19904:19999:21080:21212:21221:21347:21451:21627:21796:30029:30036:30054:30070:30075,0,RBL:210.61.82.183:@mediatek.com:.lbl8.mailshell.net-62.14.12.100 64.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,M SF:not b X-HE-Tag: grade10_1a6965807811 X-Filterd-Recvd-Size: 5948 Received: from mailgw01.mediatek.com (unknown [210.61.82.183]) by imf23.hostedemail.com (Postfix) with ESMTP for ; Tue, 19 May 2020 02:23:31 +0000 (UTC) X-UUID: 1287ad98d3fb47f4bb82707ef0185cdb-20200519 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=pahJ2L0gjM1kDa0csOJAjHWKOME8knEXrsVPb3ccsfw=; b=bo4ndfY0hbuUhMe9tTnbuLff343NTH8JGpMrZT4hKjayI5YTRTH94/0WYhBCs9pqriImvf1z6tT1a/ea1EmrJSP23vB+Fls35RQe2iWBmln93pIhCyJCDyNN3g7EJ8C/GiCZQk4eiiYh3netXZ8P7/rAdEQ5tLws0wbVBnmrA1Q=; X-UUID: 1287ad98d3fb47f4bb82707ef0185cdb-20200519 Received: from mtkcas06.mediatek.inc [(172.21.101.30)] by mailgw01.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0809 with TLS) with ESMTP id 1620647460; Tue, 19 May 2020 10:23:25 +0800 Received: from mtkcas08.mediatek.inc (172.21.101.126) by mtkmbs01n1.mediatek.inc (172.21.101.68) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 19 May 2020 10:23:24 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas08.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 19 May 2020 10:23:24 +0800 From: Walter Wu To: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Matthias Brugger , "Paul E . McKenney" , Josh Triplett , Mathieu Desnoyers , Lai Jiangshan , Joel Fernandes , Andrew Morton CC: , , , , wsd_upstream , , Walter Wu Subject: [PATCH v4 0/4] kasan: memorize and print call_rcu stack Date: Tue, 19 May 2020 10:23:22 +0800 Message-ID: <20200519022322.24053-1-walter-zh.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 X-MTK: N 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: This patchset improves KASAN reports by making them to have call_rcu() call stack information. It is useful for programmers to solve use-after-free or double-free memory issue. The KASAN report was as follows(cleaned up slightly): BUG: KASAN: use-after-free in kasan_rcu_reclaim+0x58/0x60 Freed by task 0: kasan_save_stack+0x24/0x50 kasan_set_track+0x24/0x38 kasan_set_free_info+0x18/0x20 __kasan_slab_free+0x10c/0x170 kasan_slab_free+0x10/0x18 kfree+0x98/0x270 kasan_rcu_reclaim+0x1c/0x60 Last one call_rcu() call stack: kasan_save_stack+0x24/0x50 kasan_record_aux_stack+0xbc/0xd0 call_rcu+0x8c/0x580 kasan_rcu_uaf+0xf4/0xf8 Generic KASAN will record the last two call_rcu() call stacks and print up to 2 call_rcu() call stacks in KASAN report. it is only suitable for generic KASAN. This feature considers the size of struct kasan_alloc_meta and kasan_free_meta, we try to optimize the structure layout and size , let it get better memory consumption. [1]https://bugzilla.kernel.org/show_bug.cgi?id=198437 [2]https://groups.google.com/forum/#!searchin/kasan-dev/better$20stack$20traces$20for$20rcu%7Csort:date/kasan-dev/KQsjT_88hDE/7rNUZprRBgAJ Changes since v2: - remove new config option, default enable it in generic KASAN - test this feature in SLAB/SLUB, it is pass. - modify macro to be more clearly - modify documentation Changes since v3: - change recording from first/last to the last two call stacks - move free track into kasan free meta - init slab_free_meta on object slot creation - modify documentation Changes since v4: - change variable name to be more clearly - remove the redundant condition - remove init free meta-data and increasing object condition Walter Wu (4): rcu/kasan: record and print call_rcu() call stack kasan: record and print the free track kasan: add tests for call_rcu stack recording kasan: update documentation for generic kasan Documentation/dev-tools/kasan.rst | 3 +++ include/linux/kasan.h | 2 ++ kernel/rcu/tree.c | 2 ++ lib/Kconfig.kasan | 2 ++ lib/test_kasan.c | 30 ++++++++++++++++++++++++++++++ mm/kasan/common.c | 26 ++++---------------------- mm/kasan/generic.c | 37 +++++++++++++++++++++++++++++++++++++ mm/kasan/kasan.h | 17 +++++++++++++++++ mm/kasan/report.c | 36 ++++++++++++++++++++---------------- mm/kasan/tags.c | 37 +++++++++++++++++++++++++++++++++++++ 10 files changed, 154 insertions(+), 38 deletions(-)