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 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 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id BBEE8C433EF for ; Fri, 10 Dec 2021 17:51:39 +0000 (UTC) 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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=PWN7GlyLenJxIIAbgiHYh3XoVwKRns/VxCeYrXpqdC8=; b=BED0TCIk5rTjeo Xf2c6rAuie+cNnq4spdKqygueRR1CBl9KUvyCM3bq0hqPXxbCKpXpVmYUPQMtuEbaMj0s3BF4peb/ s5qf2cROuOm/pviUTuMginNQiHjNXmXD2G8pJhE8fWvuwN6ntM89oYtA1oPPMNyZsboOcTBenvPIN JwJ9hp8/HHy4Kk77vQE5wxbOpmn+kV9AKGzQmKWiuoQ2Xq655jU8s3DfbL2uMcEo6DQXehN9okH73 8z/UitoYhzT/k75madL8I90uN7A3zuAMWff0RIDuWrV4dRMle0Ws1OFgAYy8M1ZlGJmR20edZIYpq tlPxAfykIpvz2DY5L5eQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mvk2F-002zv3-16; Fri, 10 Dec 2021 17:50:19 +0000 Received: from sin.source.kernel.org ([145.40.73.55]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mvk0u-002zFq-QS for linux-arm-kernel@lists.infradead.org; Fri, 10 Dec 2021 17:48:58 +0000 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 7E674CE2C73; 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-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211210_094857_075289_925BDCA9 X-CRM114-Status: GOOD ( 19.41 ) 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, 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel