Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3983584pxj; Mon, 21 Jun 2021 10:46:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxmaM2xM/jvkhHFXFdm34fzIlao/x9/GTAIjmXVewXfRUOORHhNLMd0/4LjA8XWWpgT4NCq X-Received: by 2002:aa7:cc19:: with SMTP id q25mr23063375edt.56.1624297587400; Mon, 21 Jun 2021 10:46:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624297587; cv=none; d=google.com; s=arc-20160816; b=UtzzV2n6tLciQ8B5tnua/7X5NY6RjilP1IFlesgFYDPcptXBnqzHDgZHmx3w/zo+1j ZJNBT/hPq4xQdaXYZjHZYyN966TTfjzKKAYm5O4VzR0lcxwkMFNickSE1jmxOLUM1LiD 4O843Uqt1kt1u4KicoBZIhajUKyIoK1l9N+Hl2x1kdMXeWvY0Nfz3W2NpwJKqX0LG3aj y3xa316UNMvrFHrEYwC9Gg+Eu8jl0iMFdeTPsJzJ97tWz7JMPF8WP+Xi+dxa6M+bUU8x hdMY41HoFoB52m3XtioIWgCLXLshsz4VaFi23SyvByKpnbVabpJTS5QhQP4fbpZQWnoN ZaZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=kWdKmgG81sJBpjzyn6TSXwSeeJGUkRqGGWlo4fqoDn8=; b=daGelnSnv98RzkrODGSzrVwobdrqIH/Ho9iitNO2I7ko/rkMeAqDKOs3TbOpbYoBkf LEnv7ZA83IAS7zLOvJUvqWgvvcaSANgrTIuYluLH0xTND6D0sZh9s3k1PKx0DH1yEpZY n74OTdy5C4WEZrhC1U/MopbV/wB4cxWfUuaSA+SIBD82vAp1rN+l1WHQ6TAEvlgFwRDW v4oKbvDkye94wIduYJ03J90w7MhFgcUcYB6PPGla+KVdKtw+Sdpd/2XmgYWwzcHlmizB v0q6knAFarC8VOZMx9/cFrV4g++6v95BYV3eaHFMgt3MbtkfXvgaLgFTSS/h8UQlDH32 mNkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=CiXJ6n5G; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 7si12764471ejg.355.2021.06.21.10.46.03; Mon, 21 Jun 2021 10:46:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=CiXJ6n5G; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231411AbhFURpT (ORCPT + 99 others); Mon, 21 Jun 2021 13:45:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231357AbhFURpS (ORCPT ); Mon, 21 Jun 2021 13:45:18 -0400 Received: from mail-ot1-x331.google.com (mail-ot1-x331.google.com [IPv6:2607:f8b0:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D696AC061574 for ; Mon, 21 Jun 2021 10:43:02 -0700 (PDT) Received: by mail-ot1-x331.google.com with SMTP id v11-20020a9d340b0000b0290455f7b8b1dcso5616379otb.7 for ; Mon, 21 Jun 2021 10:43:02 -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=kWdKmgG81sJBpjzyn6TSXwSeeJGUkRqGGWlo4fqoDn8=; b=CiXJ6n5GdF+RiiNqGBO8F/j8UT/qhrN72JVb6QaRtPts6IKnis1CFRapxq7H+wy4y1 GWFo9rcHlHpgxkBuLl4FS+8nlfkbFdEK030ZBhpN6qPJyMdUafOT0hCU6NEZg+/cJrRf pfUzmq6g8hNiBVMMQmi5KfoIWhoTK5CYmbo4zeZ/tHEV5+AmXckA3wZ3WT3BZXuMYZhj NVF9LE5CuIVcXNVCX2rJkKM0UTagmKMDidAkcc234Ig0n0BY3qwZzxSC3tO838vQVzra HPm27NoxKSHr5adMk4M2O98++8T2eFSxAVl/o/Ma4PEiSFCcZeTUZXl2qx5wnX0IoVAk IjQw== 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=kWdKmgG81sJBpjzyn6TSXwSeeJGUkRqGGWlo4fqoDn8=; b=CTSPVmC0rcbyfIOM0z1iK2NNY9zyBLvn/Ag0EsjaKy2052/yqROyl6zvjDeJBZKemO SNsNw+WvXO+qgmlHKQnhaFJcTRrsoGab/mR1tgEm8XohZhcQDydVdfifHGw2TyNSbs0S cmj/KNDK60HCXKSRVFJnn0gwT/6+FQ0mi0ZbVp6nJcuHyOd8rs/ON8MEfu2i/RL9wbcq RK3nvL0ox6AtW0SlS2gCnIlr3hxCp6lp5KHrVlG27uzdY6D+mtD2ZK2SVGC+MAEQwJQ5 ly43bcYOkW90OhlfiHFbkulevMyafyYkZqtqN2xc8st55XkDk6YEbIvFiCqfbNGx6vu8 K6YQ== X-Gm-Message-State: AOAM533N6D5JnMTTsGPmjg7wGoSjgqJSaSaxFWYep7FWHKaOTpdq8r0S jZGIQon5PWuNHOYFfPsJMUtxxjdObvmMVmQeYGIH9w== X-Received: by 2002:a05:6830:93:: with SMTP id a19mr22053479oto.17.1624297381993; Mon, 21 Jun 2021 10:43:01 -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: Marco Elver Date: Mon, 21 Jun 2021 19:42:50 +0200 Message-ID: Subject: Re: [PATCH] kasan: unpoison use memset to init unaligned object size To: yee.lee@mediatek.com Cc: andreyknvl@gmail.com, 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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 21 Jun 2021 at 17:45, wrote: > > From: Yee Lee > > This patch adds a memset to initialize object of unaligned size. s/This patch adds/Add/ > Duing to the MTE granulrity, the integrated initialization using s/Duing/Doing/ s/granulrity/granularity/ > 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 Did you encounter a crash due to this? Was it only SLUB debug that caused the problem? Do you have data on what the percentage of allocations are that would now be treated differently? E.g. what's the percentage of such odd-sized allocations during a normal boot with SLUB debug off? We need to know if this change would pessimize a non-debug kernel, and if so, we'd have to make the below behave differently. > uses memset to initailize context instead of the hwtag instruction. s/initailize/initialize/ > 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); Should use memzero_explicit(). > + } > size = round_up(size, KASAN_GRANULE_SIZE); > - Remove whitespace change. > hw_set_mem_tag_range((void *)addr, size, tag, init); > } Thanks, -- Marco