Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3DB63C433EF for ; Fri, 10 Dec 2021 17:49:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244748AbhLJRwe (ORCPT ); Fri, 10 Dec 2021 12:52:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230526AbhLJRwc (ORCPT ); Fri, 10 Dec 2021 12:52:32 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 300F8C061746 for ; Fri, 10 Dec 2021 09:48:56 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 7C8D7CE2C70 for ; Fri, 10 Dec 2021 17:48:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94365C00446; Fri, 10 Dec 2021 17:48:49 +0000 (UTC) Date: Fri, 10 Dec 2021 17:48:46 +0000 From: Catalin Marinas To: andrey.konovalov@linux.dev Cc: Marco Elver , Alexander Potapenko , Vincenzo Frascino , Peter Collingbourne , Andrey Konovalov , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Andrew Morton , linux-mm@kvack.org, Will Deacon , Mark Rutland , linux-arm-kernel@lists.infradead.org, Evgenii Stepanov , linux-kernel@vger.kernel.org, Andrey Konovalov Subject: Re: [PATCH v2 08/34] kasan: only apply __GFP_ZEROTAGS when memory is zeroed Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 06, 2021 at 10:43:45PM +0100, andrey.konovalov@linux.dev wrote: > From: Andrey Konovalov > > __GFP_ZEROTAGS should only be effective if memory is being zeroed. > Currently, hardware tag-based KASAN violates this requirement. > > Fix by including an initialization check along with checking for > __GFP_ZEROTAGS. > > Signed-off-by: Andrey Konovalov > Reviewed-by: Alexander Potapenko > --- > mm/kasan/hw_tags.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c > index 0b8225add2e4..c643740b8599 100644 > --- a/mm/kasan/hw_tags.c > +++ b/mm/kasan/hw_tags.c > @@ -199,11 +199,12 @@ void kasan_alloc_pages(struct page *page, unsigned int order, gfp_t flags) > * page_alloc.c. > */ > bool init = !want_init_on_free() && want_init_on_alloc(flags); > + bool init_tags = init && (flags & __GFP_ZEROTAGS); > > if (flags & __GFP_SKIP_KASAN_POISON) > SetPageSkipKASanPoison(page); > > - if (flags & __GFP_ZEROTAGS) { > + if (init_tags) { You can probably leave this unchanged but add a WARN_ON_ONCE() if !init. AFAICT there's only a single place where __GFP_ZEROTAGS is passed. -- Catalin