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,URIBL_BLOCKED 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 33895C2B9F4 for ; Tue, 22 Jun 2021 15:23:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D8FE461289 for ; Tue, 22 Jun 2021 15:23:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D8FE461289 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 C5EDC6B0070; Tue, 22 Jun 2021 11:23:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C0FB56B0071; Tue, 22 Jun 2021 11:23:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A8AC26B0074; Tue, 22 Jun 2021 11:23:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0160.hostedemail.com [216.40.44.160]) by kanga.kvack.org (Postfix) with ESMTP id 7278B6B0070 for ; Tue, 22 Jun 2021 11:23:39 -0400 (EDT) Received: from forelay.prod.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by fograve04.hostedemail.com (Postfix) with ESMTP id 4D60F10F96 for ; Tue, 22 Jun 2021 14:04:05 +0000 (UTC) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 6FB1E8249980 for ; Tue, 22 Jun 2021 14:04:04 +0000 (UTC) X-FDA: 78281528808.23.3D08CAD Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) by imf11.hostedemail.com (Postfix) with ESMTP id 9734B20015FF for ; Tue, 22 Jun 2021 14:04:03 +0000 (UTC) Received: by mail-ed1-f44.google.com with SMTP id s15so23821538edt.13 for ; Tue, 22 Jun 2021 07:04:03 -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=iPbarU+l9m1KwGWUNyzhJZ595uUBAZXAe0wQ6HeHGxQ=; b=fZ5quJ/GoR3vzQSaVgMyRterjrZrpqo9hDF73so2ArtYbScuKnpfg7SJpZLlOeJRP3 gHIrQh6r2s7lxRe0jZfBM3LGiife/yusjkB2dfeDAKLJDltmFw71IvK22ZM2yulR8Gqt lUbJlqPikmDnu9MU6YfZERpi/kGM8dteQcDU4iAYgqoxjNX4cNxG8I0Z9GkAt4LvZnRT 1bdwtlbpmVBitmLQKdNwsM9mNUJ9uQf5FTai6gabf9yOPNikyYwD+FpS62jc9QvPwLbA smcPdUZucZZvzUBhYSMb27+LXgIv+ehd09ATJAp5W2ztoZDoWKXMu8WjiHQ1s3W7OOQu /WAQ== 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=iPbarU+l9m1KwGWUNyzhJZ595uUBAZXAe0wQ6HeHGxQ=; b=sx7yGXvoBe2sef1vkhuTh68m56/laulJ5+CPfHQbE2qr1us86fwRZYbVdS5iY8Ul9Y toVxP0xMYjADrVsSWyyaxfvc5uN4TDEuI9r6BwLaISN6nc8PbsyCXZwGlFSvBb+Ix0EK 4+k6dxqpNDsVQHFjySjFVr+DgoOEmuNj/JOc81LEZmtYmHZd/AE/G3ZrKdEYroVor+pu J9RbGXMK9H5FR14Ahk9Gt8BPDzFtqm6fK6WRsK/7h1WNebo4ll3kEt6oucs33wTRdXl/ b8gQK3/oySersV964poS8WnWV01od/0oldxQoFVW+k8TKkBoUwRpTVUyz9y2pqK7i8Be rJjA== X-Gm-Message-State: AOAM533e/ETexNCK3F36pbKxKVpLG7WbOZTFTsl9AOaxkWJq32C8qGm3 Cs2tTlf6O1tIGPZQNOYtnqvGNQ2hG9ibbkhOjRc= X-Google-Smtp-Source: ABdhPJyy8TmTF93FpLorqiyKQWA81gkRh7uJHO1hw4kf4OWfe0s6Kp5ze7cRnhKGAvUyoA9bAQOE4/Bt8SXdzX+GsFI= X-Received: by 2002:a50:fd83:: with SMTP id o3mr5199829edt.95.1624370642532; Tue, 22 Jun 2021 07:04:02 -0700 (PDT) MIME-Version: 1.0 References: <20210621154442.18463-1-yee.lee@mediatek.com> In-Reply-To: <20210621154442.18463-1-yee.lee@mediatek.com> From: Andrey Konovalov Date: Tue, 22 Jun 2021 17:03:42 +0300 Message-ID: Subject: Re: [PATCH] kasan: unpoison use memset to init unaligned object size 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" , Marco Elver Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b="fZ5quJ/G"; spf=pass (imf11.hostedemail.com: domain of andreyknvl@gmail.com designates 209.85.208.44 as permitted sender) smtp.mailfrom=andreyknvl@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: kx9oi741b74iuygx1ocef41iy6wj3kkd X-Rspamd-Queue-Id: 9734B20015FF X-Rspamd-Server: rspam06 X-HE-Tag: 1624370643-650959 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, Jun 21, 2021 at 6:45 PM wrote: > > From: Yee Lee > > This patch adds a memset to initialize object of unaligned size. > Duing to the MTE granulrity, the integrated initialization using > hwtag instruction will force clearing out bytes in granular size, > which may cause undesired effect, such as overwriting to the redzone > of SLUB debug. In this patch, for the unaligned object size, function > uses memset to initailize context instead of the hwtag instruction. > > Signed-off-by: Yee Lee > --- > mm/kasan/kasan.h | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h > index 8f450bc28045..d8faa64614b7 100644 > --- a/mm/kasan/kasan.h > +++ b/mm/kasan/kasan.h > @@ -387,8 +387,11 @@ static inline void kasan_unpoison(const void *addr, size_t size, bool init) > > if (WARN_ON((unsigned long)addr & KASAN_GRANULE_MASK)) > return; > + if (init && ((unsigned long)size & KASAN_GRANULE_MASK)) { > + init = false; > + memset((void *)addr, 0, size); > + } With this implementation, we loose the benefit of setting tags and initializing memory with the same instructions. Perhaps a better implementation would be to call hw_set_mem_tag_range() with the size rounded down, and then separately deal with the leftover memory. > size = round_up(size, KASAN_GRANULE_SIZE); > - > hw_set_mem_tag_range((void *)addr, size, tag, init); > } > > -- > 2.18.0 >