From mboxrd@z Thu Jan 1 00:00:00 1970 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=-23.7 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=unavailable 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 B3981C07E9B for ; Mon, 5 Jul 2021 10:45:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 93BF261474 for ; Mon, 5 Jul 2021 10:45:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231186AbhGEKsC (ORCPT ); Mon, 5 Jul 2021 06:48:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230168AbhGEKsB (ORCPT ); Mon, 5 Jul 2021 06:48:01 -0400 Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA2A6C061760 for ; Mon, 5 Jul 2021 03:45:23 -0700 (PDT) Received: by mail-ot1-x329.google.com with SMTP id i12-20020a05683033ecb02903346fa0f74dso17888880otu.10 for ; Mon, 05 Jul 2021 03:45:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=/dlGtZu9Ej/xN5Tsuqsmc/vVOMpJLibVcfVItFdDo7U=; b=rzSYkZK4ThrPA7smzcFNs/5Jpclbny/wcmfSQ8ORkq914C2DoGl0LnnmVaVBf+GSTU cLg454r3cKsTz8r0/LI3A8jiqvat498AEPySwnwQDrkBQB2Z8MPavannymAkadlwCbfx Csku08DMBzkEafDnNel69M7EN0kR7nB9LMem4pcRtUUH+kql+y8bf8n0b2GFWDknwps6 //spGXvECrbO40sSisf4xvjw2KfLYVu2/TIhODA91ZPkGbr3BWPAY+C8hUppoPo728RU VKby50aiKF843yEXxbKAGEFYcuw8/4FVbXCC7lfE5ubVb87wKWwmyU5A+9xmy94ciW/Z fe0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/dlGtZu9Ej/xN5Tsuqsmc/vVOMpJLibVcfVItFdDo7U=; b=tnn4Kzs6ikueu4Zg5cutvjqphMJnu2jDKwFQ1nAj8G+jmdP7iVjvzUhv0wFTXgsULd zPuAQWFwmY9DpgXL1D3pu6JctOcqTtifXV2tCcMSkWO89hEHMsEwqZvuRLyY19xOctDe zyiLhWnUmpbCJ0QrdGevxMi0k45Zjy94zVqU5Fw125bqnxhlh3nbMhrLEEUCkWBkz6Rm rSKLwMG8FNw9dg1KMmfPCg+OaHtrnP+MfWqQZeb4g59C8l8v1cLzcqPsVHjmusFjQwjL V65lTSHikhvz2rpbfcdWNUpnlotPUMz5ObZRqpFIbBx5VhgI/zYb6NgZ5XILwS+gc3Z6 g7GQ== X-Gm-Message-State: AOAM532lDelIG+5JHrzRx/GaaXVCv+pcqlakoBl+QvxnpjBgYdPDU1Ry nqzfIaNVBAG6PR4FXbZmTQeiNIi+WOa6T6YbZForGw== X-Google-Smtp-Source: ABdhPJz7Ojrr+OaKK7eh0H330aLKUBIAQgR26pV3/KDO8TkXS7oJOSMJQ2lq5muUp+LwEhxnKBOuBoP/AfYymTXkTok= X-Received: by 2002:a9d:d04:: with SMTP id 4mr10779395oti.251.1625481922714; Mon, 05 Jul 2021 03:45:22 -0700 (PDT) MIME-Version: 1.0 References: <20210705103229.8505-1-yee.lee@mediatek.com> <20210705103229.8505-3-yee.lee@mediatek.com> In-Reply-To: <20210705103229.8505-3-yee.lee@mediatek.com> From: Marco Elver Date: Mon, 5 Jul 2021 12:45:11 +0200 Message-ID: Subject: Re: [PATCH v6 2/2] kasan: Add memzero int for unaligned size at DEBUG To: yee.lee@mediatek.com Cc: linux-kernel@vger.kernel.org, nicholas.tang@mediatek.com, Kuan-Ying.Lee@mediatek.com, chinwen.chang@mediatek.com, Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Andrew Morton , Andrey Konovalov , Matthias Brugger , "open list:KASAN" , "open list:MEMORY MANAGEMENT" , "moderated list:ARM/Mediatek SoC support" , "moderated list:ARM/Mediatek SoC support" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 5 Jul 2021 at 12:33, wrote: > 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. > > The penalty is acceptable since they are only enabled in debug mode, > not production builds. A block of comment is added for explanation. > > Cc: Andrey Ryabinin > Cc: Alexander Potapenko > Cc: Dmitry Vyukov > Cc: Andrew Morton > Suggested-by: Marco Elver > Suggested-by: Andrey Konovalov > Signed-off-by: Yee Lee Reviewed-by: Marco Elver Thank you! > --- > mm/kasan/kasan.h | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h > index 98e3059bfea4..d739cdd1621a 100644 > --- a/mm/kasan/kasan.h > +++ b/mm/kasan/kasan.h > @@ -9,6 +9,7 @@ > #ifdef CONFIG_KASAN_HW_TAGS > > #include > +#include "../slab.h" > > DECLARE_STATIC_KEY_FALSE(kasan_flag_stacktrace); > extern bool kasan_flag_async __ro_after_init; > @@ -387,6 +388,17 @@ static inline void kasan_unpoison(const void *addr, size_t size, bool init) > > if (WARN_ON((unsigned long)addr & KASAN_GRANULE_MASK)) > return; > + /* > + * Explicitly initialize the memory with the precise object size to > + * avoid overwriting the SLAB redzone. This disables initialization in > + * the arch code and may thus lead to performance penalty. The penalty > + * is accepted since SLAB redzones aren't enabled in production builds. > + */ > + if (__slub_debug_enabled() && > + init && ((unsigned long)size & KASAN_GRANULE_MASK)) { > + init = false; > + memzero_explicit((void *)addr, size); > + } > size = round_up(size, KASAN_GRANULE_SIZE); > > hw_set_mem_tag_range((void *)addr, size, tag, init); > -- > 2.18.0 From mboxrd@z Thu Jan 1 00:00:00 1970 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=-23.7 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL 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 5EEE0C07E99 for ; Mon, 5 Jul 2021 10:45:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EC4CB6145D for ; Mon, 5 Jul 2021 10:45:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EC4CB6145D Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A7A446B0011; Mon, 5 Jul 2021 06:45:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A29CD6B0036; Mon, 5 Jul 2021 06:45:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8CA286B005D; Mon, 5 Jul 2021 06:45:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0185.hostedemail.com [216.40.44.185]) by kanga.kvack.org (Postfix) with ESMTP id 6A3C26B0011 for ; Mon, 5 Jul 2021 06:45:24 -0400 (EDT) Received: from smtpin34.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id DEFB418028E85 for ; Mon, 5 Jul 2021 10:45:23 +0000 (UTC) X-FDA: 78328202526.34.384CE0E Received: from mail-ot1-f52.google.com (mail-ot1-f52.google.com [209.85.210.52]) by imf16.hostedemail.com (Postfix) with ESMTP id 97DD1F000091 for ; Mon, 5 Jul 2021 10:45:23 +0000 (UTC) Received: by mail-ot1-f52.google.com with SMTP id r4-20020a0568301204b029047d1030ef5cso10975431otp.12 for ; Mon, 05 Jul 2021 03:45:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=/dlGtZu9Ej/xN5Tsuqsmc/vVOMpJLibVcfVItFdDo7U=; b=rzSYkZK4ThrPA7smzcFNs/5Jpclbny/wcmfSQ8ORkq914C2DoGl0LnnmVaVBf+GSTU cLg454r3cKsTz8r0/LI3A8jiqvat498AEPySwnwQDrkBQB2Z8MPavannymAkadlwCbfx Csku08DMBzkEafDnNel69M7EN0kR7nB9LMem4pcRtUUH+kql+y8bf8n0b2GFWDknwps6 //spGXvECrbO40sSisf4xvjw2KfLYVu2/TIhODA91ZPkGbr3BWPAY+C8hUppoPo728RU VKby50aiKF843yEXxbKAGEFYcuw8/4FVbXCC7lfE5ubVb87wKWwmyU5A+9xmy94ciW/Z fe0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/dlGtZu9Ej/xN5Tsuqsmc/vVOMpJLibVcfVItFdDo7U=; b=MnVZvqgSAxq+4VWjGsOXwk3yw+f31fA7NHCNoa5z6e3opvoLU7rbKEoJU4D7wkTpGh 1YHt04+zhhoyF1FgXBdioxpnKumW3ynPW5bIVOirv/yhsQnJK/nOv6RK7Gw68jZ+IkYq olzHKaQprP8vKyDv46k+aoji1Ti4mHCloCM5uOEPyje1Wt2MPOPjOMHmm/oWLvNwEAJ6 Fd/jiC8tNR96wOaEXw+V4DFF8AN0Dr+rDbisq+9Ptv9EHVh21Xro/uj0lFPq+KBaBaxo CRDu1r0IYqMpiVdw/EOIG96RsUa+W4SxEg/XwQkh7pAeo8uv2M2xLMnjIM4Jw0qK48Xf Y5WA== X-Gm-Message-State: AOAM531VxD6Rz9S5bVSVxfJGAfLOL89swpBov0vXwWPMz1kLb08hIq+f 5ef2zpkWbrtnPYAhohebfAd+RDJ7gr/hCrl25BT43A== X-Google-Smtp-Source: ABdhPJz7Ojrr+OaKK7eh0H330aLKUBIAQgR26pV3/KDO8TkXS7oJOSMJQ2lq5muUp+LwEhxnKBOuBoP/AfYymTXkTok= X-Received: by 2002:a9d:d04:: with SMTP id 4mr10779395oti.251.1625481922714; Mon, 05 Jul 2021 03:45:22 -0700 (PDT) MIME-Version: 1.0 References: <20210705103229.8505-1-yee.lee@mediatek.com> <20210705103229.8505-3-yee.lee@mediatek.com> In-Reply-To: <20210705103229.8505-3-yee.lee@mediatek.com> From: Marco Elver Date: Mon, 5 Jul 2021 12:45:11 +0200 Message-ID: Subject: Re: [PATCH v6 2/2] kasan: Add memzero int for unaligned size at DEBUG To: yee.lee@mediatek.com Cc: linux-kernel@vger.kernel.org, nicholas.tang@mediatek.com, Kuan-Ying.Lee@mediatek.com, chinwen.chang@mediatek.com, Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Andrew Morton , Andrey Konovalov , Matthias Brugger , "open list:KASAN" , "open list:MEMORY MANAGEMENT" , "moderated list:ARM/Mediatek SoC support" , "moderated list:ARM/Mediatek SoC support" Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=rzSYkZK4; spf=pass (imf16.hostedemail.com: domain of elver@google.com designates 209.85.210.52 as permitted sender) smtp.mailfrom=elver@google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: peurpnu3ccns5fmwjmu3syipx7r6hkjr X-Rspamd-Queue-Id: 97DD1F000091 X-Rspamd-Server: rspam06 X-HE-Tag: 1625481923-750958 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: On Mon, 5 Jul 2021 at 12:33, wrote: > 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. > > The penalty is acceptable since they are only enabled in debug mode, > not production builds. A block of comment is added for explanation. > > Cc: Andrey Ryabinin > Cc: Alexander Potapenko > Cc: Dmitry Vyukov > Cc: Andrew Morton > Suggested-by: Marco Elver > Suggested-by: Andrey Konovalov > Signed-off-by: Yee Lee Reviewed-by: Marco Elver Thank you! > --- > mm/kasan/kasan.h | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h > index 98e3059bfea4..d739cdd1621a 100644 > --- a/mm/kasan/kasan.h > +++ b/mm/kasan/kasan.h > @@ -9,6 +9,7 @@ > #ifdef CONFIG_KASAN_HW_TAGS > > #include > +#include "../slab.h" > > DECLARE_STATIC_KEY_FALSE(kasan_flag_stacktrace); > extern bool kasan_flag_async __ro_after_init; > @@ -387,6 +388,17 @@ static inline void kasan_unpoison(const void *addr, size_t size, bool init) > > if (WARN_ON((unsigned long)addr & KASAN_GRANULE_MASK)) > return; > + /* > + * Explicitly initialize the memory with the precise object size to > + * avoid overwriting the SLAB redzone. This disables initialization in > + * the arch code and may thus lead to performance penalty. The penalty > + * is accepted since SLAB redzones aren't enabled in production builds. > + */ > + if (__slub_debug_enabled() && > + init && ((unsigned long)size & KASAN_GRANULE_MASK)) { > + init = false; > + memzero_explicit((void *)addr, size); > + } > size = round_up(size, KASAN_GRANULE_SIZE); > > hw_set_mem_tag_range((void *)addr, size, tag, init); > -- > 2.18.0 From mboxrd@z Thu Jan 1 00:00:00 1970 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=-15.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 7DF14C07E99 for ; Mon, 5 Jul 2021 10:46:10 +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 42BF16145D for ; Mon, 5 Jul 2021 10:46:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 42BF16145D Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.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:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=wKLlkN/pafXh/QSG3qPZiqziE/RVKQXOCXLYlE5ZFeA=; b=aA5LOfXLOkiK7s Zah99gPmbyQbIpR7dv5LZ1MiNtXKhW9JPHd+MnGJ1cUCxjwkGnZZEb/rXFiux19A/M3LosJ4XqGjF oDjIcrdPsg/Ztq0AvyB1YdviMd44JlPytwUOn3eA2b3dfx1JrRcikjAlbdNDm7YKgDXyA2jbmPzcT 9UnLjrpCIAEEKDVxYl4zaYCOgUt56mYSJj8Jk5mVHlJsT19kUiDkL/7/TxzRf3KWjZZcX/7oZgROH IxKskG4ZMVxttSHFoqCNaEqxDtHLR11Ju1b7h0dmb4n8pfBlZgZ4v5DoFfUcZ21mkD7g/PhKXybM8 AKN/1sSZxk7IE1MvEpGA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m0M6z-008cv2-AB; Mon, 05 Jul 2021 10:46:01 +0000 Received: from mail-ot1-x32b.google.com ([2607:f8b0:4864:20::32b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m0M6O-008cm8-7p for linux-mediatek@lists.infradead.org; Mon, 05 Jul 2021 10:45:25 +0000 Received: by mail-ot1-x32b.google.com with SMTP id o13-20020a9d404d0000b0290466630039caso17908654oti.6 for ; Mon, 05 Jul 2021 03:45:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=/dlGtZu9Ej/xN5Tsuqsmc/vVOMpJLibVcfVItFdDo7U=; b=rzSYkZK4ThrPA7smzcFNs/5Jpclbny/wcmfSQ8ORkq914C2DoGl0LnnmVaVBf+GSTU cLg454r3cKsTz8r0/LI3A8jiqvat498AEPySwnwQDrkBQB2Z8MPavannymAkadlwCbfx Csku08DMBzkEafDnNel69M7EN0kR7nB9LMem4pcRtUUH+kql+y8bf8n0b2GFWDknwps6 //spGXvECrbO40sSisf4xvjw2KfLYVu2/TIhODA91ZPkGbr3BWPAY+C8hUppoPo728RU VKby50aiKF843yEXxbKAGEFYcuw8/4FVbXCC7lfE5ubVb87wKWwmyU5A+9xmy94ciW/Z fe0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/dlGtZu9Ej/xN5Tsuqsmc/vVOMpJLibVcfVItFdDo7U=; b=OO1/H3OxDa38NkIEeimvnbOp8G2ugh18Lk2EBe93FeP2HVVaVsRoN++oE2qRcFw/fB oECqMg921A9yOsJEs8zFv7YRFuJRzkCyukyuSvABcNjKbAuZlcnpOXOfz/1lLdry1BQW 1YGYA08s9bUC3eTGwXw8PhmZh0xLPzy0/CtOiwSYnMl5zZPLeCeGtZbBFy7KBAoCdeuk 1w3rQjj4lk0y4/7VWE8z8RhvLSBPt4D0i2GoTqKo+7ibl/tWc+v/Rh5zXsR6c1raepOB C5Px96jfwxQW/fPzcgfNfRxsN9ecDg0TjdPOWhSqI3PiD10A1aOLmFKga6Dw1U4r1c+q LKaQ== X-Gm-Message-State: AOAM531JM820/mjaKZbwFOe5RZqyY66TBeGCsZsPXiyESf8E1mFeEdzy mRYmtYx2vXHk9ypcXQ+OjWrbAdPym1Rq4zHaemLabg== X-Google-Smtp-Source: ABdhPJz7Ojrr+OaKK7eh0H330aLKUBIAQgR26pV3/KDO8TkXS7oJOSMJQ2lq5muUp+LwEhxnKBOuBoP/AfYymTXkTok= X-Received: by 2002:a9d:d04:: with SMTP id 4mr10779395oti.251.1625481922714; Mon, 05 Jul 2021 03:45:22 -0700 (PDT) MIME-Version: 1.0 References: <20210705103229.8505-1-yee.lee@mediatek.com> <20210705103229.8505-3-yee.lee@mediatek.com> In-Reply-To: <20210705103229.8505-3-yee.lee@mediatek.com> From: Marco Elver Date: Mon, 5 Jul 2021 12:45:11 +0200 Message-ID: Subject: Re: [PATCH v6 2/2] kasan: Add memzero int for unaligned size at DEBUG To: yee.lee@mediatek.com Cc: linux-kernel@vger.kernel.org, nicholas.tang@mediatek.com, Kuan-Ying.Lee@mediatek.com, chinwen.chang@mediatek.com, Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Andrew Morton , Andrey Konovalov , Matthias Brugger , "open list:KASAN" , "open list:MEMORY MANAGEMENT" , "moderated list:ARM/Mediatek SoC support" , "moderated list:ARM/Mediatek SoC support" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210705_034524_348989_95DCAFF5 X-CRM114-Status: GOOD ( 21.30 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org On Mon, 5 Jul 2021 at 12:33, wrote: > 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. > > The penalty is acceptable since they are only enabled in debug mode, > not production builds. A block of comment is added for explanation. > > Cc: Andrey Ryabinin > Cc: Alexander Potapenko > Cc: Dmitry Vyukov > Cc: Andrew Morton > Suggested-by: Marco Elver > Suggested-by: Andrey Konovalov > Signed-off-by: Yee Lee Reviewed-by: Marco Elver Thank you! > --- > mm/kasan/kasan.h | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h > index 98e3059bfea4..d739cdd1621a 100644 > --- a/mm/kasan/kasan.h > +++ b/mm/kasan/kasan.h > @@ -9,6 +9,7 @@ > #ifdef CONFIG_KASAN_HW_TAGS > > #include > +#include "../slab.h" > > DECLARE_STATIC_KEY_FALSE(kasan_flag_stacktrace); > extern bool kasan_flag_async __ro_after_init; > @@ -387,6 +388,17 @@ static inline void kasan_unpoison(const void *addr, size_t size, bool init) > > if (WARN_ON((unsigned long)addr & KASAN_GRANULE_MASK)) > return; > + /* > + * Explicitly initialize the memory with the precise object size to > + * avoid overwriting the SLAB redzone. This disables initialization in > + * the arch code and may thus lead to performance penalty. The penalty > + * is accepted since SLAB redzones aren't enabled in production builds. > + */ > + if (__slub_debug_enabled() && > + init && ((unsigned long)size & KASAN_GRANULE_MASK)) { > + init = false; > + memzero_explicit((void *)addr, size); > + } > size = round_up(size, KASAN_GRANULE_SIZE); > > hw_set_mem_tag_range((void *)addr, size, tag, init); > -- > 2.18.0 _______________________________________________ Linux-mediatek mailing list Linux-mediatek@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-mediatek From mboxrd@z Thu Jan 1 00:00:00 1970 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=-15.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 C6885C07E99 for ; Mon, 5 Jul 2021 10:47:14 +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 8CB9B613FC for ; Mon, 5 Jul 2021 10:47:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8CB9B613FC Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=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:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=XQ9jmlWk4PGuXIQjsUcKDlayVMfFTg3IRPr4CIWi2wk=; b=kyUzZMwFJh8Xtf cPd2euIQQwsjdyZoYhmy6mUKt/AR8eciM3/J5Vhf3SA/iptV5Uh/ZW2fQcnlh7f9mSX4eyh9dn2aA IxaI7neywdNYOcADggwKwS6xVUXCZZ8x9dcabizgbtwQr9gGW3kM7h7rmF3ah5pzKYgQtjjK54qqj +180cNJjAv/WHUwJHUsS16GjizH5wrOu4yQlXCr69d7lI1BDFqo3/gbh1sa92xRDm6jztuMfe6p2z gEmfWM8iik9EjDzRpXki63fTTVIY4QtNYhuwKe17yYqzuBuDBpXxsNA7t8krNRLTUuS35c11N8Kf3 ThyIj52SKasDEPGm1rCQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m0M6m-008cqt-2F; Mon, 05 Jul 2021 10:45:48 +0000 Received: from mail-ot1-x331.google.com ([2607:f8b0:4864:20::331]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m0M6O-008cm7-7m for linux-arm-kernel@lists.infradead.org; Mon, 05 Jul 2021 10:45:25 +0000 Received: by mail-ot1-x331.google.com with SMTP id 7-20020a9d0d070000b0290439abcef697so17928627oti.2 for ; Mon, 05 Jul 2021 03:45:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=/dlGtZu9Ej/xN5Tsuqsmc/vVOMpJLibVcfVItFdDo7U=; b=rzSYkZK4ThrPA7smzcFNs/5Jpclbny/wcmfSQ8ORkq914C2DoGl0LnnmVaVBf+GSTU cLg454r3cKsTz8r0/LI3A8jiqvat498AEPySwnwQDrkBQB2Z8MPavannymAkadlwCbfx Csku08DMBzkEafDnNel69M7EN0kR7nB9LMem4pcRtUUH+kql+y8bf8n0b2GFWDknwps6 //spGXvECrbO40sSisf4xvjw2KfLYVu2/TIhODA91ZPkGbr3BWPAY+C8hUppoPo728RU VKby50aiKF843yEXxbKAGEFYcuw8/4FVbXCC7lfE5ubVb87wKWwmyU5A+9xmy94ciW/Z fe0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/dlGtZu9Ej/xN5Tsuqsmc/vVOMpJLibVcfVItFdDo7U=; b=JFK8xOowUo+wuM0nfWhzYoAz3Lbt60iNvpB7dBbiM3oQo6VqE/WgrkRFZFS9ztC9cd 0RWAtgiCHaj8l1+ExGJqoAHC2mVPD+/6VEUWzJZ40C3niJSq5v27F82+h2aE4jNJg9QB JDfqJfN35n06Lp1gOtIH34EAcjgvD/DvvYQEWGGed4fSM00PNicW2/H3mSxzgA/tde8b 8REa040ZMpTqAXaj+CyDFbDw4FmASRiBGZqUFaldKX3XsUev+MG2MgN4gXztan7kbTfh zKkeBhUudWVhcRzOyqEx26+xn9Zkrz/ujo8OLwT7etqFloVFpjJO/ohM7jFj5DyHoExL 8WDw== X-Gm-Message-State: AOAM530HmHVFUwWMh3dzF2pOHsucQuCqJGN1sGO+3dQTMA6Bg3eRV4ls MZUhuIXGSpV+9Gh81qeu1SHZmfflT3uLZ61L0fIrPg== X-Google-Smtp-Source: ABdhPJz7Ojrr+OaKK7eh0H330aLKUBIAQgR26pV3/KDO8TkXS7oJOSMJQ2lq5muUp+LwEhxnKBOuBoP/AfYymTXkTok= X-Received: by 2002:a9d:d04:: with SMTP id 4mr10779395oti.251.1625481922714; Mon, 05 Jul 2021 03:45:22 -0700 (PDT) MIME-Version: 1.0 References: <20210705103229.8505-1-yee.lee@mediatek.com> <20210705103229.8505-3-yee.lee@mediatek.com> In-Reply-To: <20210705103229.8505-3-yee.lee@mediatek.com> From: Marco Elver Date: Mon, 5 Jul 2021 12:45:11 +0200 Message-ID: Subject: Re: [PATCH v6 2/2] kasan: Add memzero int for unaligned size at DEBUG To: yee.lee@mediatek.com Cc: linux-kernel@vger.kernel.org, nicholas.tang@mediatek.com, Kuan-Ying.Lee@mediatek.com, chinwen.chang@mediatek.com, Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Andrew Morton , Andrey Konovalov , Matthias Brugger , "open list:KASAN" , "open list:MEMORY MANAGEMENT" , "moderated list:ARM/Mediatek SoC support" , "moderated list:ARM/Mediatek SoC support" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210705_034524_341760_8212D722 X-CRM114-Status: GOOD ( 22.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, 5 Jul 2021 at 12:33, wrote: > 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. > > The penalty is acceptable since they are only enabled in debug mode, > not production builds. A block of comment is added for explanation. > > Cc: Andrey Ryabinin > Cc: Alexander Potapenko > Cc: Dmitry Vyukov > Cc: Andrew Morton > Suggested-by: Marco Elver > Suggested-by: Andrey Konovalov > Signed-off-by: Yee Lee Reviewed-by: Marco Elver Thank you! > --- > mm/kasan/kasan.h | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h > index 98e3059bfea4..d739cdd1621a 100644 > --- a/mm/kasan/kasan.h > +++ b/mm/kasan/kasan.h > @@ -9,6 +9,7 @@ > #ifdef CONFIG_KASAN_HW_TAGS > > #include > +#include "../slab.h" > > DECLARE_STATIC_KEY_FALSE(kasan_flag_stacktrace); > extern bool kasan_flag_async __ro_after_init; > @@ -387,6 +388,17 @@ static inline void kasan_unpoison(const void *addr, size_t size, bool init) > > if (WARN_ON((unsigned long)addr & KASAN_GRANULE_MASK)) > return; > + /* > + * Explicitly initialize the memory with the precise object size to > + * avoid overwriting the SLAB redzone. This disables initialization in > + * the arch code and may thus lead to performance penalty. The penalty > + * is accepted since SLAB redzones aren't enabled in production builds. > + */ > + if (__slub_debug_enabled() && > + init && ((unsigned long)size & KASAN_GRANULE_MASK)) { > + init = false; > + memzero_explicit((void *)addr, size); > + } > size = round_up(size, KASAN_GRANULE_SIZE); > > hw_set_mem_tag_range((void *)addr, size, tag, init); > -- > 2.18.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel