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: 12877703 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 4198EC43334 for ; Fri, 10 Jun 2022 15:21:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 875B86B00FF; Fri, 10 Jun 2022 11:21:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 826798D00C0; Fri, 10 Jun 2022 11:21:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6ECC48D00B3; Fri, 10 Jun 2022 11:21:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 622376B00FF for ; Fri, 10 Jun 2022 11:21:50 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 3677A1203A6 for ; Fri, 10 Jun 2022 15:21:50 +0000 (UTC) X-FDA: 79562691180.18.C397C26 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf07.hostedemail.com (Postfix) with ESMTP id 94AFF40065 for ; Fri, 10 Jun 2022 15:21:49 +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 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1654874509; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lgMgeWhztOHyVi3SUORGBw5VvBKlP0XC/a7AJMMixY8=; b=XxmNYBlsxOKsNmM3JLF2nW24btA3FCvxAbcbaUGK61QehsoalK+iL8a2Nr8jJ2VpsLasCN TnjLBePOv+CKyhzFW5UbFhGg9gjSelB/oEFmupkZTeX1K/o4KSWjDyl2+vYkogS8/MIQti Byoey4EzAKseuWLmUhJveopzKJcgPBI= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf07.hostedemail.com: domain of cmarinas@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cmarinas@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1654874509; a=rsa-sha256; cv=none; b=7yDZ/yAiCtCQ7jGGK9eH090dhzzegtHYITCIaqA/hxQuhdlJrGDPsl4h5lDP8RWbdK2HcZ eOndnZvqsUY2F5wYN3gJWvjX22xrlJQlmZxZ5chLq3FXe4/a7Wg4McwbB0yYMvVXEsetP4 p4W7lwrgq+a8ml2cxq3Syce3UQ9Oymk= X-Stat-Signature: ouyde8kfsgizsc73s5gkeae14jrz11wh X-Rspamd-Queue-Id: 94AFF40065 Authentication-Results: imf07.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf07.hostedemail.com: domain of cmarinas@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cmarinas@kernel.org X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1654874509-191335 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: __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)