From patchwork Wed Jun 23 13:35:32 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: 12339849 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.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, 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 5FB78C4743C for ; Wed, 23 Jun 2021 13:36:09 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 2ECBE61026 for ; Wed, 23 Jun 2021 13:36:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2ECBE61026 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-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=v2LSXVXp0FiYe6Dx5e4BsvWPX4NqOC/U+CrMSAePIsY=; b=aN73RTv/f3JdiX lmuNI4iwv4sNAmoFkb+Lvoz5uGT4+Kqvs68gsgjyXN1ZHFUN5rCsWVYCeS4yfN9Zs41SEf79QNggd 6RpwxaW0PfIGjHSOqFolyt5dHY25RjomXdt9D7yqSMGsJEsrIPPfBWZACeX8VhV/+2UvArw+Zl2aC 60bJBAs16I+QvTOjinyBTLXwzxYo8w2TWwMBSJfLoz/W9/b4D4lmbPLTzU6S9Hsv3nVO0/iJw7C4v PGeTZ9RRU44huAwVcT7zfc1kYx9dxQPbm12MsnrzEbQX70RmbSyvuAaLCA6dFy6NX2oDq305i34n7 3RqzuKXbjG+mUDStkTwg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lw32q-00AplB-Eb; Wed, 23 Jun 2021 13:35:56 +0000 Received: from mailgw01.mediatek.com ([216.200.240.184]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lw32l-00ApkU-LI; Wed, 23 Jun 2021 13:35:54 +0000 X-UUID: f558436f6fa8477b9c597ced6620d25f-20210623 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=j7Ly1QQ9cVIZKTojMwqQxheF9osuhMIN7o324H9OuyU=; b=C1j8Nt9gBAR46h6RJGK1yRrIcKfqRosyEYjM6tOqiqlpHlFKZm9UwU7V1jZFL5iVZl/9hZ23EcemkIxUdzSX61prrnnR8cW7En2OZipB8Q/LwR/iEZHGTH51tG03wsrE02F93NPT4l08YlU2eFrLeJopowQwvRpZyaRjEW3LkWE=; X-UUID: f558436f6fa8477b9c597ced6620d25f-20210623 Received: from mtkcas68.mediatek.inc [(172.29.94.19)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1580966004; Wed, 23 Jun 2021 06:35:49 -0700 Received: from MTKMBS01N1.mediatek.inc (172.21.101.68) by MTKMBS62N2.mediatek.inc (172.29.193.42) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 23 Jun 2021 06:35:47 -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; Wed, 23 Jun 2021 21:35:40 +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, 23 Jun 2021 21:35:40 +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: Wed, 23 Jun 2021 21:35:32 +0800 Message-ID: <20210623133533.2246-2-yee.lee@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20210623133533.2246-1-yee.lee@mediatek.com> References: <20210623133533.2246-1-yee.lee@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210623_063552_071122_C36A1237 X-CRM114-Status: GOOD ( 12.10 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org From: Yee Lee Issue: when SLUB debug is on, hwtag kasan_unpoison() would overwrite the redzone with unaligned object size. An additional memzero_explicit() path is added to replacing hwtag initialization at SLUB deubg mode. Signed-off-by: Yee Lee Suggested-by: Marco Elver Cc: Andrey Ryabinin Cc: Alexander Potapenko Cc: Andrey Konovalov Cc: Dmitry Vyukov Cc: Andrew Morton --- mm/kasan/kasan.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index d8faa64614b7..e984a9ac814d 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -387,10 +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; - memset((void *)addr, 0, size); + memzero_explicit((void *)addr, size); } + #endif size = round_up(size, KASAN_GRANULE_SIZE); hw_set_mem_tag_range((void *)addr, size, tag, init); }