From patchwork Wed Feb 9 15:22:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 12740381 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 F3B41C433F5 for ; Wed, 9 Feb 2022 15:25:27 +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=+JZCe1hDPkRlrihJnuLbylrV678RKSRE6y1GYePWuxw=; b=qsy/Qw4vANkvbJ ik+ohUk0GlaPG+yrAND4RIrgbiWO73zG/ZnX7BcloaZJx1J6QI9m7yrjUonIShsY3VdwiOHH1yX/e b9JZ6SCCK+qXuKc7OhZxg9sYO3AyOJFr6t5UIDwxtLNbEQ9RbqhKqvgi3kPb5UeBo9B4n3+eLIjNj QGZdCveeWxFKQurBuieTsmFYMMHOqI54s5l98kvn7WwfwUXsf8CPC4SrmHYbKwDjNva70+vs4bJKQ kA3/sE6xD9ZSisKmZhs2w9R2xof5789EvxnelTV5qH9Mks8frdLwCpNSjggRKavf4mwiK5TxXwTmr bALTuLu96z2rzpj5HGXw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nHook-000YKy-4w; Wed, 09 Feb 2022 15:23:38 +0000 Received: from mail-db5eur01on0602.outbound.protection.outlook.com ([2a01:111:f400:fe02::602] helo=EUR01-DB5-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nHooH-000YBV-JM for linux-arm-kernel@lists.infradead.org; Wed, 09 Feb 2022 15:23:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7zrFR/5yfryMYPJxbnasHVRAHNFbLp4MPEyNkzpxB0U=; b=3lyo/kg5MdO5OvqXUYJYOueq3dPsLYDmvEdrvllLkCFf84THD8Idc86djq78w3ql9L1LjvW5urrba82HeP4nyNmRWtZuMiq+sEpTUuEzi22etWS0q1tTSv1w7j1di1hlccZKPMZZpRMqp3FkgQ0IFZ/w4TmsTvFcPw4XF4h/CO4= Received: from AM6PR05CA0006.eurprd05.prod.outlook.com (2603:10a6:20b:2e::19) by AM8PR08MB5636.eurprd08.prod.outlook.com (2603:10a6:20b:1c6::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12; Wed, 9 Feb 2022 15:23:06 +0000 Received: from AM5EUR03FT048.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:2e:cafe::45) by AM6PR05CA0006.outlook.office365.com (2603:10a6:20b:2e::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.19 via Frontend Transport; Wed, 9 Feb 2022 15:23:06 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT048.mail.protection.outlook.com (10.152.17.177) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12 via Frontend Transport; Wed, 9 Feb 2022 15:23:06 +0000 Received: ("Tessian outbound 741ca6c82739:v113"); Wed, 09 Feb 2022 15:23:06 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 3e56b5aebf36f51a X-CR-MTA-TID: 64aa7808 Received: from f8e88ca1b39e.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 4A2C5390-15E0-4B9E-8DA4-E09E9902D79D.1; Wed, 09 Feb 2022 15:22:59 +0000 Received: from EUR03-VE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id f8e88ca1b39e.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 09 Feb 2022 15:22:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kULLDDWYzFWET/+u64l+1EF6wq/s6gF9bYPVrC7QeEjoXsryiUyo50ei/QEHgQXnlYRrUzcw1+7pRYqlezFWgDNa0hiizQxPwUkuCFJM7BTyrAqCMxZmUxhkK/DYXtq8FyR4zGUN4T/M7Wnd4E+grXVP2QDPF/5EXtoX4krlpDX7kaE5JQ/eI3o+oNZOXCisZb01CKdm75Z9STRcOVIuaG4TIOPrF4HObZEWvozXCk0vLXA3E6otPmpABVCPC7ALr79rTEAuhUH4I5ej7vMBewYf2gcvx6yA78+JQAO99BZuPzjpK+Sx4D9RyrukftLn69XE+v4e3+YyvW94i4g+Hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7zrFR/5yfryMYPJxbnasHVRAHNFbLp4MPEyNkzpxB0U=; b=lXedgpTgZ2WI7fok7vb/8pv9JsJbMa453ifpsOXE1VAYbhzfh+A08kC/CplaVlFUxzizD76ITj/Smu5teEdrCXptNVwV6tHZOBYntwARoDzmR/7D5iKyi9STH1uv/CyD9ixpqN4bvc4Q6qQU1V2HIHGJNShQHlhCCa0uAp8bv/wfDKrXGRDbvUR3/l0Q5seh/6Vuv/JiwkUR2UC3+wT3wcREwelYhqlCIeqgxFLbs3o5O8PZO59vsDP35y2FjJfPFdPIE8jHNfUZF0YcAtGzEvyV+J+QRwsrZotknBuzRgA3nNU02JvPqqtITMqUdFAD3v4HRCG6VJOBGgsYv7vODg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=lists.infradead.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7zrFR/5yfryMYPJxbnasHVRAHNFbLp4MPEyNkzpxB0U=; b=3lyo/kg5MdO5OvqXUYJYOueq3dPsLYDmvEdrvllLkCFf84THD8Idc86djq78w3ql9L1LjvW5urrba82HeP4nyNmRWtZuMiq+sEpTUuEzi22etWS0q1tTSv1w7j1di1hlccZKPMZZpRMqp3FkgQ0IFZ/w4TmsTvFcPw4XF4h/CO4= Received: from AM6PR02CA0019.eurprd02.prod.outlook.com (2603:10a6:20b:6e::32) by HE1PR08MB2923.eurprd08.prod.outlook.com (2603:10a6:7:2b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.18; Wed, 9 Feb 2022 15:22:56 +0000 Received: from AM5EUR03FT015.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:6e:cafe::9b) by AM6PR02CA0019.outlook.office365.com (2603:10a6:20b:6e::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.19 via Frontend Transport; Wed, 9 Feb 2022 15:22:56 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; Received: from nebula.arm.com (40.67.248.234) by AM5EUR03FT015.mail.protection.outlook.com (10.152.16.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4951.12 via Frontend Transport; Wed, 9 Feb 2022 15:22:56 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 9 Feb 2022 15:22:50 +0000 Received: from e124191.cambridge.arm.com (10.1.197.45) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.2308.20 via Frontend Transport; Wed, 9 Feb 2022 15:22:50 +0000 From: Joey Gouly To: CC: , , , , , , , Subject: [PATCH v3 3/6] kselftest/arm64: mte: user_mem: check different offsets and sizes Date: Wed, 9 Feb 2022 15:22:37 +0000 Message-ID: <20220209152240.52788-4-joey.gouly@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220209152240.52788-1-joey.gouly@arm.com> References: <20220209152240.52788-1-joey.gouly@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-Correlation-Id: d5b743b3-5064-41c3-0fc9-08d9ebe01287 X-MS-TrafficTypeDiagnostic: HE1PR08MB2923:EE_|AM5EUR03FT048:EE_|AM8PR08MB5636:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:7691;OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: npbCxEm940+s0nO0Yy20R2gIFzzkgkmDWxhKvmeulZeADWS52IgTpYgSFFxfAo8zuoQFmyl0H1lbwPXY+YRMjjERkmDFpOYtgoUWHEjDcm8HqfdTx7clALB1OnaBEpG+77CaXWrGUiF55udpPNEwkfZDpTj++52LPEwLzHpmHVYIKrFqiyJLlZWtN1MooWXkerMg1CNvAEaLcF+F1GacgXbF8rZTDOfEwEMNXnQKPfgzDuDnMq4LMrxQCb2DmDy6c0I42bTRYzByi2ozrMM+MvyNsWPoQ+fySt/S5JoPf45BJ/Xds9gJ+pf0Eoq0u0hdnCWpSmHNiWNQz8gCjJMkHLFsAW4XLaptqKQAt8AIutzeNnwujFpc1u+2QK9URdODQjdWFLXYjjHCTsiva8TjgpY2+Ku1QlU7okAl0KVP9yLMs0fdZiub1ECDZ4qOSJIhhwutfEfqT2wDBYjV97cdnI2+ruUGNXZk2nR2ImLdKt+dwf/diEJ3m2k47o6dc2eSl9BXxoYE7m9WICDi0dPm0DEZdgFrX5jHxqgQz3Ti+sG7DkyygsD729AmytjGjTcvT9rhIS/4swGPqgn2SfrI1hnG9W4ZZPJYbO0zB4+njq6ZlsSrcALqI7fuGVKJTef6GDbG8mWkMVWoUBHLKU3+KYWAUXPqbYKGXc/fYmiRgpY0zPIj4wKKpvGdsLqwxU5zaTkubqB13Uk0L+dCLgJZNg== X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:nebula.arm.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230001)(4636009)(40470700004)(46966006)(36840700001)(36860700001)(26005)(4326008)(8936002)(8676002)(86362001)(1076003)(336012)(426003)(70206006)(70586007)(6916009)(82310400004)(54906003)(186003)(316002)(81166007)(7696005)(2906002)(6666004)(47076005)(356005)(2616005)(36756003)(40460700003)(83380400001)(44832011)(508600001)(5660300002)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR08MB2923 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT048.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 7d558006-94ad-406a-bc63-08d9ebe00c56 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LGFh/GcrOkj7u2NXFQZnFvquvDV1c+rRYKBcaIHNMWH5w0lpHmUljSI+IMD3Kg2dpIGSaRpTPk/8L19KWJCHGK4IPgIrXcd0jIA3ZArmU9oNHOlLc/OtUrl2yltriVMIs72mVs4nNQyaqcfVHGPDyvJcWQTCvhQiSqv1SSwN+aXIB4UVevEEVNFPvd9m5DMa1U9yDS0amkbK09KJtoeBi3WxL6Y1y4FIlPjD4WByOu8TgDUKFT1gA0rwC5vEisL3O8gNcaX0MztLmR1OaQDeSSXKCOcS3s1v2sp8yDQbtZdlGKgkNXTK40fWXvVHrjIcPkbZRAzV2PNHm9g+NyYlaXgwrE+ct2EiAPVUUDin1uM6JD68VKT6/d0gP5BTgOmaBtuuoXRLstL4RSea74aHrcjRQqDOFc/miIDAINxOFvj6aTIuj7BGT0ek4i25T+k4MhogQ7EqX+jA9XJiVY7QNKGLnbzIemCqVG09T0mETDVtmbDPVqBORNIG08knIb0aqvGal37yZQLPJg0ht89mYUxR8DJUpx4KnOMSjEcO1cGsTxfAA0mtjaxKzwyhCL4mRsJgn47K0eCCkPCLZSLlgEtSdDj8mMsKn7Jx60CtN5r97VzmA0GsYMtoUD9e6hH8y1P+HDpeVBTCoAJ/CqflbpOXtgzMiR8u91pzNTGNh3CNSN2HlBIQW2ApWSb1o8SX X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(81166007)(47076005)(44832011)(426003)(508600001)(4326008)(8676002)(5660300002)(70586007)(8936002)(86362001)(83380400001)(70206006)(6916009)(40460700003)(26005)(316002)(336012)(186003)(7696005)(1076003)(6666004)(54906003)(36860700001)(2616005)(2906002)(107886003)(36756003)(82310400004); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Feb 2022 15:23:06.5210 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d5b743b3-5064-41c3-0fc9-08d9ebe01287 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT048.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB5636 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220209_072309_707913_DF1D984F X-CRM114-Status: GOOD ( 17.13 ) 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 To check there are no assumptions in the kernel about buffer sizes or alignments of user space pointers, expand the test to cover different sizes and offsets. Signed-off-by: Joey Gouly Cc: Catalin Marinas Cc: Will Deacon Cc: Mark Brown Cc: Shuah Khan Reviewed-by: Mark Brown Tested-by: Mark Brown Reviewed-by: Shuah Khan Reviewed-by: Catalin Marinas --- .../selftests/arm64/mte/check_user_mem.c | 45 +++++++++++-------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/tools/testing/selftests/arm64/mte/check_user_mem.c b/tools/testing/selftests/arm64/mte/check_user_mem.c index 2afcc9fb9ae8..89c861ee68fa 100644 --- a/tools/testing/selftests/arm64/mte/check_user_mem.c +++ b/tools/testing/selftests/arm64/mte/check_user_mem.c @@ -26,6 +26,8 @@ static int check_usermem_access_fault(int mem_type, int mode, int mapping, char val = 'A'; size_t len, read_len; void *ptr, *ptr_next; + int fileoff, ptroff, size; + int sizes[] = {1, 2, 3, 8, 16, 32, 4096, page_sz}; err = KSFT_PASS; len = 2 * page_sz; @@ -62,24 +64,31 @@ static int check_usermem_access_fault(int mem_type, int mode, int mapping, ptr_next = mte_insert_new_tag(ptr_next); mte_set_tag_address_range(ptr_next, tag_len); - lseek(fd, 0, 0); - /* Copy from file into buffer with invalid tag */ - read_len = read(fd, ptr, len); - mte_wait_after_trig(); - /* - * Accessing user memory in kernel with invalid tag should fail in sync - * mode without fault but may not fail in async mode as per the - * implemented MTE userspace support in Arm64 kernel. - */ - if (cur_mte_cxt.fault_valid) - goto usermem_acc_err; - - if (mode == MTE_SYNC_ERR && read_len < len) { - /* test passed */ - } else if (mode == MTE_ASYNC_ERR && read_len == len) { - /* test passed */ - } else { - goto usermem_acc_err; + for (fileoff = 0; fileoff < 16; fileoff++) { + for (ptroff = 0; ptroff < 16; ptroff++) { + for (i = 0; i < ARRAY_SIZE(sizes); i++) { + size = sizes[i]; + lseek(fd, 0, 0); + /* Copy from file into buffer with invalid tag */ + read_len = read(fd, ptr + ptroff, size); + mte_wait_after_trig(); + /* + * Accessing user memory in kernel with invalid tag should fail in sync + * mode without fault but may not fail in async mode as per the + * implemented MTE userspace support in Arm64 kernel. + */ + if (cur_mte_cxt.fault_valid) { + goto usermem_acc_err; + } + if (mode == MTE_SYNC_ERR && read_len < len) { + /* test passed */ + } else if (mode == MTE_ASYNC_ERR && read_len == size) { + /* test passed */ + } else { + goto usermem_acc_err; + } + } + } } goto exit;