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=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 A163DC2B9F4 for ; Fri, 25 Jun 2021 14:03:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1ACE2616ED for ; Fri, 25 Jun 2021 14:03:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1ACE2616ED Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id CB7FA6B0036; Fri, 25 Jun 2021 10:03:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C675B6B005D; Fri, 25 Jun 2021 10:03:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B078E6B006C; Fri, 25 Jun 2021 10:03:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0168.hostedemail.com [216.40.44.168]) by kanga.kvack.org (Postfix) with ESMTP id 808FC6B0036 for ; Fri, 25 Jun 2021 10:03:46 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id ACD81127A2 for ; Fri, 25 Jun 2021 14:03:46 +0000 (UTC) X-FDA: 78292414452.12.B84A836 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) by imf02.hostedemail.com (Postfix) with ESMTP id 7B2F44202A32 for ; Fri, 25 Jun 2021 14:03:45 +0000 (UTC) Received: by mail-ej1-f42.google.com with SMTP id bg14so15258440ejb.9 for ; Fri, 25 Jun 2021 07:03:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=KCBPWXjUtJqDX481tplGmByedXmi+6SSSYQlopDVlm8=; b=g2xI4G+YbXPOBweU0Dfhxgv8sAgTFjbLRxRY9HnhBIJ7t5750aZ2AnfPNLCZChITxz e9Yo/swOJ5U1cF9kBUv8dI/7589kD4AZiZBgJwj+exGZnoVksbjpyl7e0/BN5vAQfWv6 /VXekcwiU8mYzSd1XvznpHZOiHKkHaZiSiQ+oCpAVQCWkYKQs79Xt0o7EPj4sXlIUNO3 1WhKzAfHJucTboztqcpWrkg3AIrya5Bjw25wWjYqzOZSch6BNQkAuqg7m1wQhDCzFOTI V2Ulu0v2PpcsdfkXJBJ29grL9PL7XZ9xga6QgiyEoU5CU3O4wWbre7BvkL66xvJL9OiJ UNtQ== 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=KCBPWXjUtJqDX481tplGmByedXmi+6SSSYQlopDVlm8=; b=ZIh73B77Bpj1hG3B4z/Ba+p0MMFn7k0Tk+vbwJ6CNmo77cA7CZUXPLuDrVQygPZ8Bk j7BEVYy/SxcD8r1NI5864hqmL5bV69UK9jndTu/sBhJCl34Zf7fTyIIma7Ff9BV8qgxI ySn3sl6Lof3U1E1FAU94YWg9fZKuz3ZcCNvIwDXSgu4WSjvyA3YLQtD8d/x+W5EwGn25 zTKizD4Av33Dh6fUKf61qRjfkBs2x3Zdeq0Vi1kG+96h7C1k1llu0TuFrWvJCQwOm+Kl jGZA6dpHae0Xfj9CKjLeqlxFOyCM/RgEAZMBG7kIGvVGOayic1v2XLx8aZUO2rmQV6b3 o95w== X-Gm-Message-State: AOAM533A7q6QaMBVpf+dc13EJGVkW7MdbpEnzUNKqd2siJi09XWvl9rV hCeH4mwvxB3/wV8moTClfzwfGrrDZZuHSqTJwyk= X-Google-Smtp-Source: ABdhPJwRxAwp1s4YjTUqcX/AAdgKGNstFB5jd3lyos+3LPa3ijtjUuFxbmNzJUzvo6qSGiT+GSa9ZkA6wg579vc/N0Q= X-Received: by 2002:a17:906:6d16:: with SMTP id m22mr11315367ejr.333.1624629824272; Fri, 25 Jun 2021 07:03:44 -0700 (PDT) MIME-Version: 1.0 References: <20210624112624.31215-1-yee.lee@mediatek.com> <20210624112624.31215-2-yee.lee@mediatek.com> In-Reply-To: <20210624112624.31215-2-yee.lee@mediatek.com> From: Andrey Konovalov Date: Fri, 25 Jun 2021 17:03:21 +0300 Message-ID: Subject: Re: [PATCH v2 1/1] kasan: Add memzero init for unaligned size under SLUB debug To: yee.lee@mediatek.com Cc: wsd_upstream@mediatek.com, 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" Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=g2xI4G+Y; spf=pass (imf02.hostedemail.com: domain of andreyknvl@gmail.com designates 209.85.218.42 as permitted sender) smtp.mailfrom=andreyknvl@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 7B2F44202A32 X-Stat-Signature: bxkugztx31kwtcrntyp8rmj5omo9w7d1 X-HE-Tag: 1624629825-965378 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 Thu, Jun 24, 2021 at 2:26 PM 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. > > 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) Is this an issue only with SLUB? SLAB also uses redzones. > + if (init && ((unsigned long)size & KASAN_GRANULE_MASK)) { This needs a comment along the lines of: /* 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. */ > + 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); > -- > 2.18.0 >