From patchwork Tue Jun 22 08:47:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?WWVlIExlZSAo5p2O5bu66Kq8KQ==?= X-Patchwork-Id: 12336619 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MIME_BASE64_TEXT,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56438C48BDF for ; Tue, 22 Jun 2021 08:55:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E52F86108E for ; Tue, 22 Jun 2021 08:55:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E52F86108E 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 170906B0036; Tue, 22 Jun 2021 04:55:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 121176B0062; Tue, 22 Jun 2021 04:55:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EDC096B006C; Tue, 22 Jun 2021 04:55:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0254.hostedemail.com [216.40.44.254]) by kanga.kvack.org (Postfix) with ESMTP id BAF636B0036 for ; Tue, 22 Jun 2021 04:55:40 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 4C623BEF0 for ; Tue, 22 Jun 2021 08:55:40 +0000 (UTC) X-FDA: 78280751640.23.48713AB Received: from mailgw02.mediatek.com (mailgw02.mediatek.com [216.200.240.185]) by imf30.hostedemail.com (Postfix) with ESMTP id 74BC4E0009B6 for ; Tue, 22 Jun 2021 08:55:36 +0000 (UTC) X-UUID: c6a04d9e855d4b9fb7d476e41208e16a-20210622 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=7i5vombE2LgwFykIPcGk4y+2hu2bStqgOtES8TP4NYo=; b=nXdlmaahLXYSVdifLiqXc4ID1MDL4yEI6Em9HNYvlV+T0sCD7h9zLEUJZXX4mUDQhKLEbY8qsv20MjSrTpqw/v/khvU0igOMwpWtkNkl0mRsr92W6gK10UyNg/EURrlSNHDXiy8XIW4FerSnQJ6nOTnbO4H7YWjhfnDyJVRpxA0=; X-UUID: c6a04d9e855d4b9fb7d476e41208e16a-20210622 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 359449174; Tue, 22 Jun 2021 01:55:24 -0700 Received: from MTKMBS01N1.mediatek.inc (172.21.101.68) by MTKMBS62N1.mediatek.inc (172.29.193.41) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 22 Jun 2021 01:47:59 -0700 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; Tue, 22 Jun 2021 16:47:58 +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; Tue, 22 Jun 2021 16:47:57 +0800 From: To: CC: , Yee Lee , "Andrey Ryabinin" , Alexander Potapenko , Dmitry Vyukov , Andrew Morton , Matthias Brugger , "open list:KASAN" , "open list:MEMORY MANAGEMENT" , open list , "moderated list:ARM/Mediatek SoC support" , "moderated list:ARM/Mediatek SoC support" Subject: [PATCH] kasan: [v2]unpoison use memzero to init unaligned object Date: Tue, 22 Jun 2021 16:47:20 +0800 Message-ID: <20210622084723.27637-1-yee.lee@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 X-MTK: N Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=mediatek.com header.s=dk header.b=nXdlmaah; dmarc=pass (policy=none) header.from=mediatek.com; spf=pass (imf30.hostedemail.com: domain of yee.lee@mediatek.com designates 216.200.240.185 as permitted sender) smtp.mailfrom=yee.lee@mediatek.com X-Rspamd-Server: rspam02 X-Stat-Signature: zfsebyy63ir5osnsfcm4fjt846e9ttiz X-Rspamd-Queue-Id: 74BC4E0009B6 X-HE-Tag: 1624352136-762868 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: From: Yee Lee Follows the discussion: https://patchwork.kernel.org/project/linux-mediatek/list/?series=504439 This patch Add memzero_explict to initialize unaligned object. Based on the integrateion of initialization in kasan_unpoison(). The hwtag instructions, constrained with its granularity, has to overwrite the data btyes in unaligned objects. This would cause issue when it works with SLUB debug redzoning. In this patch, an additional initalizaing path is added for the unaligned objects. It contains memzero_explict() to clear out the data and disables its init flag for the following hwtag actions. In lab test, this path is executed about 1.1%(941/80854) within the overall kasan_unpoison during a non-debug booting process. Lab test: QEMU5.2 (+mte) / linux kernel 5.13-rc7 Signed-off-by: Yee Lee --- mm/kasan/kasan.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 2.18.0 diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index d8faa64614b7..edc11bcc3ff3 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -389,7 +389,7 @@ static inline void kasan_unpoison(const void *addr, size_t size, bool init) return; if (init && ((unsigned long)size & KASAN_GRANULE_MASK)) { init = false; - memset((void *)addr, 0, size); + memzero_explicit((void *)addr, size); } size = round_up(size, KASAN_GRANULE_SIZE); hw_set_mem_tag_range((void *)addr, size, tag, init);