From patchwork Fri May 22 01:57:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Walter Wu X-Patchwork-Id: 11564315 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 B5F7C1391 for ; Fri, 22 May 2020 01:58:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 838E72072C for ; Fri, 22 May 2020 01:58:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="cvdLQwfP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 838E72072C 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 41DB580008; Thu, 21 May 2020 21:58:17 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3CE0180007; Thu, 21 May 2020 21:58:17 -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 2E38C80008; Thu, 21 May 2020 21:58:17 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0137.hostedemail.com [216.40.44.137]) by kanga.kvack.org (Postfix) with ESMTP id 1476680007 for ; Thu, 21 May 2020 21:58:17 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id C20A1824805A for ; Fri, 22 May 2020 01:58:16 +0000 (UTC) X-FDA: 76842694992.29.rings64_653d5c8ac5905 X-Spam-Summary: 2,0,0,f27dbfdb5b43531b,d41d8cd98f00b204,walter-zh.wu@mediatek.com,,RULES_HIT:41:69:355:379:421:541:966:967:968:973:982: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:2731:2859:2892:2895:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3354:3653:3865:3866:3867:3868:3870:3871:3872:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4117:4250:4385:4605:5007:6119:6261:6653:6737:7875:7903:8603:8660:8784:9025:10004:10400:10450:10455:10945:11026:11218:11473:11658:11914:12043:12048:12049:12291:12296:12297:12438:12521:12555:12679:12683:12698:12737:13095:13148:13161:13200:13229:13230:14095:14096:14181:14394:14721:19904:19999:21080:21212:21221:21347:21433:21451:21627:21796:21939: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,Bayesia n:0.5,0. X-HE-Tag: rings64_653d5c8ac5905 X-Filterd-Recvd-Size: 6478 Received: from mailgw01.mediatek.com (unknown [210.61.82.183]) by imf14.hostedemail.com (Postfix) with ESMTP for ; Fri, 22 May 2020 01:58:15 +0000 (UTC) X-UUID: 5e4ea46496fb4a92a0a23d7d4553f0ee-20200522 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=Xb9E+XZkPSEUYQhPO9o49Hp+qlF6ImWZr8Z4BQKjcUw=; b=cvdLQwfPN36y3awG5CH+ce9CSDJKCJkYkKV6im0PIdKu3olLGhDwRGEz0LKechLD5wLAo4Coslzu9QUojKtF84rxi7KSa6e5V6V+rpxKqvtsmRD8rWugKivqeTuMwM4RV6SHRA64Tax49jAx04LAg1xeK+nzMciaI39W5yCe+Sk=; X-UUID: 5e4ea46496fb4a92a0a23d7d4553f0ee-20200522 Received: from mtkcas11.mediatek.inc [(172.21.101.40)] by mailgw01.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0809 with TLS) with ESMTP id 884651903; Fri, 22 May 2020 09:58:11 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs06n2.mediatek.inc (172.21.101.130) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 22 May 2020 09:58:07 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 22 May 2020 09:58:08 +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 , Andrey Konovalov CC: , , , , wsd_upstream , , Walter Wu Subject: [PATCH v6 0/4] kasan: memorize and print call_rcu stack Date: Fri, 22 May 2020 09:57:57 +0800 Message-ID: <20200522015757.22267-1-walter-zh.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 X-TM-SNTS-SMTP: 4A07CD0C78D35F1D1A3F7B59AA5C56C5D75035B244EFFD9341CF91B3C9B466812000: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: 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 call_rcu(): 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 Changes since v5: - add a macro KASAN_KMALLOC_FREETRACK in order to check whether print free stack - change printing message - remove descriptions in Kocong.kasan Changes since v6: - reuse print_stack() in print_track() 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/test_kasan.c | 30 ++++++++++++++++++++++++++++++ mm/kasan/common.c | 26 ++++---------------------- mm/kasan/generic.c | 43 +++++++++++++++++++++++++++++++++++++++++++ mm/kasan/generic_report.c | 1 + mm/kasan/kasan.h | 23 +++++++++++++++++++++-- mm/kasan/quarantine.c | 1 + mm/kasan/report.c | 54 +++++++++++++++++++++++++++--------------------------- mm/kasan/tags.c | 37 +++++++++++++++++++++++++++++++++++++ 11 files changed, 171 insertions(+), 51 deletions(-) Reviewed-by: Andrey Konovalov