From patchwork Wed May 6 05:18:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Walter Wu X-Patchwork-Id: 11530211 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 BBC9314B4 for ; Wed, 6 May 2020 05:19:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7F44020721 for ; Wed, 6 May 2020 05:19:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="cfZMNlqW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7F44020721 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 6C8B48E0005; Wed, 6 May 2020 01:19:04 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 677F38E0003; Wed, 6 May 2020 01:19:04 -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 58D9F8E0005; Wed, 6 May 2020 01:19:04 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0153.hostedemail.com [216.40.44.153]) by kanga.kvack.org (Postfix) with ESMTP id 442498E0003 for ; Wed, 6 May 2020 01:19:04 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 00FF2180AD806 for ; Wed, 6 May 2020 05:19:04 +0000 (UTC) X-FDA: 76785140208.03.title82_31e8956cebc56 X-Spam-Summary: 2,0,0,be864ff16f42433e,d41d8cd98f00b204,walter-zh.wu@mediatek.com,,RULES_HIT:41:355:379:541:966:967:973:988:989:1185:1260:1277:1311:1313:1314:1345:1437:1514:1515:1516:1518:1534:1541:1585:1711:1730:1747:1777:1792:1981:2194:2196:2198:2199:2200:2201:2393:2525:2559:2563:2682:2685:2740:2859:2892:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3352:3865:3866:3867:3868:3870:3871:3872:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4250:4385:4605:5007:6119:6261:6653:7903:8660:9025:10004:10400:10450:10455:11026:11473:11658:11914:12043:12048:12291:12297:12438:12521:12555:12679:12683:12698:12737:13069:13146:13148:13161:13200:13229:13230:13311:13357:14095:14181:14394:14721:14819:19904:19999:21080:21212:21220:21451:21627:30054:30070:30075,0,RBL:210.61.82.184:@mediatek.com:.lbl8.mailshell.net-64.100.201.201 62.2.12.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:104, LUA_SUMM X-HE-Tag: title82_31e8956cebc56 X-Filterd-Recvd-Size: 4637 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by imf40.hostedemail.com (Postfix) with ESMTP for ; Wed, 6 May 2020 05:19:02 +0000 (UTC) X-UUID: 86d09f1015a844cb9f53b78527a4df92-20200506 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=uJZg8sC2cd+BcgzYcwDrLwJbXHxd7+JuJtTz708pa/0=; b=cfZMNlqWK3x2jhkWQIAI1mvtjTFqhnQOWzsv0VY4UeJ+xlT9PZDUPwumH2oOrWUqxhk6QeGNY+aoaYIUkt6BZk2AHRrmPhVdNs9EQ3IjAlC8ynAJ/hFh5ahpaDaPXVfAeCIuoJfsCqGy4qnCLeL17LN0/SROQKOEdu8WvkN1aPY=; X-UUID: 86d09f1015a844cb9f53b78527a4df92-20200506 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] by mailgw02.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0809 with TLS) with ESMTP id 1650363527; Wed, 06 May 2020 13:18:57 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs01n1.mediatek.inc (172.21.101.68) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 6 May 2020 13:18:55 +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; Wed, 6 May 2020 13:18:54 +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 0/3] kasan: memorize and print call_rcu stack Date: Wed, 6 May 2020 13:18:53 +0800 Message-ID: <20200506051853.14380-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 helpful 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) Add new CONFIG option to record first and last call_rcu() call stack and KASAN report prints two call_rcu() call stack. This option 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 Walter Wu (3): rcu/kasan: record and print call_rcu() call stack kasan: record and print the free track kasan: add KASAN_RCU_STACK_RECORD documentation Documentation/dev-tools/kasan.rst | 21 +++++++++++++++++++++ include/linux/kasan.h | 7 +++++++ kernel/rcu/tree.c | 5 +++++ lib/Kconfig.kasan | 11 +++++++++++ mm/kasan/common.c | 31 +++++++++++++++++++++++++++++++ mm/kasan/kasan.h | 12 ++++++++++++ mm/kasan/report.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++------- 7 files changed, 133 insertions(+), 7 deletions(-)