From patchwork Tue Nov 30 21:41:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 12694218 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 99699C433EF for ; Tue, 30 Nov 2021 21:45:21 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=PKTOH0daM0A/Q3ScR/Q1UrQKMMFo03SpdA1M/PrH9Ok=; b=3+EVk+s/9i5Boe l+zTJDGPb8mT24hcraslRQIXgcyO0KneIRidStVjOk6KWAYSg6nZT/s3cvK7hrEk3klIUzGe2/zIV qI0LfbMz37acG6Rslgp4lpwsle4QjSr1234/IHDOPaAS9PBhESjLfnVSEqhdVd8/lGrBKbOsoCOwa nXICrYqExsC8G7MF5OjtLpasdwkoji+gP1Hq9weHdGYfT9gKf1CSCpbR4hFqy5xGzItcd5GorVDn0 /mkFnG3FRP0dbyxWdNYjcbVexlUqf+2g/nFzvV1Ih3pKAypSztl2Q+260H+jLBqMqaf2OITkbQPJ7 DDi3VleKq3gee/Hs5Q9Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1msAub-006nE8-D7; Tue, 30 Nov 2021 21:43:41 +0000 Received: from out2.migadu.com ([188.165.223.204]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1msAsn-006mGD-GZ for linux-arm-kernel@lists.infradead.org; Tue, 30 Nov 2021 21:41:51 +0000 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1638308507; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=USDGw+3TDan6rheydUBAEIrBt2Dp4Aw0TGvQ3YV1Rwc=; b=J8aQq0R4JYN4G76DD1gc+Nc4q4O9pJDOK1OdTxnOseu+oRyqvy0aRTnENMCmx4DgLXiNGA yZEoJZ0cte/I2gSLAkcER1wM0mLlEvVRKJZitBYR6stQv0l8zVLdkpvxSSts3OuQ2r6Eqn pyf2CWAFn1TeoJb4CoKSl1uIIQ7814Q= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko , Vincenzo Frascino , Catalin Marinas , Peter Collingbourne Cc: Andrey Konovalov , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Andrew Morton , linux-mm@kvack.org, Will Deacon , linux-arm-kernel@lists.infradead.org, Evgenii Stepanov , linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH 07/31] kasan: only apply __GFP_ZEROTAGS when memory is zeroed Date: Tue, 30 Nov 2021 22:41:44 +0100 Message-Id: <938a827f9927ee2112d98e2053ad7764aae9d8f8.1638308023.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211130_134149_760483_D709CFAC X-CRM114-Status: GOOD ( 10.57 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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) { int i; for (i = 0; i != 1 << order; ++i)