From patchwork Fri Jun 10 15:21:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Catalin Marinas X-Patchwork-Id: 12877707 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 7ED0FCCA47B for ; Fri, 10 Jun 2022 15:22:58 +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=TACOXilBmEn8nvSN0qfDWLie3binhMgCTpjunBW8sgc=; b=B+Ic3ext2D3FTM bprCi68AwbgvcLtQ85fggaSxiGmhv3w4+za1VlIXMf7QgPCBi3xBomEJVZLwP3lkBmtKQKDVaVhRZ OD1AKqU5L1rVh/SdSLSZaiZ+IdXyMg0Tw2NudO834IzQW4IYhz/QPkCQRSi7UjcAjR4GeCXolqkHC mbECLUYdPJdxlFmr4qs8LH6HBmPvUF3lu+vgQXhm1idhb9oQTK5eXBRwUoi//HG6bEEprF3LD0lDF RKHX51keUYu8aw4TqTqbpFJppOnIRP9N4t6PFYu8TnmLiW1R8QfJ5onhKxiGsAEJbMZu0SDndE9/U i+hia4+CeLLooKXKsqcw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nzgSW-008jxo-8e; Fri, 10 Jun 2022 15:22:00 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nzgSL-008jtG-BP for linux-arm-kernel@lists.infradead.org; Fri, 10 Jun 2022 15:21:50 +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 dfw.source.kernel.org (Postfix) with ESMTPS id AACE361F8A; Fri, 10 Jun 2022 15:21:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41782C3411E; Fri, 10 Jun 2022 15:21:46 +0000 (UTC) From: Catalin Marinas To: Andrey Ryabinin , Andrey Konovalov Cc: Will Deacon , Vincenzo Frascino , Peter Collingbourne , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 1/4] mm: kasan: Ensure the tags are visible before the tag in page->flags Date: Fri, 10 Jun 2022 16:21:38 +0100 Message-Id: <20220610152141.2148929-2-catalin.marinas@arm.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220610152141.2148929-1-catalin.marinas@arm.com> References: <20220610152141.2148929-1-catalin.marinas@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220610_082149_466117_243D9A39 X-CRM114-Status: GOOD ( 13.55 ) 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 __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 --- 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)