Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp4224907rwb; Sun, 7 Aug 2022 18:35:30 -0700 (PDT) X-Google-Smtp-Source: AA6agR79Tuq7CtPL1p7WJtV9TG48KdpjC07oZFB1Lby6ZfhUS+bLK7AvhKC/ZV1ri+0sZxbZU9th X-Received: by 2002:a17:906:cc48:b0:730:7545:bf51 with SMTP id mm8-20020a170906cc4800b007307545bf51mr11877414ejb.247.1659922530270; Sun, 07 Aug 2022 18:35:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659922530; cv=none; d=google.com; s=arc-20160816; b=LNcLwDSZjpVNLvH1SOCeGhpEpNaZm4OfS5bTO1zTWyfRdT2NolxlKD0e0FwthqhTr8 EyNyfXC9btNfp+d4xuvE49VW8v70yLZo+GUWGVM6lKzfOF2onBkvQnOp9Tpffyc3F0bV qtHvUf5LtyErIw6pmdX9rDPgvljW9JRGmcDVE3/JWnX34SNXAhGm9DjRot01BJQ1MeJq YQmKv4mEzWKrXmjswqhwu8rkqB2An8FP/itoyDhpVBQ5W9Igv3HZXuqDwq8FXZIbFde3 tfGCnc9soEdVx5b+vguNGjk0WadG9vtkFNoDH8gIoYAK0El8hfZtCSZfRZC/oa0SzjlQ P/Xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rd8ZKdn/WQ0KEm6ZZRaSem3F0aJ3Qe54rAM+TlPiyeE=; b=KBdNV5i7HdmczgHmkQBkLsV6NJ2M4ogTXNwrnqz6jrHt4ZhgYrj+r1s1GG8cZHbOLw lixM3vZn2JZR2HAJYeSo8EvJpRMQV1eZXoiwbqUVU05Bek0Ocp8jem1zlhEI5qFY4Fw1 4y0XyICzWMeCDiSpmQbu2XGSgl1N6mIRKbUPxH+cPY1XD3PozDBm7jxUlrqFCTmFPQGi G3i/6MgJkNdv+xNIbu3fcY+kPrAtn3xb88eEvamqND+/cOb2GJV+mXrVb/Xr3/07UMz7 GKjz1gx4vxYtiTqPJA46pJKqJOmJBsqZzTFrGnGKrSyLlRvksUt+Bv6oFne93cb8QH/e FcsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RR9VxMZ1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id wg6-20020a17090705c600b00718bf486a1csi8890281ejb.782.2022.08.07.18.35.05; Sun, 07 Aug 2022 18:35:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RR9VxMZ1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242095AbiHHBc3 (ORCPT + 99 others); Sun, 7 Aug 2022 21:32:29 -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 X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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