From patchwork Fri Jul 10 16:21:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Walter Wu X-Patchwork-Id: 11657019 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 BC1B613B1 for ; Fri, 10 Jul 2020 16:23:22 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 94578206F4 for ; Fri, 10 Jul 2020 16:23:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="qd1kTWx7"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="AzVCRYD7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 94578206F4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=mediatek.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=dCjjyeCTKW7IO3lJQAnj1ahU8SVgYGqVQIXzsoLbqKc=; b=qd1kTWx7ocIFkThEIufOcH4X+o 6RHK01YI1KTuYH/M6rDyHfkjKAAD6LPP+aUODQI30GSS2xF5j/tLn7r9XifYfoHKUtzAk3yRhlqZJ ojWG+SRsDshSj8CMkXJlG7r2Yd0W/9I9tWDlwMcenYLUSOhA1qnG27TNd6/ckn9db4AO1BmmSbuvm lRwUWzZzaAX9v2hGvs4t9D5dUZdzOkYdtY8vePhk9xiCgiiJVu26Pz1qnZ605fYgsnjE1d7F+MvF+ jVJoMlb1lE0+Ib5g3ve0KkIV5hTRfq9TvD9zfkeNvrUqO4mV3QPwimI1zUuSsqW+4521iduOIBKqa 1/4jIfmA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jtvmQ-0000sA-P9; Fri, 10 Jul 2020 16:21:42 +0000 Received: from mailgw01.mediatek.com ([216.200.240.184]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jtvmM-0000pa-Tb; Fri, 10 Jul 2020 16:21:40 +0000 X-UUID: 92a4a382d6564fdf93af4c0849fc65a3-20200710 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=LoI2c6gi3jQYjLM5dZfi8Lk3EE1492i2ph2ScUkCE1Y=; b=AzVCRYD7jMgWJEFyBZY+6zeTRaliGMihlUhA11+g0uoFMyawWuun5mgYcrG8GYVaQP+1XOFLsj699ajE8k8Fq83mkiz+4kV6UYXQgIlgTw60oWy9VZ3mwZCWxIkbbonLdQspFncmBHaE5ET7HDVI4y+gYbkhZx/D2QjCpt+n+rk=; X-UUID: 92a4a382d6564fdf93af4c0849fc65a3-20200710 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 1396889665; Fri, 10 Jul 2020 08:21:32 -0800 Received: from MTKMBS06N1.mediatek.inc (172.21.101.129) by MTKMBS62N2.mediatek.inc (172.29.193.42) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 10 Jul 2020 09:21:30 -0700 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs06n1.mediatek.inc (172.21.101.129) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 11 Jul 2020 00:21:29 +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; Sat, 11 Jul 2020 00:21:30 +0800 From: Walter Wu To: Andrew Morton Subject: [PATCH v8 0/4] kasan: memorize and print call_rcu stack Date: Sat, 11 Jul 2020 00:21:23 +0800 Message-ID: <20200710162123.23713-1-walter-zh.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200710_122139_104564_A23EEAF1 X-CRM114-Status: GOOD ( 14.56 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 MIME_BASE64_TEXT RAW: Message text disguised using base64 encoding -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.0 UNPARSEABLE_RELAY Informational: message has unparseable relay lines X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Walter Wu , wsd_upstream , Andrey Konovalov , linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , linux-arm-kernel@lists.infradead.org, Matthias Brugger , Andrey Ryabinin , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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 , lets 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 v1: - 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 v2: - 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 v3: - change variable name to be more clearly - remove the redundant condition - remove init free meta-data and increasing object condition Changes since v4: - add a macro KASAN_KMALLOC_FREETRACK in order to check whether print free stack - change printing message - remove descriptions in Kocong.kasan Changes since v5: - reuse print_stack() in print_track() Changes since v6: - fix typo - renamed the variable name in testcase Changes since v7: - fix this commit dependence in the series 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(-)