From patchwork Thu Jan 19 16:03:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13108322 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 5581CC46467 for ; Thu, 19 Jan 2023 16:04:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D1AEF6B0072; Thu, 19 Jan 2023 11:04:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CCAE16B0073; Thu, 19 Jan 2023 11:04:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AF6AB6B0075; Thu, 19 Jan 2023 11:04:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 9FC576B0072 for ; Thu, 19 Jan 2023 11:04:56 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 19E64140D12 for ; Thu, 19 Jan 2023 16:04:56 +0000 (UTC) X-FDA: 80372022192.06.FC70242 Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2072.outbound.protection.outlook.com [40.107.104.72]) by imf10.hostedemail.com (Postfix) with ESMTP id D23B3C0002 for ; Thu, 19 Jan 2023 16:04:50 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b="tuQI7n/b"; dkim=pass header.d=armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b="tuQI7n/b"; spf=pass (imf10.hostedemail.com: domain of Joey.Gouly@arm.com designates 40.107.104.72 as permitted sender) smtp.mailfrom=Joey.Gouly@arm.com; dmarc=pass (policy=none) header.from=arm.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1674144291; a=rsa-sha256; cv=pass; b=BXKatSvcBx/4VrOK90GEl1NdpJmamT7jM9ahVX7JE73154FWVItX17F7AihzwLCVGX3Giu SGzdcU+HKP1Vv5rPmKUi+sqIcc/WFHwZ5yJg4FZGniZGYWNfDVv+sM0iuAVrQunpV115Ti GIM/ELCGoTmsnForoGy8mxAv77o2eEo= ARC-Authentication-Results: i=2; imf10.hostedemail.com; dkim=pass header.d=armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b="tuQI7n/b"; dkim=pass header.d=armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b="tuQI7n/b"; spf=pass (imf10.hostedemail.com: domain of Joey.Gouly@arm.com designates 40.107.104.72 as permitted sender) smtp.mailfrom=Joey.Gouly@arm.com; dmarc=pass (policy=none) header.from=arm.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674144291; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BWnBE/PL1egq8JVxHK3Rs1L98loH/NJaLJV0FmvDpbs=; b=MuJX/zoEXPALfioQa/IHSErFe6rlp5QX4lNSuiRDQWy+5V+Kj59RhZaDGWCiQzt+ZWIuW2 lq9Q4UA1fZKpAWguw5zYnT3acI0MMgnY4GHEeF7Azgc9ov0Bg4DuAIHLFnh+dYG0k0Nsdl +UQ7+8kcd2Pxh9+uCYKdMrLISX+vSgs= 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=BWnBE/PL1egq8JVxHK3Rs1L98loH/NJaLJV0FmvDpbs=; b=tuQI7n/bMvlfnfQesj/RIZsa6OLWxdGJ9NVoYZQDCPz1Cv5HBqnZ7i7PL26q/SUi7ZXFreVvoATBEapBOacwlMW5DPjTaQr/ZNfbB5gNDWvGAmahcVLFpyoBChpKFDd5FFLWhho1/KNJV+3Z+wibfAlSS+hFtTFbRv2Vc95Z+As= Received: from AM6P191CA0087.EURP191.PROD.OUTLOOK.COM (2603:10a6:209:8a::28) by AM8PR08MB5635.eurprd08.prod.outlook.com (2603:10a6:20b:1c5::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.13; Thu, 19 Jan 2023 16:04:35 +0000 Received: from AM7EUR03FT028.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:8a:cafe::64) by AM6P191CA0087.outlook.office365.com (2603:10a6:209:8a::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.25 via Frontend Transport; Thu, 19 Jan 2023 16:04:35 +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; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM7EUR03FT028.mail.protection.outlook.com (100.127.140.192) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.13 via Frontend Transport; Thu, 19 Jan 2023 16:04:35 +0000 Received: ("Tessian outbound 6e565e48ed4a:v132"); Thu, 19 Jan 2023 16:04:34 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: af47519074e9bf56 X-CR-MTA-TID: 64aa7808 Received: from ec8cb9d0b8ca.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id A7BB288E-AA90-4770-AE10-D67636400B79.1; Thu, 19 Jan 2023 16:04:04 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id ec8cb9d0b8ca.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 19 Jan 2023 16:04:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HSnFPvfuaDbmy2+AvnEJIXu6h0FuC1yo4+8s2jRRPx0/FXI/QzlpzooiFE58IL0zlDDCPNFS2/ZJEPws4KgTqN1xOm9mA1tPbrzgXFm9mfNjnvx8fFw2oXEejtrpFm9QMnh6YcuWVRSiHI68XZl5am1V6AMAAhwSqIWl8EP5UY2awwPA47g++Ke0hNlkZ/nnH5M6BZiaYIaFjrsU2VLldNj617ZNBFte2crj41QqL5AIFe3qGmUgM0yb4ANXjkt5fgD7GM7Q+oY7nUXw2qJOhZOvtV0KSKl5Fn2pANkIZ5mxpwgXqBBEhMTNCRZEHuVDRJOQlyRbMMwtIwAUcSLKtQ== 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=BWnBE/PL1egq8JVxHK3Rs1L98loH/NJaLJV0FmvDpbs=; b=eM7K4ANkMsi5JRA3qw+bmcjG4XaEewBdIaq11T0UsvVtJpyK1XS4zF7YcyF7SiAeEmI8vcv7yEXyW1gjrbWiH0nd87Z2UIYlHIHrwagZrDOopV0uTvAOBwNi5ssv4j3ZOgYiex0cDGjBh4XeX5FynB4771c8BTrTttbiSI5ZwBmW2XhV2+o9ErsELnuRIABeup+TD64s6qgb9m+a8EDHFV+8M+54tRMUduiMc+kEEj+SqIdvH1BXedQoaZxSk3NKTzXHPGFB+8tcaDRZcUUbfIrHdjoKkADrFSL3rpGr1eb1PovK6y3pxjzL9Ya8qnFIVaJyr+mIDEz1375E0ZleOA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=linux-foundation.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=BWnBE/PL1egq8JVxHK3Rs1L98loH/NJaLJV0FmvDpbs=; b=tuQI7n/bMvlfnfQesj/RIZsa6OLWxdGJ9NVoYZQDCPz1Cv5HBqnZ7i7PL26q/SUi7ZXFreVvoATBEapBOacwlMW5DPjTaQr/ZNfbB5gNDWvGAmahcVLFpyoBChpKFDd5FFLWhho1/KNJV+3Z+wibfAlSS+hFtTFbRv2Vc95Z+As= Received: from AS9PR05CA0309.eurprd05.prod.outlook.com (2603:10a6:20b:491::12) by AS8PR08MB9528.eurprd08.prod.outlook.com (2603:10a6:20b:61c::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.24; Thu, 19 Jan 2023 16:04:02 +0000 Received: from AM7EUR03FT056.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:491:cafe::38) by AS9PR05CA0309.outlook.office365.com (2603:10a6:20b:491::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.25 via Frontend Transport; Thu, 19 Jan 2023 16:04:02 +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; pr=C Received: from nebula.arm.com (40.67.248.234) by AM7EUR03FT056.mail.protection.outlook.com (100.127.140.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6002.13 via Frontend Transport; Thu, 19 Jan 2023 16:04:02 +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.2507.16; Thu, 19 Jan 2023 16:04:00 +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.2507.16 via Frontend Transport; Thu, 19 Jan 2023 16:03:59 +0000 From: Joey Gouly To: Catalin Marinas , Andrew Morton , Lennart Poettering , =?utf-8?q?Zbigniew_J=C4=99drze?= =?utf-8?q?jewski-Szmek?= CC: Alexander Viro , Kees Cook , Szabolcs Nagy , Mark Brown , Jeremy Linton , Topi Miettinen , , , , , , , Subject: [PATCH v2 1/2] mm: Implement memory-deny-write-execute as a prctl Date: Thu, 19 Jan 2023 16:03:43 +0000 Message-ID: <20230119160344.54358-2-joey.gouly@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230119160344.54358-1-joey.gouly@arm.com> References: <20230119160344.54358-1-joey.gouly@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: AM7EUR03FT056:EE_|AS8PR08MB9528:EE_|AM7EUR03FT028:EE_|AM8PR08MB5635:EE_ X-MS-Office365-Filtering-Correlation-Id: a8018418-591d-4ffa-2992-08dafa36dbec x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: V0el0I3AGkk0QRLFORZua0C7VnSelmI4sgfJfChIFySVKJMlQYw0m9Fas65dnDBDjp4KcAROEgGw+yUJcMLAOiUCiqX6E6sgjgrPG9fwnUOf7uel8k3ASFZPD7oXZcvgXvodLqNP9DUH29oYHEzsJAmOuKreiUR+zXPR0QRiu4ujOmY0A6gPWul5YzIUnUj6x2OQYPaGEmTUWccxDRPt0cnSeM9R1WkDpTGDVmc4eA3761WAIfqVVXz8ODpW1vNAsJIGQkQGBu8MthRpmoPuMi7qeCavcT6EJaKEY/SEZ0HZXwJKMdUAWfnygD3FHO3yM00OSVYb6ukCGP0wuH/BmyxtN3BB++qzyCOoDiW2CPCA7rRL4bAyKPP1Yfwo43BkmXioA/RxrUfSZ0/WObGgb0CmeKziLPcV0uMFeruMYLDFZoW/henx4Y3XG5ZxqQ5Y1svsgs+C05UN/t3cGZBoVuPqL/OTyUx8oMmY62N3UjpGIh3ZVWOLknepD+tzADuIZq50MScprr/SPOttzXeJpC4brfoLar12hGFKPHb0DXqL0DSlZtwBqndwOkY12RA0QSN8quSR95bPuzE6kst5SPbLKsQAboLa09LXDrTFJxh8UcCDaoSeDN2PHvuIfif02CUh8TQDnbHEdc2Ft/LXrjo0glnNUJzNTV4qJuCGqyRBm5nVWrC1Yi8h9cBpNl3hJcC9vYFe5XWg7W9hnOx/H0TVDNV+IYP01vDCLZeoKTkzQgnnkHDrluS4TN91Yy+/b6YKpGyznwsITqTTnHLTmw== 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:(13230022)(4636009)(376002)(346002)(396003)(39860400002)(136003)(451199015)(40470700004)(36840700001)(46966006)(41300700001)(4326008)(6666004)(8676002)(8936002)(70206006)(70586007)(2906002)(40460700003)(36756003)(336012)(36860700001)(2616005)(82310400005)(44832011)(5660300002)(7416002)(54906003)(110136005)(316002)(40480700001)(86362001)(7696005)(186003)(478600001)(26005)(1076003)(356005)(81166007)(83380400001)(82740400003)(426003)(47076005)(17423001)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB9528 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM7EUR03FT028.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 8b5ae33a-3b4f-454f-2bea-08dafa36c8bf X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: G4wvLXoQuZcuuk1iKvWV4tBF1lDxDd8D3jnBbkPk2oT1Zu0LRByCFJBoYxg7DIk3SeM1vbqjoNG7n3RmrOXq1Nt+yYIDBY/WBFrgsqTrCN7Y9PdvZxRWKNymtXiLZRljSlpsOGOKAZ8xP4GxwBMs/hqLbaqalYZ7KYaeLie3e2hT42ZL6DiexCiep58ij9mmaEJ5LohViAOzR37GfGDCFoKkA7Z20iS85I+pgRziUqkuZPBIlbAI8ss+GAb4DGYDzBlc4M6YGdNNFWrb2xCljSO36azD7mvPIPkkmbCaLFjxe6cUeMSI2cDVw4ZMFKKm7AgSKSIanQdCS7fZeQhW0s5xsoeEA7j/+neI3CiuNM/Cl6jBCDH9kKucpgDJ3X0WzYa3q2QlrFpw8Aqco45Bw5bg2z13Dd/zUHTe7th14D2NkvYa2MESjSMLOYGlZG7UOnufIVW2oUkvy7WEUxodV6E7TVDBRx7JJnflNoN1bi9kttaupsM+0bgbKd03bf5L8vj1bXt+Lj4spwhmF+cq06RpXhTQ2Ki4ESF4u+wjBBv/4qesZ7r03yexmst0AHrjUAvwZ55VcCVj/YWKhQyIr82DBMMr3y7f5KQ5xooz6xldPmraYTNEFC1rRghwfYoDq4fYj9usp+UTqdaSVlrE4epQDaEBMazHviPNWW2VVwyadqK+DlYO5G9BNL2TI2Yd8T7arOYvTdIb2puXoVSsCCRNgiox8xrzkqIAmFLDM58= 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:(13230022)(4636009)(346002)(136003)(396003)(376002)(39860400002)(451199015)(40470700004)(36840700001)(46966006)(6666004)(86362001)(478600001)(426003)(47076005)(186003)(26005)(41300700001)(107886003)(2616005)(2906002)(1076003)(336012)(82310400005)(7696005)(83380400001)(40460700003)(5660300002)(40480700001)(81166007)(44832011)(316002)(82740400003)(70206006)(70586007)(8676002)(4326008)(8936002)(36860700001)(110136005)(54906003)(36756003)(17423001);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2023 16:04:35.0118 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a8018418-591d-4ffa-2992-08dafa36dbec 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: AM7EUR03FT028.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB5635 X-Rspam-User: X-Rspamd-Queue-Id: D23B3C0002 X-Rspamd-Server: rspam01 X-Stat-Signature: hud4jbnapto3qn31j5n16gdnckfa4ith X-HE-Tag: 1674144290-799783 X-HE-Meta: U2FsdGVkX18Jxa9bWb7Mz6g7EXHXc20w3hLktMpOovPLyfpJgggn6LCHzMPmVypD7SlqowCsxeyRNxIatBmiWggON3jt4O+dPWlw9BqNz6Bz4KEGzuh5fdDwYKDK/sqczMs7LbfIjL03FT7JurPucqSeviVgZE4ESUx78UYbYCJC5Be4rgpwbLWo2Jt/jQyiwWKwJV79NpndGfMkQkDpK/Jkfv6ukDk4o5YNzsE1K28wQSJENyJFs/viI5VYdCmvN7pAiw80aIOHxQLoPqARD9IWMZoD8gtzw6bji7Z7FJK2dzacqIdfOMV59iBZlr0903vUXj92FEJF7LhNRSmVO3iL1/82L+O4aU7XbjmNUirzyy0fgG5RC7lqG1gQAWveQeoco2NpAfh48aIMPdk9U1z1lmpXQZmLa2trtIWa5s+pkhC3RSzjxLIZ91V97SNMR4jXRToSQRg/sFJMArBWjafIrgMEWrD28iHxkCTpx1lmszLXDoHM1+AGzU1fs+GRZ3rft9amqLvj4UMDXq6N/keLaB0RcHBxj+HTxhT5X2IMU4FbKZhA4o4khZtRNvl1be40LPGnSv9boqAYlc0flHaBPDlOKV203TZfftnOLRaPcCBn9vsjRPSHG9Uk6b+Cx+Nsn1VPjTIBA+dI3sFTleDnmpTHoa/pSd8YP6SrQcIGtBTkA8d+r8jXIhpX0MJ7lsgdylegXGa5FvYZPBZwL8L2K9NYlMCBNnTWhCeU15nemwUHn+XhX/hGmShMICuw9PlI4cApN99F7Dbxypn3MsvF8behfjp4fLzm7irXIAzJbuKiIyn/2kzfm4V55kIyoFRPE1nHck2nJGohht/hD0pnV7o/faIzXzGkeenXkFr3p6muq/Hryd9zXLpDDuMxaSkSfK5RV4nU5PldriOWJX3t06A347r2+ZqCCZByh70VoAD5kKmDwOtpS+WkfnIt3SskrjcD+JvS47nQFzA gVz/+Kf4 fM6phayRcwr1lvsUq9VaR+cOetXbLhZS2aeVuL9utVbiJI/cUWNGd3NifIZmk05vXxdQ0doVEM5yOg/KNSojH89Hl7g== 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: The aim of such policy is to prevent a user task from creating an executable mapping that is also writeable. An example of mmap() returning -EACCESS if the policy is enabled: mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, flags, 0, 0); Similarly, mprotect() would return -EACCESS below: addr = mmap(0, size, PROT_READ | PROT_EXEC, flags, 0, 0); mprotect(addr, size, PROT_READ | PROT_WRITE | PROT_EXEC); The BPF filter that systemd MDWE uses is stateless, and disallows mprotect() with PROT_EXEC completely. This new prctl allows PROT_EXEC to be enabled if it was already PROT_EXEC, which allows the following case: addr = mmap(0, size, PROT_READ | PROT_EXEC, flags, 0, 0); mprotect(addr, size, PROT_READ | PROT_EXEC | PROT_BTI); where PROT_BTI enables branch tracking identification on arm64. Signed-off-by: Joey Gouly Co-developed-by: Catalin Marinas Signed-off-by: Catalin Marinas Cc: Andrew Morton --- include/linux/mman.h | 34 ++++++++++++++++++++++++++++++++++ include/linux/sched/coredump.h | 6 +++++- include/uapi/linux/prctl.h | 6 ++++++ kernel/sys.c | 33 +++++++++++++++++++++++++++++++++ mm/mmap.c | 10 ++++++++++ mm/mprotect.c | 5 +++++ 6 files changed, 93 insertions(+), 1 deletion(-) diff --git a/include/linux/mman.h b/include/linux/mman.h index 58b3abd457a3..cee1e4b566d8 100644 --- a/include/linux/mman.h +++ b/include/linux/mman.h @@ -156,4 +156,38 @@ calc_vm_flag_bits(unsigned long flags) } unsigned long vm_commit_limit(void); + +/* + * Denies creating a writable executable mapping or gaining executable permissions. + * + * This denies the following: + * + * a) mmap(PROT_WRITE | PROT_EXEC) + * + * b) mmap(PROT_WRITE) + * mprotect(PROT_EXEC) + * + * c) mmap(PROT_WRITE) + * mprotect(PROT_READ) + * mprotect(PROT_EXEC) + * + * But allows the following: + * + * d) mmap(PROT_READ | PROT_EXEC) + * mmap(PROT_READ | PROT_EXEC | PROT_BTI) + */ +static inline bool map_deny_write_exec(struct vm_area_struct *vma, unsigned long vm_flags) +{ + if (!test_bit(MMF_HAS_MDWE, ¤t->mm->flags)) + return false; + + if ((vm_flags & VM_EXEC) && (vm_flags & VM_WRITE)) + return true; + + if (!(vma->vm_flags & VM_EXEC) && (vm_flags & VM_EXEC)) + return true; + + return false; +} + #endif /* _LINUX_MMAN_H */ diff --git a/include/linux/sched/coredump.h b/include/linux/sched/coredump.h index 8270ad7ae14c..0e17ae7fbfd3 100644 --- a/include/linux/sched/coredump.h +++ b/include/linux/sched/coredump.h @@ -81,9 +81,13 @@ static inline int get_dumpable(struct mm_struct *mm) * lifecycle of this mm, just for simplicity. */ #define MMF_HAS_PINNED 27 /* FOLL_PIN has run, never cleared */ + +#define MMF_HAS_MDWE 28 +#define MMF_HAS_MDWE_MASK (1 << MMF_HAS_MDWE) + #define MMF_DISABLE_THP_MASK (1 << MMF_DISABLE_THP) #define MMF_INIT_MASK (MMF_DUMPABLE_MASK | MMF_DUMP_FILTER_MASK |\ - MMF_DISABLE_THP_MASK) + MMF_DISABLE_THP_MASK | MMF_HAS_MDWE_MASK) #endif /* _LINUX_SCHED_COREDUMP_H */ diff --git a/include/uapi/linux/prctl.h b/include/uapi/linux/prctl.h index a5e06dcbba13..1312a137f7fb 100644 --- a/include/uapi/linux/prctl.h +++ b/include/uapi/linux/prctl.h @@ -281,6 +281,12 @@ struct prctl_mm_map { # define PR_SME_VL_LEN_MASK 0xffff # define PR_SME_VL_INHERIT (1 << 17) /* inherit across exec */ +/* Memory deny write / execute */ +#define PR_SET_MDWE 65 +# define PR_MDWE_REFUSE_EXEC_GAIN 1 + +#define PR_GET_MDWE 66 + #define PR_SET_VMA 0x53564d41 # define PR_SET_VMA_ANON_NAME 0 diff --git a/kernel/sys.c b/kernel/sys.c index 5fd54bf0e886..b3cab94545ed 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -2348,6 +2348,33 @@ static int prctl_set_vma(unsigned long opt, unsigned long start, } #endif /* CONFIG_ANON_VMA_NAME */ +static inline int prctl_set_mdwe(unsigned long bits, unsigned long arg3, + unsigned long arg4, unsigned long arg5) +{ + if (arg3 || arg4 || arg5) + return -EINVAL; + + if (bits & ~(PR_MDWE_REFUSE_EXEC_GAIN)) + return -EINVAL; + + if (bits & PR_MDWE_REFUSE_EXEC_GAIN) + set_bit(MMF_HAS_MDWE, ¤t->mm->flags); + else if (test_bit(MMF_HAS_MDWE, ¤t->mm->flags)) + return -EPERM; /* Cannot unset the flag */ + + return 0; +} + +static inline int prctl_get_mdwe(unsigned long arg2, unsigned long arg3, + unsigned long arg4, unsigned long arg5) +{ + if (arg2 || arg3 || arg4 || arg5) + return -EINVAL; + + return test_bit(MMF_HAS_MDWE, ¤t->mm->flags) ? + PR_MDWE_REFUSE_EXEC_GAIN : 0; +} + SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, unsigned long, arg4, unsigned long, arg5) { @@ -2623,6 +2650,12 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, error = sched_core_share_pid(arg2, arg3, arg4, arg5); break; #endif + case PR_SET_MDWE: + error = prctl_set_mdwe(arg2, arg3, arg4, arg5); + break; + case PR_GET_MDWE: + error = prctl_get_mdwe(arg2, arg3, arg4, arg5); + break; case PR_SET_VMA: error = prctl_set_vma(arg2, arg3, arg4, arg5); break; diff --git a/mm/mmap.c b/mm/mmap.c index 87d929316d57..99a4d9e2b0d8 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2665,6 +2665,16 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vma_set_anonymous(vma); } + if (map_deny_write_exec(vma, vma->vm_flags)) { + error = -EACCES; + if (file) + goto close_and_free_vma; + else if (vma->vm_file) + goto unmap_and_free_vma; + else + goto free_vma; + } + /* Allow architectures to sanity-check the vm_flags */ if (!arch_validate_flags(vma->vm_flags)) { error = -EINVAL; diff --git a/mm/mprotect.c b/mm/mprotect.c index 908df12caa26..bc0587df042f 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -762,6 +762,11 @@ static int do_mprotect_pkey(unsigned long start, size_t len, break; } + if (map_deny_write_exec(vma, newflags)) { + error = -EACCES; + goto out; + } + /* Allow architectures to sanity-check the new flags */ if (!arch_validate_flags(newflags)) { error = -EINVAL; From patchwork Thu Jan 19 16:03:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13108323 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 36E44C6379F for ; Thu, 19 Jan 2023 16:05:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A5C676B0073; Thu, 19 Jan 2023 11:04:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A33096B0075; Thu, 19 Jan 2023 11:04:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 837B46B0078; Thu, 19 Jan 2023 11:04:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 6CECA6B0073 for ; Thu, 19 Jan 2023 11:04:59 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id C4D451A0DE2 for ; Thu, 19 Jan 2023 16:04:58 +0000 (UTC) X-FDA: 80372022276.23.20D9A6B Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2042.outbound.protection.outlook.com [40.107.21.42]) by imf24.hostedemail.com (Postfix) with ESMTP id 95CD7180019 for ; Thu, 19 Jan 2023 16:04:53 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=V73VpP7Z; dkim=pass header.d=armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=V73VpP7Z; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf24.hostedemail.com: domain of Joey.Gouly@arm.com designates 40.107.21.42 as permitted sender) smtp.mailfrom=Joey.Gouly@arm.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674144293; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=TVqUovDaP0Eis0yf04LEyuGnbnC1xSyDtOGIyaojtyA=; b=z6g+7HSWWwcbqvp9jdfT9hu8yHt1nX60FXoe72iiWJHQ7Ho2TpYUfsClLGM77Q13UJ5poX 6zJJkCza1fIIUjy2NO7lp0/dZGkf8Rvn1dOX7PvzoDPuwzDToQUuyQrGvnE3JfOUdB5VYY MA5caV6/wvVdYAtDFSQUkqpEw8vtYwM= ARC-Authentication-Results: i=2; imf24.hostedemail.com; dkim=pass header.d=armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=V73VpP7Z; dkim=pass header.d=armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=V73VpP7Z; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf24.hostedemail.com: domain of Joey.Gouly@arm.com designates 40.107.21.42 as permitted sender) smtp.mailfrom=Joey.Gouly@arm.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1674144293; a=rsa-sha256; cv=pass; b=aet/nh9f5sMjUwgqL4OPVNYErdHIFiApQkr42hqiAvDeASYlgghr25erhCucyxZjgXbbfd jRiX38+1Mr7OjWJLhIqhPWC9Q0NeuI62tvv0R7gM0znE73XNgXFupm4zb8l68chpvopIAg fVBYT4jev3mxRTPQC/p1wDfIoXg25VY= 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=TVqUovDaP0Eis0yf04LEyuGnbnC1xSyDtOGIyaojtyA=; b=V73VpP7Z56d4ftzhBcoPMGZ9SLcgx2v+yQRa3sVGW8+g+RNr3WXtcxzKfKEopOaf6/fA+oVFIJNkeDcVD8WlzEhCGDQTPC3x2omvjJtzgb1TPbzDurgNIOmdIMzQOHPIJc71uAF/aBhPajxfTksFhirqFMOVcl19qLOdkP2qfWo= Received: from AM6P191CA0073.EURP191.PROD.OUTLOOK.COM (2603:10a6:209:8a::14) by PR3PR08MB5852.eurprd08.prod.outlook.com (2603:10a6:102:8e::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.13; Thu, 19 Jan 2023 16:04:50 +0000 Received: from AM7EUR03FT017.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:8a:cafe::d7) by AM6P191CA0073.outlook.office365.com (2603:10a6:209:8a::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.24 via Frontend Transport; Thu, 19 Jan 2023 16:04:49 +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; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM7EUR03FT017.mail.protection.outlook.com (100.127.140.184) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6023.16 via Frontend Transport; Thu, 19 Jan 2023 16:04:49 +0000 Received: ("Tessian outbound 3ad958cd7492:v132"); Thu, 19 Jan 2023 16:04:49 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: ae1d195896073eb1 X-CR-MTA-TID: 64aa7808 Received: from cb9ffc682106.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id A654F2B7-F24F-4434-A2CE-8B00202A7FD2.1; Thu, 19 Jan 2023 16:04:06 +0000 Received: from EUR03-DBA-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id cb9ffc682106.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 19 Jan 2023 16:04:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CBt93A7pn/yhEWmvxLmH/8P+JHctCpPg7sYTkvGXHdiiSbGx1LXFtb/8WcPM7WPpbQzxXfWKB3Pix6TkYws1PmC0WQI2HJmtJ5ecffAPSWnH2cX4Bt0EX2DV1LbiQ6hf0/w0XC6FW/dExrMlB03pYBEs+qFe0ABLCKScmmaBgWYIVIxI2Ip1TUxu3WMDMl1lduIp+5Zil1rPHUNryZWl0kPJHBzSy9SkgaKgXXQGzOHeriFBQOCt7igUd944YUuGd0SzdRmcXuybF+QbybekDdZW43Nqg9qkmFwtj5UPiCyvYOn9f2T3Ctu+D5OalJsOcCp7IUKlZTOKjcQIbGwEUg== 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=TVqUovDaP0Eis0yf04LEyuGnbnC1xSyDtOGIyaojtyA=; b=lWIpeJ8qhIemmks1v+GMIPZlJ79+SYK0tidfOmXXx8EVUbVkiR7iF5XAvBB3wds/s/CnVUKnO4WVPZdV8rEqSCScdBYDbljIdGsezkPWBwMKyszzzt1cjsRhA8PCxeqwWvCPQvYXQ+sSJDUdp2Vb1sBzfAXkwb6czpElYSkHBXDNtkGBmyO/3tFVTJC44Z3CiOKJVenTJhg7tLGjEUBkYQAxE8djMWyY2EN92LgLR97E8AmNsbL0/KU1XWPTmpirj/aPgHt+rDv9JRYMdz0TJxCS7j2+6bTxniYUMsJ7BY+ivtGLcUw4BhFw0DhTMpaavlT0NEbDLz7CEgPFemnGnA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=linux-foundation.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=TVqUovDaP0Eis0yf04LEyuGnbnC1xSyDtOGIyaojtyA=; b=V73VpP7Z56d4ftzhBcoPMGZ9SLcgx2v+yQRa3sVGW8+g+RNr3WXtcxzKfKEopOaf6/fA+oVFIJNkeDcVD8WlzEhCGDQTPC3x2omvjJtzgb1TPbzDurgNIOmdIMzQOHPIJc71uAF/aBhPajxfTksFhirqFMOVcl19qLOdkP2qfWo= Received: from DU2PR04CA0342.eurprd04.prod.outlook.com (2603:10a6:10:2b4::21) by VI1PR08MB10121.eurprd08.prod.outlook.com (2603:10a6:800:1c4::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.25; Thu, 19 Jan 2023 16:04:02 +0000 Received: from DBAEUR03FT022.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:2b4:cafe::90) by DU2PR04CA0342.outlook.office365.com (2603:10a6:10:2b4::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.25 via Frontend Transport; Thu, 19 Jan 2023 16:04:02 +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; pr=C Received: from nebula.arm.com (40.67.248.234) by DBAEUR03FT022.mail.protection.outlook.com (100.127.142.217) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6002.13 via Frontend Transport; Thu, 19 Jan 2023 16:04:02 +0000 Received: from AZ-NEU-EX02.Emea.Arm.com (10.251.26.5) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Thu, 19 Jan 2023 16:04:01 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX02.Emea.Arm.com (10.251.26.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Thu, 19 Jan 2023 16:04:00 +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.2507.16 via Frontend Transport; Thu, 19 Jan 2023 16:04:00 +0000 From: Joey Gouly To: Catalin Marinas , Andrew Morton , Lennart Poettering , =?utf-8?q?Zbigniew_J=C4=99drze?= =?utf-8?q?jewski-Szmek?= CC: Alexander Viro , Kees Cook , Szabolcs Nagy , Mark Brown , Jeremy Linton , Topi Miettinen , , , , , , , Subject: [PATCH v2 2/2] kselftest: vm: add tests for memory-deny-write-execute Date: Thu, 19 Jan 2023 16:03:44 +0000 Message-ID: <20230119160344.54358-3-joey.gouly@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230119160344.54358-1-joey.gouly@arm.com> References: <20230119160344.54358-1-joey.gouly@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: DBAEUR03FT022:EE_|VI1PR08MB10121:EE_|AM7EUR03FT017:EE_|PR3PR08MB5852:EE_ X-MS-Office365-Filtering-Correlation-Id: eae1544a-4899-4880-c7e5-08dafa36e496 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: hQajnFbyiBtM6evBKQi+8/X+dow65HqZhKYZGVA+iJZDjLKrxsvrAZOiCBjxCysA7VHjnJSezMa8HBYQzGPp9ChJWfC7X76NMtNlZAi5qi57C8xbovpsWefWfEiobXj2bkUqN+2RbuV/OnovppztDdO+wjZw/kvCJ9cnKEhR/Vb3u9UAPLkI7ECcmcl+U1aWlUd2OgjtUdz1p9k6qO+5NQsIyeMnsjIcmSyCg6zCuBaZLoxTMYaIN/O7mgbQd2JSVajB/UIgzyU7CZgnm8XS6szjKwHkqg2AFiIDow5W1+DBgDG2GJteOqvpVcRVJZqT9S3ehcBKDoEmlblgpuynnZjlGIvuuDD9HI4YPRKSQG3MJWYLbPeUjjYoHlUgDMCBkJ1Ks+9RdHiAXCNUh/FJl4Nz7yBp7wrEKMPNk8siu0+QMQDSGTc5HMPeJznCLoHBu/8g2YNv9XaNdZ5FWSCMgSR78skWVK9l3w9E7l0zhTmNDHiUjFqNdWv9S3t2howiQ/1Ru/ZyPq2GdNczXUxvQW5i55ukKvkXeidGAoTXUaBFsAlbw8qK/qUYChv6tLmG9ll5OZ91yzARwwZlKgtdGedzAXwpE1DoPefc/pBWlpvPF7RWFKzi6+NFPOQ1DhzZPnU9zVneZ/aE7IUFbvyNGQcuLS1ClpumxMUcJ5AD6GStf6kbAYzVIcwSqG6DhmQmDl1AjHtnkXJG3AnfOkvTvY9Dpp64RdavF6SgY9HFA0o= 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:(13230022)(4636009)(396003)(39860400002)(376002)(136003)(346002)(451199015)(40470700004)(46966006)(36840700001)(2906002)(36860700001)(81166007)(82740400003)(40460700003)(426003)(47076005)(40480700001)(82310400005)(36756003)(2616005)(8676002)(316002)(110136005)(7696005)(86362001)(356005)(54906003)(70206006)(7416002)(44832011)(41300700001)(5660300002)(4326008)(70586007)(336012)(1076003)(6666004)(8936002)(26005)(186003)(478600001)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB10121 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM7EUR03FT017.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 282693c1-6223-41a5-f24a-08dafa36c854 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: R/3LQG5wmcFWXlX2dJ5kDsCsOE4aYrmb2/7FropCnwI8UuDMF8ZcznZZxgPic4x8cyQfQWzrCSiRNXlxoQeJvk7MErquB8DgOXFoAw3tvPRjpAprmhhq1kWOEv9hn+SbomfRrjtDClRpmXKFxWy9yo4PZBGFgWiMQUX7k7wnVgqOOIhb1qpx0w4FyLOd2y6M856uje5+YEEXZfrux7gI6SIsPbXgGZxLycGmUqm+HdhXUOfoPAC0Pkwjm62/RNQkhAnKHgU8jBCBXeEevvK5a+daiAKBNy0vj8g/zwHDWGwBhVqocbNFMXA7VZ+FBTGlPjg0NeCIBueF3apev7W6CPvTAklFYqMGPe8Qu87bqTbNFqCiTuDKtNFBqTrFcYfBLsvboNvFPh+YTgZgUlIN/nlmikNj350hNAxd/0DdBa0GceoFqG4SW7utE52KMi6hNfd9VlT1/yL8CXRCai+ONmLgtgtr8wez4idyH3pYxofiK2w7gl20vmDuKtjYgyi38IYzXffL3zYvvLVaM9OZ1V08R79WUFsU9h+KFXMwzIDhp9v6VTBYcg0hmAhl+2oDyhdZZUAct4ZBdVrSx9Im+NqjJHSBnIPADrfC+V2+0vuQdPFFtaMspxyig6FbKqNXD3bB7MmWJV5+/KiEuZxziO6+hA2POQFMmFl+PRN5IWLdDGqL/4RryXHtmnFyIyadx/jkAVDDDLfZofyJWfH8kA== 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:(13230022)(4636009)(136003)(346002)(376002)(39860400002)(396003)(451199015)(36840700001)(40470700004)(46966006)(1076003)(44832011)(2906002)(82740400003)(36860700001)(316002)(81166007)(8936002)(70206006)(478600001)(26005)(82310400005)(54906003)(426003)(40480700001)(110136005)(8676002)(6666004)(186003)(7696005)(5660300002)(40460700003)(107886003)(2616005)(86362001)(4326008)(36756003)(70586007)(47076005)(336012)(41300700001);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2023 16:04:49.5830 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: eae1544a-4899-4880-c7e5-08dafa36e496 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: AM7EUR03FT017.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR08MB5852 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 95CD7180019 X-Stat-Signature: 5zm98qkoxccs4epqwrxpsst5gfaz1j5b X-HE-Tag: 1674144293-346509 X-HE-Meta: U2FsdGVkX187gz/hci7iA3890Jor7cFFtiYm9J3n3RdfK0zxKJoLgyu81Ob/pz7I/0FWVmNRuUF19R1eNqSE2R8Gj7E1MHmJDBn6LoujNOps6rqJ5DtDE8xiA/kcW8OfvOXfbprm/hijikyrvTpjzfDSR/ALvU6h24vnP/mwLTTa5ESXv4Wzquca1qk9WGrCo10HI8W3WzhVsYouO46fN8x3CrMwJW2CFNjdhcj1jw+KeezLRbd2D0na3owQtnrgETLbu8OsHb7Eft1Fe1OjlTcbW5Oz5yJ7/TjbbPs8kJgRBFWylCzlXHg9s7PMO3qftDTUDa/d/GwMQ+Hdnd3mLQ+mb24XyfF6wAGbo3kqD/7FBw4L2Rs0cHVZ2x26asG05+J3YKIWAoBPbTG7keRnI3Jai8v0mZ9uSQXaMo6YrSvnQCuR25RaUZAHqhBx4UASXrtEejC7xHkOCLGxrG8vhCgjVz0mPfHfvsuDbXU4NTePjUsNIHUYIqFR7e10e5btBjo2kON7WmMW0Swka0Icy1UcHk1g3zqEdMEoquM8LnLjwhMnu2/MTnuJVWfG+178qbGSDJxDBxSKlwJYKpLh9f0Mp0UCx9UdtDzlDaKaUnd8+VcbtNlAOMvDtZCUcirK9C/gb+hirNRHramn88J8gk0Ovc/9/zco6gARj6mysI1SUV2trjWQmIg0Xry8zyLNdZgxPmVili7XeFVmGYipQHmm3gkq58dT+KXxAHhnNflyWnV0uhOm3iDps6ArrY+FfDylq2vp2Gpd4Sux+29bL8AuEexCxvlOJbJYc8Iv3xSRotWVcB258H3rnXSegI2MuJ476h1BZx26F7op9RC6NfyQrygZ7TGHp77EFPlOSAJMIyM47qLuICIjrnBOELz1RXnQt4vXgX7PEgbR8ZPJBiLrOofSGBo4HPoWpgX60K5p1SABz0xfJd8+TAAWUSV2NrT4gVYpiZOSdu27lu/ jZ2N54JG g/WRc1OyOJyboxp9s3hmxFj17XCEJhj+2YX0mc2OucY4H9sx+c6EiETmdqkwOW0VKCJbgJJQAJCWMMJVhDrfD1+djgQ== 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: From: Kees Cook Add some tests to cover the new PR_SET_MDWE prctl. Co-developed-by: Joey Gouly Signed-off-by: Joey Gouly Signed-off-by: Kees Cook Cc: Shuah Khan Acked-by: Joey Gouly --- tools/testing/selftests/vm/Makefile | 1 + tools/testing/selftests/vm/mdwe_test.c | 197 +++++++++++++++++++++++++ 2 files changed, 198 insertions(+) create mode 100644 tools/testing/selftests/vm/mdwe_test.c diff --git a/tools/testing/selftests/vm/Makefile b/tools/testing/selftests/vm/Makefile index 89c14e41bd43..4e1a7b1d4c52 100644 --- a/tools/testing/selftests/vm/Makefile +++ b/tools/testing/selftests/vm/Makefile @@ -56,6 +56,7 @@ TEST_GEN_PROGS += soft-dirty TEST_GEN_PROGS += split_huge_page_test TEST_GEN_FILES += ksm_tests TEST_GEN_PROGS += ksm_functional_tests +TEST_GEN_PROGS += mdwe_test ifeq ($(MACHINE),x86_64) CAN_BUILD_I386 := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_32bit_program.c -m32) diff --git a/tools/testing/selftests/vm/mdwe_test.c b/tools/testing/selftests/vm/mdwe_test.c new file mode 100644 index 000000000000..f466a099f1bf --- /dev/null +++ b/tools/testing/selftests/vm/mdwe_test.c @@ -0,0 +1,197 @@ +// SPDX-License-Identifier: GPL-2.0 + +#ifdef __aarch64__ +#include +#endif + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "../kselftest_harness.h" + +#ifndef __aarch64__ +# define PROT_BTI 0 +#endif + +TEST(prctl_flags) +{ + EXPECT_LT(prctl(PR_SET_MDWE, 7L, 0L, 0L, 0L), 0); + EXPECT_LT(prctl(PR_SET_MDWE, 0L, 7L, 0L, 0L), 0); + EXPECT_LT(prctl(PR_SET_MDWE, 0L, 0L, 7L, 0L), 0); + EXPECT_LT(prctl(PR_SET_MDWE, 0L, 0L, 0L, 7L), 0); + + EXPECT_LT(prctl(PR_GET_MDWE, 7L, 0L, 0L, 0L), 0); + EXPECT_LT(prctl(PR_GET_MDWE, 0L, 7L, 0L, 0L), 0); + EXPECT_LT(prctl(PR_GET_MDWE, 0L, 0L, 7L, 0L), 0); + EXPECT_LT(prctl(PR_GET_MDWE, 0L, 0L, 0L, 7L), 0); +} + +FIXTURE(mdwe) +{ + void *p; + int flags; + size_t size; + pid_t pid; +}; + +FIXTURE_VARIANT(mdwe) +{ + bool enabled; + bool forked; +}; + +FIXTURE_VARIANT_ADD(mdwe, stock) +{ + .enabled = false, + .forked = false, +}; + +FIXTURE_VARIANT_ADD(mdwe, enabled) +{ + .enabled = true, + .forked = false, +}; + +FIXTURE_VARIANT_ADD(mdwe, forked) +{ + .enabled = true, + .forked = true, +}; + +FIXTURE_SETUP(mdwe) +{ + int ret, status; + + self->p = NULL; + self->flags = MAP_SHARED | MAP_ANONYMOUS; + self->size = getpagesize(); + + if (!variant->enabled) + return; + + ret = prctl(PR_SET_MDWE, PR_MDWE_REFUSE_EXEC_GAIN, 0L, 0L, 0L); + ASSERT_EQ(ret, 0) { + TH_LOG("PR_SET_MDWE failed or unsupported"); + } + + ret = prctl(PR_GET_MDWE, 0L, 0L, 0L, 0L); + ASSERT_EQ(ret, 1); + + if (variant->forked) { + self->pid = fork(); + ASSERT_GE(self->pid, 0) { + TH_LOG("fork failed\n"); + } + + if (self->pid > 0) { + ret = waitpid(self->pid, &status, 0); + ASSERT_TRUE(WIFEXITED(status)); + exit(WEXITSTATUS(status)); + } + } +} + +FIXTURE_TEARDOWN(mdwe) +{ + if (self->p && self->p != MAP_FAILED) + munmap(self->p, self->size); +} + +TEST_F(mdwe, mmap_READ_EXEC) +{ + self->p = mmap(NULL, self->size, PROT_READ | PROT_EXEC, self->flags, 0, 0); + EXPECT_NE(self->p, MAP_FAILED); +} + +TEST_F(mdwe, mmap_WRITE_EXEC) +{ + self->p = mmap(NULL, self->size, PROT_WRITE | PROT_EXEC, self->flags, 0, 0); + if (variant->enabled) { + EXPECT_EQ(self->p, MAP_FAILED); + } else { + EXPECT_NE(self->p, MAP_FAILED); + } +} + +TEST_F(mdwe, mprotect_stay_EXEC) +{ + int ret; + + self->p = mmap(NULL, self->size, PROT_READ | PROT_EXEC, self->flags, 0, 0); + ASSERT_NE(self->p, MAP_FAILED); + + ret = mprotect(self->p, self->size, PROT_READ | PROT_EXEC); + EXPECT_EQ(ret, 0); +} + +TEST_F(mdwe, mprotect_add_EXEC) +{ + int ret; + + self->p = mmap(NULL, self->size, PROT_READ, self->flags, 0, 0); + ASSERT_NE(self->p, MAP_FAILED); + + ret = mprotect(self->p, self->size, PROT_READ | PROT_EXEC); + if (variant->enabled) { + EXPECT_LT(ret, 0); + } else { + EXPECT_EQ(ret, 0); + } +} + +TEST_F(mdwe, mprotect_WRITE_EXEC) +{ + int ret; + + self->p = mmap(NULL, self->size, PROT_WRITE, self->flags, 0, 0); + ASSERT_NE(self->p, MAP_FAILED); + + ret = mprotect(self->p, self->size, PROT_WRITE | PROT_EXEC); + if (variant->enabled) { + EXPECT_LT(ret, 0); + } else { + EXPECT_EQ(ret, 0); + } +} + +TEST_F(mdwe, mmap_FIXED) +{ + void *p, *p2; + + p2 = mmap(NULL, self->size, PROT_READ | PROT_EXEC, self->flags, 0, 0); + self->p = mmap(NULL, self->size, PROT_READ, self->flags, 0, 0); + ASSERT_NE(self->p, MAP_FAILED); + + p = mmap(self->p + self->size, self->size, PROT_READ | PROT_EXEC, + self->flags | MAP_FIXED, 0, 0); + if (variant->enabled) { + EXPECT_EQ(p, MAP_FAILED); + } else { + EXPECT_EQ(p, self->p); + } +} + +TEST_F(mdwe, arm64_BTI) +{ + int ret; + +#ifdef __aarch64__ + if (!(getauxval(AT_HWCAP2) & HWCAP2_BTI)) +#endif + SKIP(return, "HWCAP2_BTI not supported"); + + self->p = mmap(NULL, self->size, PROT_EXEC, self->flags, 0, 0); + ASSERT_NE(self->p, MAP_FAILED); + + ret = mprotect(self->p, self->size, PROT_EXEC | PROT_BTI); + EXPECT_EQ(ret, 0); +} + +TEST_HARNESS_MAIN