From patchwork Thu Nov 28 15:06:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13888111 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 6F393D69115 for ; Thu, 28 Nov 2024 15:06:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 33E486B008C; Thu, 28 Nov 2024 10:06:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2CB5B6B0093; Thu, 28 Nov 2024 10:06:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0A4316B0096; Thu, 28 Nov 2024 10:06:49 -0500 (EST) 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 C93C56B008C for ; Thu, 28 Nov 2024 10:06:49 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 8CB53AE220 for ; Thu, 28 Nov 2024 15:06:49 +0000 (UTC) X-FDA: 82835830602.07.029D517 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf16.hostedemail.com (Postfix) with ESMTP id 51C9E180019 for ; Thu, 28 Nov 2024 15:06:38 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=Foa8+6OT; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=yIyuBfjV; spf=pass (imf16.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); dmarc=pass (policy=reject) header.from=oracle.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732806400; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=fucP9TZcpv3nFaY0Gbv55QIlReHIn6dziNcoY5psffc=; b=6wmfZMsHx7ovBWMlXD/8gZAWGqCIrMnPMJpTphtea2uZV6Ors+BsGp31GoeCs3WoAjIjoB n0Dr907e+T4hG/9s5CgkymiWAPcpi0ZOWEz6AbrD5vYZmDXLCyfXooGxz0Scj/RM6XJlJs RBLB3lv6AMISAHUaRJDwqCSo3WPSh8M= ARC-Authentication-Results: i=2; imf16.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=Foa8+6OT; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=yIyuBfjV; spf=pass (imf16.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); dmarc=pass (policy=reject) header.from=oracle.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1732806400; a=rsa-sha256; cv=pass; b=HjaRLHAtj0+bpjk9E/tsVqSQBC09QxgVmMwGuGWCcnzCQrIrFNXwXPcbZnr7sixzIBmS/7 xhdynMr96uL+Kbuu0hv5DhvD/7S7/PNjayHDGRhEy7KrYxda+VA+U9M/1cDqtktjX/yCE+ 2PgU6j7JOeFZrptlLJrEsAFDAkf9W/o= Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4ASEHEF5029077; Thu, 28 Nov 2024 15:06:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=fucP9TZcpv3nFaY0Gbv55QIlReHIn6dziNcoY5psffc=; b= Foa8+6OTwHD6U+EEOxlH/kVEYbQAR3i1/2MLUs8ylyXtei9nwUCOTgbeRpfINquq 5Q6MNotOH0/yl6M0+ThH0I0t9W8bL1jmTImm7TzwIsTM1K2KdggJ5CRpOVCUgbiC eosytAgtYXZQdnHi4jLtBMgn66AwqwyONQSWUbpY/cXAvjL4sljQ8cYgceC0c/rq 3fa3Zc4CWaMmWvbsufWXN+6vKIlxOhnrrWDRrACRT0Q1tV5HrKypGDGcQDgwSYeA gUjf+5veYRebROOGSR6Gywpl0FIOIxHG+ONQxMapUsq2m5QcNN6qMoY0Y3GA72aG CUnxBy6hc5BCdI0Kv6F4qQ== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4366xya0dm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 28 Nov 2024 15:06:33 +0000 (GMT) Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 4ASCoAdJ039401; Thu, 28 Nov 2024 15:06:32 GMT Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam04lp2174.outbound.protection.outlook.com [104.47.73.174]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 4367067rd6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 28 Nov 2024 15:06:32 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=UyimR1ypqav743DhnI5vxXzSEEDYWMZGoAaYWAbWed3CGnxo2EUsiPTSBfFtib64pw9k5KzVQe8wiCyCAbhisCyoYCiEKvNZnRURyVoEoVHLFiyDJefpG44FSbpFcAyfdINd+gu404ZTg3MX+6LOR1aMckQjInBO6YG0LyG7jGslgsIg7dU/3hpYCI1h6rVo01/5IKkIbJeEkeepeeCyvzuaqQAnGxzi/pv7xWthY7/p6/62FlrifWqhkGrJ/LyLLq4bstnFPdqAE4Kl4Osp8kUUIywWDYeOFO7QVb8uEqZV8ofOsZdkpma+bBYK8SuqWKjgIn6ptsCfQo6+SWvjNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=fucP9TZcpv3nFaY0Gbv55QIlReHIn6dziNcoY5psffc=; b=J+qiue+g0UsRetMoS0zd2mCIM3fNtEmr0D7lCy7PWQG4eMU4w2cHRWzdQuuR0tPMNQVBtH2KoBG+qc0sVcn2amUOH4TvOW/hmA1HMsTJ/1O8c2U6RmFOMX46HfoDdQbZ5c/BbwR6y25d81YmQT8Ujym6pjlbX5t43lKri8bX7BZn/1a8PurMFtSMptD3nALyLJMx+OmWhzU4VO02NE+lyok69XH/zsNXho12LOn1LeqQvI/LLMz4DqQCJb6qpOTjeOmFmvVT34roeA8iLIkppdpy9nxtjbwWYXNLbCpO3I3FjhLRYJxC1jheFhAZ4KMUg8taHu5K4TBlTvjh7/mFGg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fucP9TZcpv3nFaY0Gbv55QIlReHIn6dziNcoY5psffc=; b=yIyuBfjV/9d/t4RqsKxxb0stezM/8lan1AtYkVVUT47RQdekQNfCX7pqta9UM2GsQK788iMctiQK9Br9fg8pO3ZOGtSkVeVcjQv6Rgo2IzOTKW00Zu2duN5vatrW0bRnrJSkvrlL847GeL67TuzmhYCJIBcBwbr1UvmIa2VGGZA= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by CH3PR10MB7958.namprd10.prod.outlook.com (2603:10b6:610:1c9::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.14; Thu, 28 Nov 2024 15:06:28 +0000 Received: from BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9]) by BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9%7]) with mapi id 15.20.8207.010; Thu, 28 Nov 2024 15:06:28 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Jann Horn , Shuah Khan , Julian Orth , Linus Torvalds , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] mm: reinstate ability to map write-sealed memfd mappings read-only Date: Thu, 28 Nov 2024 15:06:17 +0000 Message-ID: <99fc35d2c62bd2e05571cf60d9f8b843c56069e0.1732804776.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0463.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1aa::18) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|CH3PR10MB7958:EE_ X-MS-Office365-Filtering-Correlation-Id: 63b9bf99-9dd6-4af8-a7ef-08dd0fbe3c41 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|366016|1800799024; X-Microsoft-Antispam-Message-Info: AOnzsvPivvUwGSh5zDT91KSRhi363SQx/kMIYeLJai1lR3Z27B1gcGh/r9jTy7zUeZWNQk+DuJX/aGBa6D9xmLYOCH9DVzW6DZZkWV0vdCnZ+WYxtVfwFlkBFbq2YUQHfQYHFjt76IOl637i039msLCjaZyYPDpgVT+r8Pb/gHP6WG3JutMCZ4HtLvzOmp+wbzALgyzQ0iZn5h7MPehlp6aXfyYebmTK0deuuoDK3rMbHvCcmmlRVrfcKVhZ9G1IukOzFHS6NAsuvhrO+0FtJF4HSnWYEoq8zK+OBDPI3juh+1QIn1aYo6XbLXDuY5OzFeXYsjB9TDbOYW5G96o/ExpbxGjh2SeebNAPdHLif9q79vHzIfPZ+aOyblCUdzdskaoDUQye7TJs5uhxF1DEzL19OHA+PfTXIVtSguyk/tkf5pOm+xTxczxIQoUEVncd5jvGrSODSjrNTQlSR++r6kv6KIj9VzEnIyz1mgxl5LttTss4fbTtKSK5ytTQf296jG47FIzY2o3khjLPzSLL5KAZdsnnUqN6r7NmOj9k4wbXQVJoIw+zhQ+c0AyoD43PujclZTAnTLfLMwnlfYJ9qCCdvmsUnkScxOH1Ir91I9pC87gSzCEsIkLQqBt5GQCciXqE19wcyjG5ikt/rT7olnD4SiexCJ+RKuLsegL1VnDabSO5go8oDFfQpX3sk4DfmghgacyHR3oBusLz8muqPFlsmXmleGlabLuWLgDVwlDyH7ixZxjAXaTy4z2Fe3bMokV34vVHnNDsKqXuNGTtJjDvrcSe+1LDzfzykKEEziqfhKwNENmRBP77EP0tlPFq2NOB6JFTZcgxON6K+/Z7dybcWZd3OC5PsSrgX/pJjc26q3smN/21vFxUX2mF8RnyoEuXIEcOv0N8lO3iLYGOKeGEEc46GfEW9iYR/OQuQ1+xwe2MWtTXVVzYY6sNu5e2j9m7R90EuGAP19YfSYJtFPfrX0gjlIvC/FKGAXP12ISW4dRMu9xEQ4Ui2kpMb33jiEiYoqmpAbJboiB9eLoF1d2+7g6PQyEcKQqD72btzz+PRgJgR6EgU89R1ddmfv/p4dV1gRUZFoyVIrwW3oIysdj/2w//NmwSSgn1gg5UgXra+AeD7qp7e6g3FoucCe2Ujyp9M4bmN3mm+3Ajd7Jj176EZ1Ze64FhXSHIm0CEU57ltebYKfqr0ZIztcrxU7/GMpiK6ebGbDXEWltGMuAYLsMRbf184/xmCy+Z4kj1DYDjlBi9V0SX7LaruLaA35AlEb0MNCKyB21lNmYDEF0nk+5rOWZQ7YhIW5piiuJkIAFA4fL4ACqosfsWjOgdafONIyJl9Bkm9vAThmx7dVCR6YqBp5QhtPj7dSgKEpi1pKQ= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB3366.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Ofavroy1XnfDc5AzfVEZfqKb6oIY9c6JTXFYRmkx0WZbEOx4PK1Pc90EUde+VyHz87aMmjpP2OeD/Jolk2pFoH3RP1kKc2YfF1sJZWVG4+cpMbvOVAa+95ESionnDckGntQKfbpP+1g7N4WgiLl+NetHAH0gFvAvz2J5YBw5meclqPfAtawVZgSqI+SBV8lCuCnIlDvGfa10Q8JqKDCbajfcZ0QL1CEl/HXpAcOeptArn/FyizTYGpo3ZjGSI8SUzhvIkF8uL6BsLO82gccfIOQ+HiLA45j+4dVqUgJtAUVzzcP7SjAOoBPwaVMJmnO/siXSXcVj1zpCrHv/nHc/OCukE0BrSUccqxoE4WcIXtuRJx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FPS+4Cl+R+JPVFyqjhm211OOEHHTVGEJNRddfc3J392pt0Se3iD5k+unwRSjV+bMp3SJhR196TIeMHltqYGjbkTtnyfBKMngc3vnHSaFfVfeUoPB/lUuEh4t+5bZnLldoQIcGOAaT1DXT0Nf3Mve8HiJXRmB5y5SDH/WnumDsNaP281CUKgRMxlQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: XDEJufNTbQ3zdV1/73xl6NlJMfdjXc2abv6BNQUZsFJQSXJb4vsuzOgQR5FTLs0mpPjoUXzb2Is0iA/nq9c31ZwOrHeDVsb98p5dPyHq5aemr2IWy3XEkQANaMVZsTa1lQtaPa7bF36VfTAtfXmkkJM4MyYeC8D0Gy+INqR5dlf+lBdglq0aqTFg8osyu3VbduUpTljLi6X9RyCercyjb9wipB3dV/Fv5kJE1s4FEMHlcwW9kQtfEGPhrdksoY4u5EKXPt4NAAeOZpvg7bDqAI5PfivwlfOVpFT0KbGkPX2rTwd/GwpAth6m87jAvvFrzXuVrgiy7wbqazl63Pr2AERMe7XvNOf9pFgG0yADVW0ngikiPVvbuMkJjkY5uVcbzSrqs8veT1HHhrS07hYgq/EeRWjPoisN7AXcp1qMSwaoRuVlw5rY3NllKcjWj3t0Lu2g1FZnAlTVo8mQG9sAc7LMVrY2gd8gvfK66QbZlDSTxM8mqtLeuTCZGa0OmkzHOsLDnTNXsQL+MKCKobg4HAiu1I6JukOWadToMc1Lmr25B4Gs/mjz8ksBj1SYGDgI7D+QL27Bhx3d+HyeNdyIb3N2HEHv4tpxUBsAY15w/6k= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 63b9bf99-9dd6-4af8-a7ef-08dd0fbe3c41 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Nov 2024 15:06:28.8205 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: t983o9dYim50ZWk7OFsBtBOIaiUj4dKTYjqsrcNK545CAzRUhrF5Y6uDVIanfipt44XBeXE46N7Us7UIzi0DJTnx/39vBwIXR4ZQddrr0zA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR10MB7958 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2024-11-28_13,2024-11-28_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 malwarescore=0 adultscore=0 bulkscore=0 mlxlogscore=999 spamscore=0 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2411280118 X-Proofpoint-ORIG-GUID: 25Myjd7UpdGfHX2JGNRCTFL9VbzoU8Cx X-Proofpoint-GUID: 25Myjd7UpdGfHX2JGNRCTFL9VbzoU8Cx X-Rspamd-Queue-Id: 51C9E180019 X-Rspamd-Server: rspam12 X-Stat-Signature: u8x4f3aam1fam4f8f65dupyn4jfpwzfx X-Rspam-User: X-HE-Tag: 1732806398-332414 X-HE-Meta: U2FsdGVkX1+C4uLAz+xJEt1lpjS7nU7WOVWgCLUI4V2dWjVHk9j2OqAAXOqT0tn0EH7AunQrYPMY0nTxUEGmr59zt2BP9wmz8nMH8Q5T6imD+pLVuW9TUzaELwsL/loOIYB7ddRlCf0cvokmJV0BFs8Q5ndQzaeD3d5ZXnqyUQZYSzLD2cV8gHW7X2p+C7g7ZpB/Qiuc1yOjGusRfw9MVIFM5WZgVJ9Av7wkhgGnzpNB9K7HqBkuSxJdCvGBpY7Lc2EXtciJupHJkRnqOWigDnqKCvV7fu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YMvCaQlqw2OVHETesocsQWm1fEEETUvU5lLdGFAKu9UfDXECmSr3FU85KkbCWMAQg3o54a1CH6Z0DSYCPSfFWOBrImcYsJA9AKWjPRdlfohmTfg4HmPB5khDww56A/3t0rSbj3DAMmnUTX6VX/ID+tx0aPUAYPhPrO5IZrjPSyoAvhVs/p3yDHip+OmlEymWdT4H+AfdT0SKwGu0Pug9x+G83Uh/Hcm2mD6nS3uviIQC+69mNagnCfQ+jNHubL8Dluj+E6mmieltRVdHoByXgiFdq/H/QUIB9t0ygk7E0DYZX9zqp8mVHnrwUJnnjBrohtDpQT3A56mjIqNxcXfPdN4UlQesSab4cCLzEThStf4tKvj0HVrqNYT4+g5zQg25o6NeXDm4= 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: List-Subscribe: List-Unsubscribe: In commit 158978945f31 ("mm: perform the mapping_map_writable() check after call_mmap()") (and preceding changes in the same series) it became possible to mmap() F_SEAL_WRITE sealed memfd mappings read-only. This was previously unnecessarily disallowed, despite the man page documentation indicating that it would be, thereby limiting the usefulness of F_SEAL_WRITE logic. We fixed this by adapting logic that existed for the F_SEAL_FUTURE_WRITE seal (one which disallows future writes to the memfd) to also be used for F_SEAL_WRITE. For background - the F_SEAL_FUTURE_WRITE seal clears VM_MAYWRITE for a read-only mapping to disallow mprotect() from overriding the seal - an operation performed by seal_check_write(), invoked from shmem_mmap(), the f_op->mmap() hook used by shmem mappings. By extending this to F_SEAL_WRITE and critically - checking mapping_map_writable() to determine if we may map the memfd AFTER we invoke shmem_mmap() - the desired logic becomes possible. This is because mapping_map_writable() explicitly checks for VM_MAYWRITE, which we will have cleared. Commit 5de195060b2e ("mm: resolve faulty mmap_region() error path behaviour") unintentionally undid this logic by moving the mapping_map_writable() check before the shmem_mmap() hook is invoked, thereby regressing this change. We reinstate this functionality by moving the check out of shmem_mmap() and instead performing it in do_mmap() at the point at which VMA flags are being determined, which seems in any case to be a more appropriate place in which to make this determination. In order to achieve this we rework memfd seal logic to allow us access to this information using existing logic and eliminate the clearing of VM_MAYWRITE from seal_check_write() which we are performing in do_mmap() instead. Reported-by: Julian Orth Closes: https://lore.kernel.org/all/CAHijbEUMhvJTN9Xw1GmbM266FXXv=U7s4L_Jem5x3AaPZxrYpQ@mail.gmail.com/ Fixes: 5de195060b2e ("mm: resolve faulty mmap_region() error path behaviour") Signed-off-by: Lorenzo Stoakes --- include/linux/memfd.h | 14 +++++++++++ include/linux/mm.h | 58 +++++++++++++++++++++++++++++-------------- mm/memfd.c | 2 +- mm/mmap.c | 4 +++ 4 files changed, 59 insertions(+), 19 deletions(-) -- 2.47.0 diff --git a/include/linux/memfd.h b/include/linux/memfd.h index 3f2cf339ceaf..d437e3070850 100644 --- a/include/linux/memfd.h +++ b/include/linux/memfd.h @@ -7,6 +7,7 @@ #ifdef CONFIG_MEMFD_CREATE extern long memfd_fcntl(struct file *file, unsigned int cmd, unsigned int arg); struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx); +unsigned int *memfd_file_seals_ptr(struct file *file); #else static inline long memfd_fcntl(struct file *f, unsigned int c, unsigned int a) { @@ -16,6 +17,19 @@ static inline struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx) { return ERR_PTR(-EINVAL); } + +static inline unsigned int *memfd_file_seals_ptr(struct file *file) +{ + return NULL; +} #endif +/* Retrieve memfd seals associated with the file, if any. */ +static inline unsigned int memfd_file_seals(struct file *file) +{ + unsigned int *sealsp = memfd_file_seals_ptr(file); + + return sealsp ? *sealsp : 0; +} + #endif /* __LINUX_MEMFD_H */ diff --git a/include/linux/mm.h b/include/linux/mm.h index 2bbf73eb53e7..043689a56e8d 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -4090,6 +4090,37 @@ void mem_dump_obj(void *object); static inline void mem_dump_obj(void *object) {} #endif +static inline bool is_write_sealed(int seals) +{ + return seals & (F_SEAL_WRITE | F_SEAL_FUTURE_WRITE); +} + +/** + * is_readonly_sealed - Checks whether write-sealed but mapped read-only, + * in which case writes should be disallowing moving + * forwards. + * @seals: the seals to check + * @vm_flags: the VMA flags to check + * + * Returns whether readonly sealed, in which case writess should be disallowed + * going forward. + */ +static inline bool is_readonly_sealed(int seals, vm_flags_t vm_flags) +{ + /* + * Since an F_SEAL_[FUTURE_]WRITE sealed memfd can be mapped as + * MAP_SHARED and read-only, take care to not allow mprotect to + * revert protections on such mappings. Do this only for shared + * mappings. For private mappings, don't need to mask + * VM_MAYWRITE as we still want them to be COW-writable. + */ + if (is_write_sealed(seals) && + ((vm_flags & (VM_SHARED | VM_WRITE)) == VM_SHARED)) + return true; + + return false; +} + /** * seal_check_write - Check for F_SEAL_WRITE or F_SEAL_FUTURE_WRITE flags and * handle them. @@ -4101,24 +4132,15 @@ static inline void mem_dump_obj(void *object) {} */ static inline int seal_check_write(int seals, struct vm_area_struct *vma) { - if (seals & (F_SEAL_WRITE | F_SEAL_FUTURE_WRITE)) { - /* - * New PROT_WRITE and MAP_SHARED mmaps are not allowed when - * write seals are active. - */ - if ((vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_WRITE)) - return -EPERM; - - /* - * Since an F_SEAL_[FUTURE_]WRITE sealed memfd can be mapped as - * MAP_SHARED and read-only, take care to not allow mprotect to - * revert protections on such mappings. Do this only for shared - * mappings. For private mappings, don't need to mask - * VM_MAYWRITE as we still want them to be COW-writable. - */ - if (vma->vm_flags & VM_SHARED) - vm_flags_clear(vma, VM_MAYWRITE); - } + if (!is_write_sealed(seals)) + return 0; + + /* + * New PROT_WRITE and MAP_SHARED mmaps are not allowed when + * write seals are active. + */ + if ((vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_WRITE)) + return -EPERM; return 0; } diff --git a/mm/memfd.c b/mm/memfd.c index c17c3ea701a1..35a370d75c9a 100644 --- a/mm/memfd.c +++ b/mm/memfd.c @@ -170,7 +170,7 @@ static int memfd_wait_for_pins(struct address_space *mapping) return error; } -static unsigned int *memfd_file_seals_ptr(struct file *file) +unsigned int *memfd_file_seals_ptr(struct file *file) { if (shmem_file(file)) return &SHMEM_I(file_inode(file))->seals; diff --git a/mm/mmap.c b/mm/mmap.c index 386429f7db5a..b1b2a24ef82e 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include @@ -368,6 +369,7 @@ unsigned long do_mmap(struct file *file, unsigned long addr, if (file) { struct inode *inode = file_inode(file); + unsigned int seals = memfd_file_seals(file); unsigned long flags_mask; if (!file_mmap_ok(file, inode, pgoff, len)) @@ -408,6 +410,8 @@ unsigned long do_mmap(struct file *file, unsigned long addr, vm_flags |= VM_SHARED | VM_MAYSHARE; if (!(file->f_mode & FMODE_WRITE)) vm_flags &= ~(VM_MAYWRITE | VM_SHARED); + else if (is_readonly_sealed(seals, vm_flags)) + vm_flags &= ~VM_MAYWRITE; fallthrough; case MAP_PRIVATE: if (!(file->f_mode & FMODE_READ))