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 113C5C19F2A for ; Mon, 8 Aug 2022 01:32:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241897AbiHHBca (ORCPT ); Sun, 7 Aug 2022 21:32:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242006AbiHHBcH (ORCPT ); Sun, 7 Aug 2022 21:32:07 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DE91BCB8; Sun, 7 Aug 2022 18:32:01 -0700 (PDT) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 3190A60DE0; Mon, 8 Aug 2022 01:32:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82E90C43141; Mon, 8 Aug 2022 01:31:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659922320; bh=Cy0VXR0/pBUrCrS9LsefsGH8QEVj0tWVRheqGk50Gvw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RR9VxMZ14ZkgCfB1sghpr8lgUyDR0E7JHBGPa6cVegge8YheLffM0qRI09AK4jUeZ DvFqIq51AhFEyLK8cVoO+6QRzlRP9ciXj4wPPL5LgUZfUvbbBNlb041eGoJTuq0zNB OvUUWXXLg8/WSWvn3X0EQ20LGH5zRXINJ1/io0IoX19Tx2RSee03TMdzPuJc3HPbtz A3VmK2xwoGKNt01fMTTwRhOv9R5EpB8ozfmDHo4XTOH9/XUtZQeJKrJCREC6JzHkXp 5kJE94l23C4LuJ1xA0VD53SkE8ramDeOtffW5FU2Oy6kivYQVRzbE4bGB0wfX+32NB 6g5Sqn/lni8Pw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Catalin Marinas , Andrey Konovalov , Andrey Ryabinin , Vincenzo Frascino , Will Deacon , Sasha Levin , kasan-dev@googlegroups.com, linux-mm@kvack.org Subject: [PATCH AUTOSEL 5.19 10/58] mm: kasan: Ensure the tags are visible before the tag in page->flags Date: Sun, 7 Aug 2022 21:30:28 -0400 Message-Id: <20220808013118.313965-10-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220808013118.313965-1-sashal@kernel.org> References: <20220808013118.313965-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Catalin Marinas [ Upstream commit ed0a6d1d973e9763989b44913ae1bd2a5d5d5777 ] __kasan_unpoison_pages() colours the memory with a random tag and stores it in page->flags in order to re-create the tagged pointer via page_to_virt() later. When the tag from the page->flags is read, ensure that the in-memory tags are already visible by re-ordering the page_kasan_tag_set() after kasan_unpoison(). The former already has barriers in place through try_cmpxchg(). On the reader side, the order is ensured by the address dependency between page->flags and the memory access. Signed-off-by: Catalin Marinas Reviewed-by: Andrey Konovalov Cc: Andrey Ryabinin Cc: Vincenzo Frascino Reviewed-by: Vincenzo Frascino Link: https://lore.kernel.org/r/20220610152141.2148929-2-catalin.marinas@arm.com Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- mm/kasan/common.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index c40c0e7b3b5f..78be2beb7453 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -108,9 +108,10 @@ void __kasan_unpoison_pages(struct page *page, unsigned int order, bool init) return; tag = kasan_random_tag(); + kasan_unpoison(set_tag(page_address(page), tag), + PAGE_SIZE << order, init); for (i = 0; i < (1 << order); i++) page_kasan_tag_set(page + i, tag); - kasan_unpoison(page_address(page), PAGE_SIZE << order, init); } void __kasan_poison_pages(struct page *page, unsigned int order, bool init) -- 2.35.1