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 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E4F3C433FE for ; Fri, 10 Dec 2021 17:49:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AFDEA6B0072; Fri, 10 Dec 2021 12:49:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AAE516B0073; Fri, 10 Dec 2021 12:49:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 974E46B0074; Fri, 10 Dec 2021 12:49:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0226.hostedemail.com [216.40.44.226]) by kanga.kvack.org (Postfix) with ESMTP id 87F4E6B0072 for ; Fri, 10 Dec 2021 12:49:09 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 40BE88249980 for ; Fri, 10 Dec 2021 17:48:59 +0000 (UTC) X-FDA: 78902620398.07.65BD426 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf30.hostedemail.com (Postfix) with ESMTP id B29298000A for ; Fri, 10 Dec 2021 17:48:58 +0000 (UTC) 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Stat-Signature: oy5d9hudbtxo71ddi141i1mjod8aknmx Authentication-Results: imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of cmarinas@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=cmarinas@kernel.org; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none) X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: B29298000A X-HE-Tag: 1639158538-191954 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, 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