From patchwork Mon May 11 02:23:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Walter Wu X-Patchwork-Id: 11539611 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 1117715AB for ; Mon, 11 May 2020 02:24:12 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D201D24955 for ; Mon, 11 May 2020 02:24:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="vAnu9TQ3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D201D24955 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 E6D7D8E0007; Sun, 10 May 2020 22:24:10 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E1E598E0001; Sun, 10 May 2020 22:24:10 -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 D34FF8E0007; Sun, 10 May 2020 22:24:10 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0111.hostedemail.com [216.40.44.111]) by kanga.kvack.org (Postfix) with ESMTP id BC0F18E0001 for ; Sun, 10 May 2020 22:24:10 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 814D48248047 for ; Mon, 11 May 2020 02:24:10 +0000 (UTC) X-FDA: 76802843460.11.base27_7b92b9048f406 X-Spam-Summary: 2,0,0,20991a7a0123b28b,d41d8cd98f00b204,walter-zh.wu@mediatek.com,,RULES_HIT:41:69:355:379: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:2740: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:8660:8784:9025:10004:10400:10450:10455:11026:11218:11658:11914:12043:12048:12049:12291:12297:12438:12521:12555:12679:12683:12698:12737:13146:13148:13161:13200:13229:13230:14095:14096:14181:14394:14721:14819:19904:19999:21080:21212:21221:21347:21451:21627:21796:30036:30054:30070:30075,0,RBL:210.61.82.184:@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,MSF:not bul k,SPF:fp X-HE-Tag: base27_7b92b9048f406 X-Filterd-Recvd-Size: 5365 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by imf06.hostedemail.com (Postfix) with ESMTP for ; Mon, 11 May 2020 02:24:08 +0000 (UTC) X-UUID: e8a9aa12e5eb4e27a98022774341eb60-20200511 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=fxR+3x6dfchTUCq1rEZKfrKVHn0oaDflYS25MJ56o6M=; b=vAnu9TQ3FbuIrF8wU4vzOU5sqqWghpUrs9x0fLAwsRtuFYayO9kCTALc1ArZr7XJUi+tiALFmz3e/mrn8v0DwlL5AP/lygHox0AI6esw74tuSSFC614FNTRPY/oID0ncGP7kf7RLBffCDYGHkbDSQXlD0wxkE43IJaguXub4CT0=; X-UUID: e8a9aa12e5eb4e27a98022774341eb60-20200511 Received: from mtkcas07.mediatek.inc [(172.21.101.84)] by mailgw02.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0809 with TLS) with ESMTP id 510547924; Mon, 11 May 2020 10:24:03 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs01n2.mediatek.inc (172.21.101.79) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 11 May 2020 10:24:00 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 11 May 2020 10:24:00 +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 v2 0/3] kasan: memorize and print call_rcu stack Date: Mon, 11 May 2020 10:23:59 +0800 Message-ID: <20200511022359.15063-1-walter-zh.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 X-TM-SNTS-SMTP: B313EB8E7A005151BC9122FE7936DF9B364C35100A83A879C7D0BF8EF3E92D172000:8 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: save_stack+0x24/0x50 __kasan_slab_free+0x110/0x178 kasan_slab_free+0x10/0x18 kfree+0x98/0x270 kasan_rcu_reclaim+0x1c/0x60 rcu_core+0x8b4/0x10f8 rcu_core_si+0xc/0x18 efi_header_end+0x238/0xa6c First call_rcu() call stack: save_stack+0x24/0x50 kasan_record_callrcu+0xc8/0xd8 call_rcu+0x190/0x580 kasan_rcu_uaf+0x1d8/0x278 Last call_rcu() call stack: (stack is not available) Generic KASAN will record first and last call_rcu() call stack and print two call_rcu() call stack in KASAN report. This feature doesn't increase the cost of memory consumption. It is only suitable for generic KASAN. [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 Walter Wu (3): rcu/kasan: record and print call_rcu() call stack kasan: record and print the free track kasan: update documentation for generic kasan Documentation/dev-tools/kasan.rst | 6 ++++++ include/linux/kasan.h | 2 ++ kernel/rcu/tree.c | 4 ++++ lib/Kconfig.kasan | 2 ++ mm/kasan/common.c | 26 ++++---------------------- mm/kasan/generic.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ mm/kasan/kasan.h | 23 +++++++++++++++++++++++ mm/kasan/report.c | 47 +++++++++++++++++++++-------------------------- mm/kasan/tags.c | 37 +++++++++++++++++++++++++++++++++++++ 9 files changed, 149 insertions(+), 48 deletions(-)