From patchwork Thu Jun 24 11:26:21 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: 12341963 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 BDA0AC48BDF for ; Thu, 24 Jun 2021 11:33:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 63971611C1 for ; Thu, 24 Jun 2021 11:33:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 63971611C1 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 3F4BC6B0036; Thu, 24 Jun 2021 07:33:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3CC206B005D; Thu, 24 Jun 2021 07:33:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 26C646B006C; Thu, 24 Jun 2021 07:33:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0093.hostedemail.com [216.40.44.93]) by kanga.kvack.org (Postfix) with ESMTP id E4FF26B0036 for ; Thu, 24 Jun 2021 07:33: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 0E7FF18018776 for ; Thu, 24 Jun 2021 11:33:05 +0000 (UTC) X-FDA: 78288405930.03.953E22C Received: from mailgw01.mediatek.com (mailgw01.mediatek.com [216.200.240.184]) by imf11.hostedemail.com (Postfix) with ESMTP id 591B920010A2 for ; Thu, 24 Jun 2021 11:33:03 +0000 (UTC) X-UUID: 95c0659d6c8844f1b852be4b790070aa-20210624 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:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=i1AvuZtSs+o2XcfvVoK11/Tb21f5bi3suSgdX1pUujE=; b=HOYYgsXBX4d1fztjcMqk0Z7guBCvK448i5v3N3auLR0ytVYpiKmAQPZNxT7OBaUoghTSALXbIHYTK4lLN6Gy3MyrXIqgrqPON7t3tm6g2p7ldpC/cds9BLGhXfKp39w/AWimd2IalrosMkqVAnsx6wHqQ1PKILdBRG/4988D4aU=; X-UUID: 95c0659d6c8844f1b852be4b790070aa-20210624 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1009943976; Thu, 24 Jun 2021 04:32:54 -0700 Received: from MTKMBS01N1.mediatek.inc (172.21.101.68) by MTKMBS62DR.mediatek.inc (172.29.94.18) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 24 Jun 2021 04:26:54 -0700 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs01n1.mediatek.inc (172.21.101.68) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 24 Jun 2021 19:26:53 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 24 Jun 2021 19:26:53 +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 v2 1/1] kasan: Add memzero init for unaligned size under SLUB debug Date: Thu, 24 Jun 2021 19:26:21 +0800 Message-ID: <20210624112624.31215-2-yee.lee@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20210624112624.31215-1-yee.lee@mediatek.com> References: <20210624112624.31215-1-yee.lee@mediatek.com> MIME-Version: 1.0 X-MTK: N X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 591B920010A2 X-Stat-Signature: uhtqsm197bhnq33uhz466jpcxitwi8gz Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=mediatek.com header.s=dk header.b=HOYYgsXB; dmarc=pass (policy=none) header.from=mediatek.com; spf=pass (imf11.hostedemail.com: domain of yee.lee@mediatek.com designates 216.200.240.184 as permitted sender) smtp.mailfrom=yee.lee@mediatek.com X-HE-Tag: 1624534383-546510 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 Issue: when SLUB debug is on, hwtag kasan_unpoison() would overwrite the redzone of object with unaligned size. An additional memzero_explicit() path is added to replacing init by hwtag instruction for those unaligned size at SLUB debug mode. Signed-off-by: Yee Lee --- mm/kasan/kasan.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 8f450bc28045..d1054f35838f 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -387,6 +387,12 @@ static inline void kasan_unpoison(const void *addr, size_t size, bool init) if (WARN_ON((unsigned long)addr & KASAN_GRANULE_MASK)) return; +#if IS_ENABLED(CONFIG_SLUB_DEBUG) + if (init && ((unsigned long)size & KASAN_GRANULE_MASK)) { + init = false; + memzero_explicit((void *)addr, size); + } +#endif size = round_up(size, KASAN_GRANULE_SIZE); hw_set_mem_tag_range((void *)addr, size, tag, init);