From patchwork Tue Oct 29 13:03:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13854904 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 18A5DD2AB3B for ; Tue, 29 Oct 2024 13:04:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 936AF6B0095; Tue, 29 Oct 2024 09:04:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8BDAE6B0098; Tue, 29 Oct 2024 09:04:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 675706B0099; Tue, 29 Oct 2024 09:04:13 -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 369DA6B0095 for ; Tue, 29 Oct 2024 09:04:13 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id AFEF11610CD for ; Tue, 29 Oct 2024 13:04:12 +0000 (UTC) X-FDA: 82726657356.15.8C19C63 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf09.hostedemail.com (Postfix) with ESMTP id 2E9E614002A for ; Tue, 29 Oct 2024 13:03:52 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=ArTrI5Bf; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="TQY/ttr0"; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf09.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1730206932; a=rsa-sha256; cv=pass; b=c0bwke4+CLT1k9s4xfLQhU/M0RZsqWHZbrSkmrzGRuglI/btZjX6GJz1AY6Z5KM+lz0SeF oOytGCvmG/issY/AIkrz0l93Lgjpecy6AAX74msjhbQC0aWbw0D35aU83oYHm11qDX/e81 qrin6vFnzeJpNQLwJ4LIjJ87vj2f8UQ= ARC-Authentication-Results: i=2; imf09.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=ArTrI5Bf; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="TQY/ttr0"; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf09.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730206932; 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=woqMSvLgvosQjv/MfE1WcUuMqxJfVahDJ68XrgLxxKs=; b=RVeEpbyRVqs9Y8SpQUI/WkatIxFL2WnLhsvvl7ZvBxxXrGiiLtslfRYO/bb6p+XpPVFGS4 9btXaT4bfHWzxRaTO4Jc8CeSdsfTAguhJ3osNVAUiySij0bA6COk/jeUXPxtZ9hdSEo+f5 qnicK491QA43zs3oKpZo7aJTGoM5J8s= Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49TCbnQ9032685; Tue, 29 Oct 2024 13:04:00 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=woqMSvLgvosQjv/MfE1WcUuMqxJfVahDJ68XrgLxxKs=; b= ArTrI5Bf0SL08WgySgAjo7fSpv38lWhGzMcKKiW5MJoqtTnoeHuth4yCPz6M10FP wsD9gUMpQCfpdFfcVte3cbCAx0vg8L7EuoGE43qUEywojSLGcpjkUFdLFHn4C0nC 2sReKQhNz31w0qjMXUdR05vJwWJO+PDF/MJodxBBQk/VYBRKrZ0ePtG8jmKSdkYN Ez6AihStXyZFFaDeSoSnMReGN/lHrz3oItxufLBtV74XdWyJ7mlbcd59vPCh045z GIGijIiHPnkcqRqS4oxVHzn2BGJWJB2MB/icEczFtyD5cNW7+DQ8/PJFnnWcyPl3 BgdViKTAPBykpuFyymQj3A== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42grdp5bv5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Oct 2024 13:04:00 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49TCAu0K004804; Tue, 29 Oct 2024 13:03:59 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2047.outbound.protection.outlook.com [104.47.58.47]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 42jb2u7h84-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Oct 2024 13:03:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Z7H+2CwbDQxvFJVO43YNW6We5yUxQj+6ch/tHACeGT95U9oHR/mw/PYhgClh19lY3WTbdXEx6icDZkYWVTqgOTQbTANsn0NWp4C9mD2TlpHN4L/A8u0CJE90W6pUWZ22lLEhaL1Z5LlJzk1F3e0yViy2X00EZeR9G6T1Q69EOaRqOSJdlXcwNhasB7FyVzIGDU4rTu4LEnMQMv4sRUL0DeyGv6dBf8sSQb+dWW0gJP8GKnIu1j+dp3T1qMwftt06J6Txar1Z+g8CWAhtbwM5QV2EmEQ6cYmeKY66gWhQXr7UiqPVWPjMHfCh22S1agx7t0qtCbJ1CbdhCNx4v4sS5w== 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=woqMSvLgvosQjv/MfE1WcUuMqxJfVahDJ68XrgLxxKs=; b=bl+SdfQtTn1a5wAZSCKL2JWXcdci0cK94FiEio6QN9Sir9gCyobrBiNt42H1HbF0HZjOQUEUM8E50H14CuVlGxlEmofhyqQoXGeeP/W9dmi/WhTAZbiphFMnOjppejrX0MWTha4LugRTV20bNOFwcUd2Gu5wqS+AR5/nI/Nnlq6v3j/mVp8XEe3atziiZqd/dWgrvLycLkngYUhhEVzrf5nS3nYUmC2G42116PC3/xHmFUhfiXbCtN6x3XXDYONl9/E71OetAjuLkEFMBfKBahFVEjx6nsls/WLAkc+++Pw8SN0iQ9HyX87Ygp2kJ1hcvabCxkwLhnV05GyD6Vj+Bg== 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=woqMSvLgvosQjv/MfE1WcUuMqxJfVahDJ68XrgLxxKs=; b=TQY/ttr0f7FYpDCi1QVbEAY72m+BX11ToRO3oYe86M0Yv5rPdSET4LKOZef7F4SznjlvWy0zL2GCQKvjOXA+PgXBSPrnbxDlQCOyzBg73JvzOB0/k/Haqmu/QCuddt7gwAJSyS8ETwOAgV/W5lhSf9epBm0L1kYJ4kbdClbl7vU= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by MW4PR10MB6462.namprd10.prod.outlook.com (2603:10b6:303:213::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.20; Tue, 29 Oct 2024 13:03:55 +0000 Received: from BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9]) by BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9%6]) with mapi id 15.20.8093.027; Tue, 29 Oct 2024 13:03:55 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Jann Horn , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Linus Torvalds , Peter Xu , Catalin Marinas , Will Deacon , Mark Brown , "David S . Miller" , Andreas Larsson Subject: [PATCH hotfix 6.12 v3 1/5] mm: avoid unsafe VMA hook invocation when error arises on mmap hook Date: Tue, 29 Oct 2024 13:03:43 +0000 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO4P265CA0166.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:312::10) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|MW4PR10MB6462:EE_ X-MS-Office365-Filtering-Correlation-Id: 36e9252e-7b2e-4377-f5e5-08dcf81a24ce X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|366016|1800799024; X-Microsoft-Antispam-Message-Info: uMGz/i0Ow4UUcYw0W/p8yd/06XlLfcXSHD/jNA+WB5nJikKOAucZ5Ni+SXx76W2N2hkvDnlhA1BmD6flyW9a0Hc3uLnh3fZGb+M6mIlTzwPbh3JQqqNvQZwGYMP675WLGvfauDakUvueEyfzhG+AzVnfhRWMacpXjjqqPDMQHgrnHpNOJilA42k70jryJI477tdbdjpdrVBfWLnDfdSyes3FhawxQFkx7nk5fjEMYUYuxoHOCnZs7AU7PaiY85awELWyJgVJSJLKP+kNdZC/5zB9I69rZ2+JMP0uiYxhSZNRZkjg0fWJHbETqK97m3Sw8QRu0nWX3M7rzqbrRwf1Sh6N3ek8mhCfvhIzYfG7V48Qn5KgyGeUQWN8Y3YKUFvM6wkNztHKqZ3QZ/yh0AxxYJHNH9rfn/oBWK/gO6Q9rmlQ01Seuuv4NDA+iTWqyBtTdj8Zg6GNIcWHPNuA3K3OOBpEMGR04+0VOVfHG/9LDwzlo5gMLC0un+vqvbVkak2VBeEqWBnrhcdYraM4oELJ2425DK0RzNXJ7cgYZPfrYwgZoxy/qWSI8uFhc/qEmNdPo850hifDlpkjibqE5g0q3VQlIddJrGKNFFhtgoTwEkCaZOAkUFAkVxUi54r/pmgALm1UGPQHfcobQfTfSM1UFti2tFOXOUNqnEnr51Ial1MihnL6t45kGzZBxHUEli+CsyzEXBCg0LZ41vBMvcA/kSdNyh8rC17wjtk6PlxtSRIWvkl5Q5mVGYtZ/d5vCPWVHlUAa0oRhdsFNjtyjZ/pRCjW/uGZsBY4meijeyJJ5JTiQgCL2kEBsF0Qmkdg5ouzNFHf/noDZRCXNf7wvjlPnN0yCAMp7KWUsv7Ts4ugCnyu9UpJRd2IyVoPQHxMbicun3fvrMpZHN6/RqWhCf9H8VlfleZnD1zX0CMlJC00b6zm5wvYGenh3wJWFSAnEJ12pz73g7kCNVvw6kTCZQcY1hekHSv3E42YFm8TBXQS8qAEoX58gsu8fLRt9MhpTO9nw037lW9JeH5Bz+dNdt19MEY12CpWewZjpZvQHRSZi3eAwvtoH4xlCisVDNvA9ZAs1tAeUJOHbRmmsQglDIHLsE9Vps0MTye/BklaiGyJFl5fJMWJsVd5fZsO6YvfOA8Ax+Ch1V0XV5k7Znl09qKZn6vDwkwaO6sZ3Oz3KCijenU2fYqnUfmPEml3G/cqJHrEhemNNJtwpjhBiYlrgEfFdkrqMIG7nutuBP+01XJYjlRTinspLbp/a1CebNm0XafotQ/fkw9lho7Off1wXCS6AqscOdZ1MZts5UmSr6n2Zxqa2ff84b4qq+aNbdyZdWS9 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)(7416014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: WxScr30ir7K/gg7AH4fyz8tLkkBqcCzZXCpn9murSbGLwWICzzqCSf5MDtNy9OdAvcLKTpBscdx7K8t2MhR/86Y01rB6IisrKDv3DJ+mKAdWCGLbA8SQ0wKgoVc1DULcceX4cKTJfFnt8lc+N9KqcmBCcbpUX4++TRt9mGnvMm9DhT8kXU0OOzbfgUCiCm1EJD3jEZUQb4X4838ORHyIwcgFCueTK287WwRi4yGHKFXouXmDup1hJfeh0N0yAMNWIfNp2naeaKqd+Z+MiFa3+kUruECZf/px9nX31bZxIcAd2TremyLzXhsGMNopUsN+PzOJjQ5dGIPSQalQIcO1sisthsp47zKwv1tc3L09/q7vUNMToavinyuGbqFNNaevlks728UUTTIAjwO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tL+2rqSW/q5y8LHPcr604i0O3g8S89ngXN6I4RRMOD1/vQQXPNQSYGUNu0xWg9z0mPTZ6r9Tc7BawI3VKWnv/oiD7i1r0+pXzWx1VltudveewrLo7H5u73YbHJDIfPYXOf9UUnMtabMSWApgsA== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: IVAlPgSdRVV/OJ4kpYcHNg32beGu6u39g6mStJn9QpDd0LvZGnSUc2aeMAk3Qc2K6KmEIp3XtBfN/hdX8iiDs4WR7AqoEHF3/1Tkc1+TujZLmLh+kYV3bk3vCInNG+tuqk0RU6bgPmpL86XoUwLMIn2CoAXtPMThZk+FgTWMo370nfnA7WgDeU6pS1QoNVaodCb4ll8n4lpSSDps3QXqCs2HfaRMTPgJkEnJblcqO6fA5K3AIuMFoEpVLUIhq+83OJcwh5VVUxjxMGgF14cCzCyqxJhwRp02PhLvOErAVt4jBiqy19aoLSfAwrb/zbbxbSrsPYgllWRHcuZ17vwdnnDdE+lZVWvP0uJk6NCnuehi24SuYkMeQAY/APneTPAvSY//RZWD6K9bovM9V9NKK0QHqMiMkS4lIUn/a21J0ADQ7Q8vH3T06EvsZIJfdtNLXe3qpGqDAb5i6BC1qA/2o7ZmpROwQ/TC7Fkqidv2LoP8KjSiowvRGJ1mg/GVe6zWYxKhV48fnAEAFAxgKBI51WwP1NSIQ0A/yWsv8fVGnVoRa9ppBkIrT/23PIzNKI2/A7DdF0Z0HXvLEMxgAFDw0xovNwmYpRZs+jhCpT7/bpk= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 36e9252e-7b2e-4377-f5e5-08dcf81a24ce X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Oct 2024 13:03:55.2483 (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: FgjlS/vMHdnFdruKxq7ErFGozHmWCnXgspwr+iRcvhecCDdirs5Fswqjjb5a85yld1Iu5PGrf+elt20x/cBl9HuWALg8pS4xATSapGdqxNU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR10MB6462 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-29_08,2024-10-29_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=0 bulkscore=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410290099 X-Proofpoint-ORIG-GUID: G_plqKKvCc62mtWTYOYY4MaGLghCb19v X-Proofpoint-GUID: G_plqKKvCc62mtWTYOYY4MaGLghCb19v X-Rspamd-Queue-Id: 2E9E614002A X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: rwm31ij7yt1e6buhaagqzqp7pwikm57p X-HE-Tag: 1730207032-255480 X-HE-Meta: U2FsdGVkX1+7zOA5PQWdP9MMFjR9DxkIZcrIRMLdwI4Rcji4Ax1or6nHDk/Pn9X4bwBrMEpPxkRIGVicfC7zQ5J236vc0sApMYYmG8aiFrlVr/5xSv3GlUq/i9XZBbobNygCooX/XT3vzoqUV3unxyAhQRbYPhD75eeuU6fYO3iWwdOmcZkny9+JVzwFIUECv6t5I5UbvhlNNF5N5TN+uE7P+qUM7Sn9Xhp3mvMxvtAYSJGTJZNxE4G2qAZNAU3RcT2xycABBmQn0cWzSwMz6f94kjJaTM2CWgM7FdMhCcHaAJoQFJViof+fU6Ya7fqcdolNUoCKIBR9RtkCsH6fPhV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yayjTpJk1tF4+SWEVKm++Zpb2zrzywea7O3z6G6Jk46Z+4NdjLPCCCvlYSlElki6poY+u3cqeAenG0cG05MeNLvTD98cF1LTbLbtbN2qqFi9qLO/AbSqiyg== 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: After an attempted mmap() fails, we are no longer in a situation where we can safely interact with VMA hooks. This is currently not enforced, meaning that we need complicated handling to ensure we do not incorrectly call these hooks. We can avoid the whole issue by treating the VMA as suspect the moment that the file->f_ops->mmap() function reports an error by replacing whatever VMA operations were installed with a dummy empty set of VMA operations. We do so through a new helper function internal to mm - mmap_file() - which is both more logically named than the existing call_mmap() function and correctly isolates handling of the vm_op reassignment to mm. All the existing invocations of call_mmap() outside of mm are ultimately nested within the call_mmap() from mm, which we now replace. It is therefore safe to leave call_mmap() in place as a convenience function (and to avoid churn). The invokers are: ovl_file_operations -> mmap -> ovl_mmap() -> backing_file_mmap() coda_file_operations -> mmap -> coda_file_mmap() shm_file_operations -> shm_mmap() shm_file_operations_huge -> shm_mmap() dma_buf_fops -> dma_buf_mmap_internal -> i915_dmabuf_ops -> i915_gem_dmabuf_mmap() None of these callers interact with vm_ops or mappings in a problematic way on error, quickly exiting out. Reported-by: Jann Horn Fixes: deb0f6562884 ("mm/mmap: undo ->mmap() when arch_validate_flags() fails") Cc: stable Reviewed-by: Liam R. Howlett Reviewed-by: Vlastimil Babka Reviewed-by: Jann Horn Signed-off-by: Lorenzo Stoakes --- mm/internal.h | 27 +++++++++++++++++++++++++++ mm/mmap.c | 6 +++--- mm/nommu.c | 4 ++-- 3 files changed, 32 insertions(+), 5 deletions(-) -- 2.47.0 diff --git a/mm/internal.h b/mm/internal.h index 16c1f3cd599e..4eab2961e69c 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -108,6 +108,33 @@ static inline void *folio_raw_mapping(const struct folio *folio) return (void *)(mapping & ~PAGE_MAPPING_FLAGS); } +/* + * This is a file-backed mapping, and is about to be memory mapped - invoke its + * mmap hook and safely handle error conditions. On error, VMA hooks will be + * mutated. + * + * @file: File which backs the mapping. + * @vma: VMA which we are mapping. + * + * Returns: 0 if success, error otherwise. + */ +static inline int mmap_file(struct file *file, struct vm_area_struct *vma) +{ + int err = call_mmap(file, vma); + + if (likely(!err)) + return 0; + + /* + * OK, we tried to call the file hook for mmap(), but an error + * arose. The mapping is in an inconsistent state and we most not invoke + * any further hooks on it. + */ + vma->vm_ops = &vma_dummy_vm_ops; + + return err; +} + #ifdef CONFIG_MMU /* Flags for folio_pte_batch(). */ diff --git a/mm/mmap.c b/mm/mmap.c index 9841b41e3c76..6e3b25f7728f 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1422,7 +1422,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, /* * clear PTEs while the vma is still in the tree so that rmap * cannot race with the freeing later in the truncate scenario. - * This is also needed for call_mmap(), which is why vm_ops + * This is also needed for mmap_file(), which is why vm_ops * close function is called. */ vms_clean_up_area(&vms, &mas_detach); @@ -1447,7 +1447,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, if (file) { vma->vm_file = get_file(file); - error = call_mmap(file, vma); + error = mmap_file(file, vma); if (error) goto unmap_and_free_vma; @@ -1470,7 +1470,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vma_iter_config(&vmi, addr, end); /* - * If vm_flags changed after call_mmap(), we should try merge + * If vm_flags changed after mmap_file(), we should try merge * vma again as we may succeed this time. */ if (unlikely(vm_flags != vma->vm_flags && vmg.prev)) { diff --git a/mm/nommu.c b/mm/nommu.c index 385b0c15add8..f9ccc02458ec 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -885,7 +885,7 @@ static int do_mmap_shared_file(struct vm_area_struct *vma) { int ret; - ret = call_mmap(vma->vm_file, vma); + ret = mmap_file(vma->vm_file, vma); if (ret == 0) { vma->vm_region->vm_top = vma->vm_region->vm_end; return 0; @@ -918,7 +918,7 @@ static int do_mmap_private(struct vm_area_struct *vma, * happy. */ if (capabilities & NOMMU_MAP_DIRECT) { - ret = call_mmap(vma->vm_file, vma); + ret = mmap_file(vma->vm_file, vma); /* shouldn't return success if we're not sharing */ if (WARN_ON_ONCE(!is_nommu_shared_mapping(vma->vm_flags))) ret = -ENOSYS; From patchwork Tue Oct 29 13:03:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13854905 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 6A591D2AB3C for ; Tue, 29 Oct 2024 13:04:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E8F416B0099; Tue, 29 Oct 2024 09:04:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E14576B009A; Tue, 29 Oct 2024 09:04:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BF3E06B009B; Tue, 29 Oct 2024 09:04:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 9908A6B0099 for ; Tue, 29 Oct 2024 09:04:17 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 530B0413BB for ; Tue, 29 Oct 2024 13:04:17 +0000 (UTC) X-FDA: 82726657356.21.D82C2D4 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf11.hostedemail.com (Postfix) with ESMTP id B8FE740024 for ; Tue, 29 Oct 2024 13:03:43 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=l2YNyRrQ; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=l9+0LvLW; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf11.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") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730206879; 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=n/a5qI/qPIV7EvCPopGmVIpb6ZM0YGR4l7zVgmrebNE=; b=1+bZ9yidLMLBzUZ/l9VcismRb2xSO045EhMi3sSTIfgL6j8yi733rjzYObAureu7SOrVoc Yl0+/yEzDgrJ5S0AC6S18HFoxkYWKPPvbIaWrxFhmJfxO7xRLtC7CkWqY7TR+MzA7POqhS P7FAgX5G/PFEQRAtUwBlbPGdUixJN+o= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1730206879; a=rsa-sha256; cv=pass; b=JxeNse3fuwdn5Mx4uQn66m3k/CK7Qyeiu1paRXAkWe+WOAv5/lPemEtl70Ule4G88HavYU qu5B3ixh0WxW+tvAPofm15RucvfB0gkXsOmye98cbNjJRpMIEbYlDVnAB0Mz0SJxaFcV7d s17+bG1AUK7MV/FInUTWRkEn0L99X9g= ARC-Authentication-Results: i=2; imf11.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=l2YNyRrQ; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=l9+0LvLW; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf11.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") Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49TCbuXM031407; Tue, 29 Oct 2024 13:04:03 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=n/a5qI/qPIV7EvCPopGmVIpb6ZM0YGR4l7zVgmrebNE=; b= l2YNyRrQ6geGSqSvT5z5XQNX/k/OgVCfiYNhxJp+62l3G4fLuofs+WOT8pcwDF9d a2azkT5C4j6OSsxOy8cHNPDfwXQPsdjLdL0feq3KZp617gU+DDl9awBn/wFC5n08 owDL+UPyKwKRG3cfnp2siD+kclb9CY/3UjYWqidadasu/cegzmdPLBnzBTGL7JLb TYiJDKXGcb9sPrNUdsUPkwBeLRg6MRmcneYexT+UgCq2AEEAM5YixV0rfFNHuSYY o/kUqivola925JXAZQGaAviWaFo9doVr/k/McWadmYKjAdplefple5FAOPCfbpFc xosAHXjeilhO1enTmMd5fg== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42grgwdb40-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Oct 2024 13:04:02 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49TCcQkZ008475; Tue, 29 Oct 2024 13:04:01 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2048.outbound.protection.outlook.com [104.47.58.48]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 42hne9kred-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Oct 2024 13:04:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Yyn1MxPhITLQs2XVHoGH6b1jo+GDHvJR3Q+GOhBXJHf4okS10TYAo/iJv0fWwwxAqOsC04nGXdKM7teoV4uNGHpETR0RcxV+LHCjTS1HzV5UoZxSDM/FXKQMADEcTHz936sV4Zp7ncP85LCOn5OwCUVCcwKWN2l58E1P1xC01wN/VfGGdLH9GJHV5uUuEzgMS2tRHbwB59qnK+0CWNFjF8/4VWJJUUqQFWC4ubPz/mkWtJQGKIMAmncSSzDXvTvRg8lz+B6op0d4hls5QOV/YWCzqyA9IL5ZmWkKZDwDfhdknQthg6YLLAQ8Z3ddGn2HGBIZbe3PTxviVR3D3L329Q== 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=n/a5qI/qPIV7EvCPopGmVIpb6ZM0YGR4l7zVgmrebNE=; b=r5U1cZezebp6JTHToUEKBUtoHS4QeLK6DvM4n2kqvZCVvklQhfNRKVWUIXjlbqLqKZVmpe6LRQa3CxjWyUa3niLx06OUKH9fv7XPIwlc4mVr8/PUOvOCfioUma4IRXvMSLAMuSSYMT5zWOryyML0/9wvgMyc7CclskP5GbQyV3GKJrgvFI10G+qBCAASE/OrgL3rdyM3eXHoGzQjk2IqtEUislFsAISA2WfDP0zh+N1eSbn0WLTgIabKQnpPRnmL/o2EpRhixM0zHI5nEBapl/zAAfVfldedF+GVhlxgo4ssEwKNy2nM9PwrioH9mn5qpiHecp10/FFikHQhuD2GGQ== 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=n/a5qI/qPIV7EvCPopGmVIpb6ZM0YGR4l7zVgmrebNE=; b=l9+0LvLWV4569b5yPIn7de7ZHaxFj3iNHhwbOXXUmu7C5r6ki1N3I7Y6RPvyEITdL+bBJMD4hP0fXF8LayLay2OoX/wsSQjGlgIS+0neLQa9eeN0igAystgUXeOzfcKW/CiAmKdD9pjHIj1HX5mSSAigWVgigVPpDsMxEr+Zo7U= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by MW4PR10MB6462.namprd10.prod.outlook.com (2603:10b6:303:213::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.20; Tue, 29 Oct 2024 13:03:58 +0000 Received: from BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9]) by BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9%6]) with mapi id 15.20.8093.027; Tue, 29 Oct 2024 13:03:58 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Jann Horn , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Linus Torvalds , Peter Xu , Catalin Marinas , Will Deacon , Mark Brown , "David S . Miller" , Andreas Larsson Subject: [PATCH hotfix 6.12 v3 2/5] mm: unconditionally close VMAs on error Date: Tue, 29 Oct 2024 13:03:44 +0000 Message-ID: <28e89dda96f68c505cb6f8e9fc9b57c3e9f74b42.1730206735.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LNXP265CA0005.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:5e::17) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|MW4PR10MB6462:EE_ X-MS-Office365-Filtering-Correlation-Id: c8c1c1bb-66d5-4103-11a0-08dcf81a2687 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|366016|1800799024; X-Microsoft-Antispam-Message-Info: 2zxpNUp5DuOKUP4LkK244ER3Cg2cIg0cpDK6z9MvX5Ig55Qi7NzXH9wtJgTQTsO69I1tUyovGN9ofilv0BIxqnkovBt0lvEaBsF7ySi/njHKOgjkCQGS5yZLYhzcUK+qdMBI3Ke1vsFuO8hll4P7ZsUPobVnpXBSBRR3aja4GNMWAjPExPKgsi19EPXZauxkkT4eVScEabA6a5ltU1mpjWHVtgBmg+rJeR7EO75+O6AqyUrGuGZ3V3G0hnuJ2Bq3V08av4Buuuf5PYE+012/n7CMBR3ndLtOZGToZgI0K3TPyPlQ2ARquQMNnGlgjOPvQ7u1rx5VFe2gVkHLdhoFReuHYuBrZUFfm3V73Y7qYNtr8pVz7W4OhBaEjOhcEvoG9VvttOBbQtYUkagbtiiOGdItrT0b9/yx+ORHOMIqmXTgh8T+ZrG9aBK9dwHQU4YtJaEa106vXVB+DDHTioVQ7+Xzt7WA2gJ57gKSUZ0GvFJPtevQ/RFaQ85ThH/X7DZPg9H4kS9fkTQgKFKScWOPTa9uO5zvNu/yB5VXMnufJdVJ63R+u7+XfZiKxzILHrDX5ifqBclM+jEvdM5Qffa5yo90txg2pfg+0YX19ixMRUzzLCaQH+aP9Gw0ewQhw6YVKdAtBBMAj2DgHRNHqF4YDWzB5WUSetRM8uzJmhPcxyZlJ2uXiGUOcEFmUA9RTHG3YYUf6XMbmAUQ2YN4BBy1+iqYMo5WKdddR5JOX8vw/v7MasDZ/tqtwxUBLN55pQrPw5cWjGu+Xop8gXa6IoKXVLkaBHBcONwohF3djrTY4xG33r0+4NhiADTI1Urix6YDjbXLfCUnKsNiQuiQ5NR9pdrqHc89gHQfowHOsXbJ0NHbk7dsaB+7x79SeFQZGySU1C7pW7V4z0xtsp2KpLz25cgVbtgFCwrgaH68g+1Mq/Z9IUnoKVYLDh5lw7Gr38D6cYl3dSvvD9rCUQUyaOi+kwT7x0MDtjUbd/8m/6awktjqog66pBE8V7NoR+hZID1wRZCrGC6tdsYiCDeSDOOYCWPbda03zq7DoNhocLgfOi/VSFY6lR3FlMiVdIAexe+5ANXaoIh+eynEk8Mim6tE/xwrB8qfliRakb1yZ1C+A1AjO4SW7+HxyCmbjlysB2rM8SMhREjUpt29uhssXudESBl3rqG2S74hZD8SZWo91TT4anM+Pnl7MIDWjhP3SkVQ2Zlgau8ZZJJ8d+ozn9swZ9916hFmu85rmZQlgeYjkIIaqoZbVfSL1MR4O9b2pKilVXIk1Ybs5ixxCnyTDRJNSp5/stJgUiqzNsnT4DZK9syy52g1IbUpUPDBozB5Lw9t 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)(7416014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: RZaAIX/6ZgsHjG3Eb+KSiMjrcSPTPRf/PTadTOQt6l2xL2iaYhX5Vign4x0GfAek/oBa2RzHzrXpiWCk6y+wwFIHu/0ArM83bLCL3ICvV5QWXbS6jaE8eFIOA10BsgLHq4jc0fJyq/DQBtaZnTSYVNJwgzl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q7e+a7BZGCxtPWUc= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: c8c1c1bb-66d5-4103-11a0-08dcf81a2687 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Oct 2024 13:03:58.1513 (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: J1U5mx/vpwpEBh5EeqWH/wsRv9Nb7pfaoGxfwFGMKdSbIIlONL8gDsygE3v5hc8IdJ/I0t4qGdOeJ3hmoslj2jkYQlmMVCVhdRkIrDhjXQI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR10MB6462 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-29_08,2024-10-29_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 bulkscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410290099 X-Proofpoint-ORIG-GUID: _qoJqAsXEoa8eX8u-nxYpx_b2WVe98-m X-Proofpoint-GUID: _qoJqAsXEoa8eX8u-nxYpx_b2WVe98-m X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: B8FE740024 X-Stat-Signature: c59qi97snkcat9ejcw9sfs6t6cda5qna X-Rspam-User: X-HE-Tag: 1730207023-373217 X-HE-Meta: U2FsdGVkX188LvvYSFcur4BtiQHf6nfhLjoMEky/7n2HDF4/Hq9T97gjquttf14gidfy1ONpzahKoKi/LQXWyBuFr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VX391CG7WThP8/1PZwpQPBfqoK48B+j8exmWbuxIUhvGEKit19VVYKJED96iJ1qzpt6Fr89OSHsMU/s3Im217EnbNmnj0kr49iyLD71mg+QaWO8n+o/U+T76DLa4IxYKF901qEYw4i2GPjd1wAG7ZU3KM4jraFM13QEt3FHzlaKtpNXNZzfSoGdeSbT8dsj57Tz11TeYG4jtEETM+BlINk8FMytMO2ciwHGxQZUAdedGjS8IxNKckno6Pe47xnBHNiwiOWvvxdQg7TwGAsjHZ7vTfbb0H6Yo23JNCiJMVxn2ZeNLYYl1zqVIOvEWnAeIAz0Q8Ea3k7+zDzg2W6M/+6zBKnlvNo+YINAhXdKnNVmfc+xrDwgOUs2JmitHmgp 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: Incorrect invocation of VMA callbacks when the VMA is no longer in a consistent state is bug prone and risky to perform. With regards to the important vm_ops->close() callback We have gone to great lengths to try to track whether or not we ought to close VMAs. Rather than doing so and risking making a mistake somewhere, instead unconditionally close and reset vma->vm_ops to an empty dummy operations set with a NULL .close operator. We introduce a new function to do so - vma_close() - and simplify existing vms logic which tracked whether we needed to close or not. This simplifies the logic, avoids incorrect double-calling of the .close() callback and allows us to update error paths to simply call vma_close() unconditionally - making VMA closure idempotent. Reported-by: Jann Horn Fixes: deb0f6562884 ("mm/mmap: undo ->mmap() when arch_validate_flags() fails") Cc: stable Reviewed-by: Vlastimil Babka Reviewed-by: Liam R. Howlett Reviewed-by: Jann Horn Signed-off-by: Lorenzo Stoakes --- mm/internal.h | 18 ++++++++++++++++++ mm/mmap.c | 5 ++--- mm/nommu.c | 3 +-- mm/vma.c | 14 +++++--------- mm/vma.h | 4 +--- 5 files changed, 27 insertions(+), 17 deletions(-) -- 2.47.0 diff --git a/mm/internal.h b/mm/internal.h index 4eab2961e69c..64c2eb0b160e 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -135,6 +135,24 @@ static inline int mmap_file(struct file *file, struct vm_area_struct *vma) return err; } +/* + * If the VMA has a close hook then close it, and since closing it might leave + * it in an inconsistent state which makes the use of any hooks suspect, clear + * them down by installing dummy empty hooks. + */ +static inline void vma_close(struct vm_area_struct *vma) +{ + if (vma->vm_ops && vma->vm_ops->close) { + vma->vm_ops->close(vma); + + /* + * The mapping is in an inconsistent state, and no further hooks + * may be invoked upon it. + */ + vma->vm_ops = &vma_dummy_vm_ops; + } +} + #ifdef CONFIG_MMU /* Flags for folio_pte_batch(). */ diff --git a/mm/mmap.c b/mm/mmap.c index 6e3b25f7728f..ac0604f146f6 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1573,8 +1573,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, return addr; close_and_free_vma: - if (file && !vms.closed_vm_ops && vma->vm_ops && vma->vm_ops->close) - vma->vm_ops->close(vma); + vma_close(vma); if (file || vma->vm_file) { unmap_and_free_vma: @@ -1934,7 +1933,7 @@ void exit_mmap(struct mm_struct *mm) do { if (vma->vm_flags & VM_ACCOUNT) nr_accounted += vma_pages(vma); - remove_vma(vma, /* unreachable = */ true, /* closed = */ false); + remove_vma(vma, /* unreachable = */ true); count++; cond_resched(); vma = vma_next(&vmi); diff --git a/mm/nommu.c b/mm/nommu.c index f9ccc02458ec..635d028d647b 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -589,8 +589,7 @@ static int delete_vma_from_mm(struct vm_area_struct *vma) */ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma) { - if (vma->vm_ops && vma->vm_ops->close) - vma->vm_ops->close(vma); + vma_close(vma); if (vma->vm_file) fput(vma->vm_file); put_nommu_region(vma->vm_region); diff --git a/mm/vma.c b/mm/vma.c index b21ffec33f8e..7621384d64cf 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -323,11 +323,10 @@ static bool can_vma_merge_right(struct vma_merge_struct *vmg, /* * Close a vm structure and free it. */ -void remove_vma(struct vm_area_struct *vma, bool unreachable, bool closed) +void remove_vma(struct vm_area_struct *vma, bool unreachable) { might_sleep(); - if (!closed && vma->vm_ops && vma->vm_ops->close) - vma->vm_ops->close(vma); + vma_close(vma); if (vma->vm_file) fput(vma->vm_file); mpol_put(vma_policy(vma)); @@ -1115,9 +1114,7 @@ void vms_clean_up_area(struct vma_munmap_struct *vms, vms_clear_ptes(vms, mas_detach, true); mas_set(mas_detach, 0); mas_for_each(mas_detach, vma, ULONG_MAX) - if (vma->vm_ops && vma->vm_ops->close) - vma->vm_ops->close(vma); - vms->closed_vm_ops = true; + vma_close(vma); } /* @@ -1160,7 +1157,7 @@ void vms_complete_munmap_vmas(struct vma_munmap_struct *vms, /* Remove and clean up vmas */ mas_set(mas_detach, 0); mas_for_each(mas_detach, vma, ULONG_MAX) - remove_vma(vma, /* = */ false, vms->closed_vm_ops); + remove_vma(vma, /* unreachable = */ false); vm_unacct_memory(vms->nr_accounted); validate_mm(mm); @@ -1684,8 +1681,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, return new_vma; out_vma_link: - if (new_vma->vm_ops && new_vma->vm_ops->close) - new_vma->vm_ops->close(new_vma); + vma_close(new_vma); if (new_vma->vm_file) fput(new_vma->vm_file); diff --git a/mm/vma.h b/mm/vma.h index 55457cb68200..75558b5e9c8c 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -42,7 +42,6 @@ struct vma_munmap_struct { int vma_count; /* Number of vmas that will be removed */ bool unlock; /* Unlock after the munmap */ bool clear_ptes; /* If there are outstanding PTE to be cleared */ - bool closed_vm_ops; /* call_mmap() was encountered, so vmas may be closed */ /* 1 byte hole */ unsigned long nr_pages; /* Number of pages being removed */ unsigned long locked_vm; /* Number of locked pages */ @@ -198,7 +197,6 @@ static inline void init_vma_munmap(struct vma_munmap_struct *vms, vms->unmap_start = FIRST_USER_ADDRESS; vms->unmap_end = USER_PGTABLES_CEILING; vms->clear_ptes = false; - vms->closed_vm_ops = false; } #endif @@ -269,7 +267,7 @@ int do_vmi_munmap(struct vma_iterator *vmi, struct mm_struct *mm, unsigned long start, size_t len, struct list_head *uf, bool unlock); -void remove_vma(struct vm_area_struct *vma, bool unreachable, bool closed); +void remove_vma(struct vm_area_struct *vma, bool unreachable); void unmap_region(struct ma_state *mas, struct vm_area_struct *vma, struct vm_area_struct *prev, struct vm_area_struct *next); From patchwork Tue Oct 29 13:03:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13854906 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 4A89ED2AB3C for ; Tue, 29 Oct 2024 13:04:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C6A216B009C; Tue, 29 Oct 2024 09:04:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BF2986B009D; Tue, 29 Oct 2024 09:04:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9829E6B009E; Tue, 29 Oct 2024 09:04:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 7027B6B009C for ; Tue, 29 Oct 2024 09:04:24 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 3BEA3413C6 for ; Tue, 29 Oct 2024 13:04:24 +0000 (UTC) X-FDA: 82726657104.09.07E9684 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf06.hostedemail.com (Postfix) with ESMTP id 5B339180014 for ; Tue, 29 Oct 2024 13:04:03 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=hGR7SbAY; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=VVw65DYo; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf06.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1730207006; a=rsa-sha256; cv=pass; b=TR0z0/4BVe0MsZxRSUef3rIoI9awvN2Rwu5MXSip6RD2EiTIqaDEBYFe4DOalLlPrLv7rH /neUHas79zMSfwmi6tJGQFgPwa9PNdYjU5NXd5xBZW3tl2qy7nADY6CN2i8K5LO+XzxmeC fLTDEacU4RP/7C5+2r3INk2t74BkRFo= ARC-Authentication-Results: i=2; imf06.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=hGR7SbAY; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=VVw65DYo; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf06.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730207006; 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=gD3/8yFb/Fj1edTJvrvVzYBFOVmebuxOTpOZBoSXr+c=; b=NvvqQ6YZJF6ZkQf5mnvdcT/OmF48rbM3CarzpEKz0WNAJ/4rla5aJtpzFIqspoReBwKStg qp5QD8O2mrI0ogr0ohRqwRdXwf0j0piQ8szWQBs6MFzmeC9LwLUamARwpm+PySEpM1f55c 6+1Qa/KwfoS8dsDQWIC9eMXWIOT03Fk= Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49TCcKNT008981; Tue, 29 Oct 2024 13:04:09 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=gD3/8yFb/Fj1edTJvrvVzYBFOVmebuxOTpOZBoSXr+c=; b= hGR7SbAYMxDh3M1qX8U0svAyjQcJZGsHZ+MjJqEkMjvoCw/ANiRT/icHDWZSzFiH Agla3FNwV8oA3T3wENHXm/HqE/l1py8mMEq1HBXq3mNGhjx0uffWFVvxJgKrNuom +2vPnvio9MK9UybP4J+oJhMEbl2GFBuDSCLIkqfCGel+O1mQK9SeoIFuV68NbNEU irdzJkWgwgrjVzncZxUMQ9OrWMHRRmo/6bDw7u8Y2WHrkUU0DMUwlk62LRMP2neU LaOLifB2HkkINRoXJAHK5g6fQEPwQWYzkV+L8uP7g3kUBl63YC0xXSNCLK2z8f2R 1mZHXBXUZgCcoThNTIstJw== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42grdqdaq1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Oct 2024 13:04:06 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49TBxCZ4004774; Tue, 29 Oct 2024 13:04:05 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2042.outbound.protection.outlook.com [104.47.55.42]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 42jb2u7hde-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Oct 2024 13:04:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=VxOlTkGcF2Ms4OMTUeszaHUeUWyf/Zf21hfQo8iV+UhXQGGSBepkW0o6Vu8vNPwp5jbNeLalOMlQX0o5ZlZ9qJYZL4TzzSi6+m+n1K7UhXhSrWv8QVchCD69KSOKhRHDCkY5BUeIAHhKZ9lNR5a59J6+eqOVV7gUqFWaA1AZEPpqkEOrxqJiYa9H8C+yGbFS3/YJlIN03FbX0EJkppe9xNsSLFpaRzvWSrtMvPf1wUtW97m5KdD2cbUBgplhfeAN03CNyraZoXfCT8gtK89/PNOrT0PxlwKIt602sGOQ0tn+F4qzut263eJcAGRSyNe5x7NI2eraDbK1aviY0rix2g== 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=gD3/8yFb/Fj1edTJvrvVzYBFOVmebuxOTpOZBoSXr+c=; b=EQ3+RfQMDhompRNegaLk7cqmNCEIIg44uEhMTtd6FkiZV/EZ398wfdmtIwxXGNIE6o7idD0uE9fHH9n8Nzws38jb8bRGke69e/SSZCZ2zTShPEY1/3+3JFWNoXYwBPVNaWa5bHj4UdnRQ9DSTVJBJr4F03T3FpF2hGaxYu+F0vxkPEvPrS2i6KVvYo+UviM+Hs67qRGikuqCs0fkCNrMeIzAyNPdhvTUIXDrJjdxPVWWVp1F509sq7BhbxKjz121buq9F/MdbpW2TTmqb91lGHaGVbvFEPApCxx3ZVSGjGKaDXmDqINmRQiyXmWSYE5VbmRIZ6PssQgvtKCGf0xj7A== 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=gD3/8yFb/Fj1edTJvrvVzYBFOVmebuxOTpOZBoSXr+c=; b=VVw65DYoS6d8BRf6hvMiVktTZRrY2ROZE94t6TrvU+mFGMeAP04cF7+mv7uJ7AQXonZQ0NPVZLa38zvIvjV1G9Rj2we3n4Mb+O07Cje/LHQI07kwIg/Rh4LXEjHf6It+7X0HmJ5gVn5PAmufI4Ve36hsAgHDypytybsoUVzWlwA= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by MW4PR10MB6462.namprd10.prod.outlook.com (2603:10b6:303:213::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.20; Tue, 29 Oct 2024 13:04:02 +0000 Received: from BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9]) by BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9%6]) with mapi id 15.20.8093.027; Tue, 29 Oct 2024 13:04:02 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Jann Horn , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Linus Torvalds , Peter Xu , Catalin Marinas , Will Deacon , Mark Brown , "David S . Miller" , Andreas Larsson Subject: [PATCH hotfix 6.12 v3 3/5] mm: refactor map_deny_write_exec() Date: Tue, 29 Oct 2024 13:03:45 +0000 Message-ID: <6be8bb59cd7c68006ebb006eb9d8dc27104b1f70.1730206735.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO3P123CA0025.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:388::14) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|MW4PR10MB6462:EE_ X-MS-Office365-Filtering-Correlation-Id: 49309bcf-0982-427e-5db4-08dcf81a2919 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|366016|1800799024; X-Microsoft-Antispam-Message-Info: jP0e3JiIKN8e4TNSqJFA4A2PrXtfeBNV+mucPYORZMpaTdoSZKJODBxSc6EDREZSkOQOus64Xvz3Q043L1KY3kWEzgdq9qdeEkW/zutJLlruXMAWdR6XRuJhNSVlSGE4W+zk05dqJCamPfxZoGfRPb0h+nL6z8WnC8OpV/oKYiYMt9JryF89V64TtK0GyyYPecJGl07MeFa64BroA9OV05yb0E6HelzhOtvLt5G1/VQ4fyZurqP+oqtu1PdmT8hKppp3WKMnfw298CtH4ucVhl2/BNOqCc9L26CCEdBbamD5OaQFDrkaQ0m+vubuXaUFA6oFz0av4VD+iABxmgw7tRHxZgJ65PWwXYZkSROLZAw0X2kvm7RmDUel2rA9AE1GisEIdqTU4SIrW21TIzeowNQr97Ez4v1mFy3V8GWTwSmaVOpYpkT/1I6VDs7sm8Bp6uMEhEkumYmvY+awuXWv4meVZS+F19NLNSt7EGntBKKTX4cwe8RzmMUyY0ZMGAuiiFoQDa1mUJd6ySL4a3mWIbXpn7+mCUyVlS5Tk0rwA6GU9/+G4/yVVObpAMIut9TzK4d/X0GFdBAh5Cr1vFU437S2vo9uFw6UWBXEVRMMibc1x7+j2kbOhI/qPozxIdjro2rn56OM2p2USA/F5HT/p1eMqazqPIhDseL8D7vnu8pcq/gUG18EnVpdKNbHmCVZO9sT06Jr4OQSV4NNMwoWFn3BzxO4wb99FG2OJD1NepGPuZOkar2MOk/wFmLsCdmMVTjGNgPGB57Iu4JQUlbephcPBVSn+WkmRItOhmkez3tPvTOm+OBOIiJHyqYgXRagZ5uPFjxtl0p5zyXSIQ0Th1uT1sdoP4ywMbisp0prA/3dC4szvKMJwu/PlONUVxhVF1N23RzQ/TvqY3hIuevjOCt3WkSDtfJz6285g2YMN/JSUp3Ac10gGoCjw+CzBdD3G/2bCJkR8Zs108PDlyPY3xuVB8d8sjwCjMS7MavLqkfdf54Zl+96mUSTvsq7YwJX4xfV3QMVw3GpzYkRaIg6bAJ4ruMVgfZg3WuaXSnA1luUAGn+/45ZEhFFfzEt3piZXFX2Gb/D/Twmv50wnYNl6+wuwIG+P41M8F1LeUiEqnI9o1jHkcv7PT7mieKNH88N4Vw6NF4RU/Yi0ZxBCihD10PTBWo4fnIx9NGoHD82ON0CAAdAJqGtOIM63M23dWbVY4fp2tbhaOR9XbleJuIMaa7RVJcUq1AJfmyqkZQrR3f8kkBMg8d3BsxuP5GZL7z1Ah5ST4ehwQH0TJiSkOUqg3xcKV7DBmrpI0Z/b4StKl25KSCCsF4zmSbHpHIbiZFd 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)(7416014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: FkY67PY9bnXC48FxNtWU+HmvhkTSmC1WtVoSxukFTFc/rVRbJNL+Q6xHzZh4WplpSHhiy5vApt3ihslfl+b9+ZaS7dzSGdfx73TZBWRExSJSHMqWlVdtZ09VxnlVCSwjz9M/udQB7En6fe4Y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pfT0zdwKarJCc023wNFrSxpIqfWvAiZGJq41ssXuZgmn9AIXpPMK/1zqpXEP9fIDdwx1XPOuAspVxe2AQA46/Jwg7utH5b4H8AbaCvhvg7BAOGGJw1qlnDmE6WAcdf9Cyh+s+vXoo6vqvOUDQ3kt7552guxmk6YVlGowH1raO5xZQddtpRB2V+3hILQ1haWcE+kwibIfM935RsFKb6xRNNbkJpLe779G3J7Q4n717CJAF/bKC0kk2BY7+tHpLSUVVxlHNwSbtizMsAapOZjy6lSmUGIVFrLBvkvH7WZIGte866jUvWbPEtMfof3x7drj+QMW3EF16usPGVpiwDArRJFOiTwtD5O0yHoYRX28f/avVf9eV/Rq78z/+tgHt1LceKn1ihVjnuvw== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: YuRQhsa/yW+7s57V5zbDyoUmsbnSwgtiJyjjSoeCKhkkbEqDzNu3v+4Z0FmJGEanA/yP+cEohcT/I2t2vw00s/FTNxpFM46Tv1L7Zddio8vJoy/8JHRC9xvZnRxOBctMcu0zQskZGf28gC7kadS6Itp5+zIxiWvJZCWU1OslfZ3SXe1m4g9VG/cp7ssVlJIeQt3UfXPzO56QOk59RfDqXbp7rmT2iseqyNNauCtYYZ1WP+0sDAz6DoX5qcoT9U2gdtacEwyovNEPwroHX7nBu3RYihVdqb/KKOGO+CWQ3+g2OPGGAKYXFLRMuKMrvDO8sHG7ydcIwjp4wZdXii/kchgVc40eDmEMlhoErGG7u05Uuvc/JWtru9tal2tWcBu7k158sxc0q4BfS+ahcn+k60qejz97orbFTlmbHa0rHn/KTYIoWa7Io6Z04MbNTiYUriWBOgbeMJ5MFDV5W3tYQeuMBHFA0gjZXjwbzQ8v9Siy4gpOZgBl+cr+7l75WLkNvIGKBxB3XUBDIxj09xBlQz212/1ckWVAJ+8PUSngXWgzGhDtAzVR2Nx4yC3hS18UNTeFM+cCyojDycqx66iyuKuHhGGSLZrimG5fLmvWoks= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 49309bcf-0982-427e-5db4-08dcf81a2919 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Oct 2024 13:04:02.5785 (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: 7Cr3qM2Xn03MM0wYqvQUbecOnPgxjS3APONPHefzKsx7NwdxqHN6ES0obWYn9elAlLqOSoBw4P8jGN/5cHjcxb90FKEbN2q+DmjkhaUknrI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR10MB6462 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-29_08,2024-10-29_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=0 bulkscore=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410290099 X-Proofpoint-GUID: yd--8GXVUFi8pe2mdqE4u1G8Y1cWvKSC X-Proofpoint-ORIG-GUID: yd--8GXVUFi8pe2mdqE4u1G8Y1cWvKSC X-Rspam-User: X-Rspamd-Queue-Id: 5B339180014 X-Rspamd-Server: rspam01 X-Stat-Signature: gmm5pokmmce9s64s88yc979rfpyqu3sr X-HE-Tag: 1730207043-289657 X-HE-Meta: U2FsdGVkX19NolUnK6bvsGLft8lJ3ZNLqwdRnT+YnPn9tDbmSfdL8YzmyZ5uYQCKrdh1ERszZnB0grUE8twhBV1HSTzRdPmWO8X4zaHvFHL9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+37dUlgMWJNttuOmQSgQ/0JVfjclRN+T9z2atQcL0vx98kNcyN8htclnC49TkIPXSD4gJ9c5/tEqiyOFFYnto57B78Bco3XVUgc199EencyehXHzQw0LmtdcvsqR6LIwZEwX6nVg4LRKjRdl1JpA1SlZnBxKYu7Zb5ED5weCfKfPvkrnjatHOho1gOY8exVUG0SaNNVyyqx1cn4sjObfveWvAMx+wmbjRJMNM/u5Q8pGqMUwgOC/xQXAyk4Ung8bhZH4O3QiKZkG2RlK3IueaShbS1w862eQcxIEMTsjelg3q9RR2OakILwpWbiisRbjr5h/b+47/YvRV/1Y3SG8p4eU5PZO2woKx/Zjw9f3w+Ru1+nY5Tbqb+vm9S/bQoUwAH5kzqcgwEe4G4/z1XpSVsot6NhDaWK0zF4iL2EFDBmxoKt375oO5Y= 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: Refactor the map_deny_write_exec() to not unnecessarily require a VMA parameter but rather to accept VMA flags parameters, which allows us to use this function early in mmap_region() in a subsequent commit. While we're here, we refactor the function to be more readable and add some additional documentation. Reported-by: Jann Horn Fixes: deb0f6562884 ("mm/mmap: undo ->mmap() when arch_validate_flags() fails") Cc: stable Reviewed-by: Liam R. Howlett Reviewed-by: Vlastimil Babka Reviewed-by: Jann Horn Signed-off-by: Lorenzo Stoakes --- include/linux/mman.h | 21 ++++++++++++++++++--- mm/mmap.c | 2 +- mm/mprotect.c | 2 +- mm/vma.h | 2 +- 4 files changed, 21 insertions(+), 6 deletions(-) -- 2.47.0 diff --git a/include/linux/mman.h b/include/linux/mman.h index bcb201ab7a41..8ddca62d6460 100644 --- a/include/linux/mman.h +++ b/include/linux/mman.h @@ -188,16 +188,31 @@ static inline bool arch_memory_deny_write_exec_supported(void) * * d) mmap(PROT_READ | PROT_EXEC) * mmap(PROT_READ | PROT_EXEC | PROT_BTI) + * + * This is only applicable if the user has set the Memory-Deny-Write-Execute + * (MDWE) protection mask for the current process. + * + * @old specifies the VMA flags the VMA originally possessed, and @new the ones + * we propose to set. + * + * Return: false if proposed change is OK, true if not ok and should be denied. */ -static inline bool map_deny_write_exec(struct vm_area_struct *vma, unsigned long vm_flags) +static inline bool map_deny_write_exec(unsigned long old, unsigned long new) { + /* If MDWE is disabled, we have nothing to deny. */ if (!test_bit(MMF_HAS_MDWE, ¤t->mm->flags)) return false; - if ((vm_flags & VM_EXEC) && (vm_flags & VM_WRITE)) + /* If the new VMA is not executable, we have nothing to deny. */ + if (!(new & VM_EXEC)) + return false; + + /* Under MDWE we do not accept newly writably executable VMAs... */ + if (new & VM_WRITE) return true; - if (!(vma->vm_flags & VM_EXEC) && (vm_flags & VM_EXEC)) + /* ...nor previously non-executable VMAs becoming executable. */ + if (!(old & VM_EXEC)) return true; return false; diff --git a/mm/mmap.c b/mm/mmap.c index ac0604f146f6..ab71d4c3464c 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1505,7 +1505,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vma_set_anonymous(vma); } - if (map_deny_write_exec(vma, vma->vm_flags)) { + if (map_deny_write_exec(vma->vm_flags, vma->vm_flags)) { error = -EACCES; goto close_and_free_vma; } diff --git a/mm/mprotect.c b/mm/mprotect.c index 0c5d6d06107d..6f450af3252e 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -810,7 +810,7 @@ static int do_mprotect_pkey(unsigned long start, size_t len, break; } - if (map_deny_write_exec(vma, newflags)) { + if (map_deny_write_exec(vma->vm_flags, newflags)) { error = -EACCES; break; } diff --git a/mm/vma.h b/mm/vma.h index 75558b5e9c8c..d58068c0ff2e 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -42,7 +42,7 @@ struct vma_munmap_struct { int vma_count; /* Number of vmas that will be removed */ bool unlock; /* Unlock after the munmap */ bool clear_ptes; /* If there are outstanding PTE to be cleared */ - /* 1 byte hole */ + /* 2 byte hole */ unsigned long nr_pages; /* Number of pages being removed */ unsigned long locked_vm; /* Number of locked pages */ unsigned long nr_accounted; /* Number of VM_ACCOUNT pages */ From patchwork Tue Oct 29 13:03:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13854907 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 22806D2AB3B for ; Tue, 29 Oct 2024 13:04:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F6E06B009D; Tue, 29 Oct 2024 09:04:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 25BD46B009E; Tue, 29 Oct 2024 09:04:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 00E026B009F; Tue, 29 Oct 2024 09:04:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C1EF16B009D for ; Tue, 29 Oct 2024 09:04:25 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 6FFB21A1550 for ; Tue, 29 Oct 2024 13:04:25 +0000 (UTC) X-FDA: 82726657398.19.E296A34 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf09.hostedemail.com (Postfix) with ESMTP id C7CCE14001A for ; Tue, 29 Oct 2024 13:04:04 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=ShPfYuJj; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=CEF0+pmb; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf09.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; 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=1730206904; 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=AiDQwp5SppPm6ae4dVe9eq+4O2yzoe4v2pgxvOajGxE=; b=0WDl9oBh1tlqsfvWPmiPhziuJW5UXqDPk7KxtFHsUjVACJpxFIksWWGydkCHyorGNTLXgH YVAPnOC9FlmV5kDgEJhtqpdLR9irPat8BHR2hzSnHd5LULBXMjH22EPHH97zB7q+1L5OeG QpdC1l+NHTT9yk/iFEd4cPTQXpYm6B8= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1730206904; a=rsa-sha256; cv=pass; b=tFBDia17nFzw/vC/yaX1uyTSql93ldqSShzRIBGi7vixK7BsWNqPF1DYPZzP8sjiMasnTz D5+nV8Plbz3A1ZsLyVH4p+bYQ7rQoe2WtcxWkCS5dDZwwxVbFDw5x/URgn4f8aI7U6isce +HLsJ4JXXNGLJWHhsBYB30j+omKJM1M= ARC-Authentication-Results: i=2; imf09.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=ShPfYuJj; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=CEF0+pmb; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf09.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49TCbnQA032685; Tue, 29 Oct 2024 13:04:11 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=AiDQwp5SppPm6ae4dVe9eq+4O2yzoe4v2pgxvOajGxE=; b= ShPfYuJjQQc7WECx2KsnX7eNv1dDKbqhJmyiA2jwRzRIl6qaHgkDZXORkxl49Xu2 u2B8PgShcnugaIrC1U1S9TXEnRsLDuSJnfqxBjfX2z/ZTJutwJiFiKYUoKGwkGx8 SQJibC5UnMCqdJB5dtyXYBDnwxCbnxXchyjUQaWn00Z+Iw4HGr4KfzcxKqUvg+4i xaXy0qzTjtP2caOhhLji/dvMTuzZMZFQBR0vBYXVFa+l7OEakUj8LWzGHjifwrdp mnTg7F2b7V9i7TBFU1JvOcV9jT27w37Rz/0FTsluiUnsqx0RvPFPjm9pzwXbY1gx 847ptjH9lx5qEa0M2MhRlA== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42grdp5bvn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Oct 2024 13:04:11 +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 49TCqEjM011986; Tue, 29 Oct 2024 13:04:10 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2048.outbound.protection.outlook.com [104.47.55.48]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 42hnacfnea-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Oct 2024 13:04:10 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XDrbqWCOl9s07wpdWRb/fQjy9yQml6BrZt0liHkUItNSJOIFVYrki91CiZcYdCRQANNW086sE9tjjZz06DOVsa6yzkyK986s1vfKLdqH3TObuW98bzJ/1DOd2KDsNHm7l9Knqc6D2XWlR+Ta9U4Dk8B144JSPdRW/QE/ZFMu5rR8GiCdP3rsg3o9Sr0OboHVt3o6vQ4gNNoXdrsnmJ16D9/xiKc36nQ7OrPzPcsro4Z//inYDWm2bc7Qha43dZAXDGrCzbOx76fS36JtnTuq8GwDnhIyleIC/m+YnUD8gzsq7Zkel+621FJa4a5PTPyHMt/7QgZe3G5wvzy1Yozs6g== 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=AiDQwp5SppPm6ae4dVe9eq+4O2yzoe4v2pgxvOajGxE=; b=h5Nnwt2rhBA+gBPlb/mgr6QOxCcFVb9rLKidS5j+8ZkxgWxyGA4mBBCUCBstteGjx5q2v6Hz+fbvMDBmhDrWYkaEznWVgF13OGjiXhNJhfJgbt8I0TK90Di+cjyoNSNaoPX5ECg77PKPY6A0ZmIYgNyylf+dTjgHt3GeCCQYLyAc6M8Fmi3cOv6CgpZD74uYJgYKSMxyPjR6B2qWpb5h08homfaaQKq+yL00vnv9P+bCygWXjIdldc+b2sAfMD7Cvuyor27FsYSo3n0q28xvsW20/Fy1UOwLtCr5mhnyx/3ukepFUOXdgfEJ4TnThTMofxH2EfZhkhu6qleEBtzk0g== 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=AiDQwp5SppPm6ae4dVe9eq+4O2yzoe4v2pgxvOajGxE=; b=CEF0+pmbYMaEStGSe01CcQ3BS8mCNWSiPMXseXX3WajFRrcgI5soWOiQ7Y06Ebksx0FwYyTD2J9PnOegZ1chgdWoNRA1mkdI4IMgFko2hqysCkGaDuVh3rRjklSn4m1AOA0nLe7n1uXuA+f399kj0KgRiEeUTvVl1YbmW6hcYdI= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by MW4PR10MB6462.namprd10.prod.outlook.com (2603:10b6:303:213::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.20; Tue, 29 Oct 2024 13:04:07 +0000 Received: from BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9]) by BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9%6]) with mapi id 15.20.8093.027; Tue, 29 Oct 2024 13:04:06 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Jann Horn , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Linus Torvalds , Peter Xu , Catalin Marinas , Will Deacon , Mark Brown , "David S . Miller" , Andreas Larsson Subject: [PATCH hotfix 6.12 v3 4/5] mm: refactor arch_validate_flags() and arm64 MTE handling Date: Tue, 29 Oct 2024 13:03:46 +0000 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0235.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a7::6) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|MW4PR10MB6462:EE_ X-MS-Office365-Filtering-Correlation-Id: 6ed47963-c553-4172-5dde-08dcf81a2bc6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|366016|1800799024; X-Microsoft-Antispam-Message-Info: tLzbKiM8lyGUyAxl0nyiINik8iicflG1G2OzRuz64vvC1b8Ui4VbT2W4OhTecLa35EFRYxJZ63bDb1rEHIebALbPGiyDGIar6ArpPq8u90lveqW3dVplbr78iBQJlNQw8FEK9SK/GJvTt7u/nlv//EO9ZTgCFlf40rD/s33r8lOjMqM6z4G6hMH0+0W8+YrIq0SsV7k4+IKpXjXfBsY9WsNnrvd/6bEWa6/G+407xWzTCgYNrjGgtB76qt1rdDys8cI73NRQJ3dei18k4R4NJtjIV2Sm6EpAuNI+2lInxi0FfmTAUVbsSkJ5L5A50anUutzdhWtUSw14B7/IG4OmVQA/yK+NhT34m5NhW3ywQU1OAENYe0NyUSwJrD6Zl67HDAZydOFyimJOrAaNhQ4MN0Jbw5bB3G+jsIPiYZgLOSS3hz6teZb7oEFtxzx9L4ZQsSH64WetcwbhkXhNGkNH3/VqkIzyHAVjOfFf7+UXTL0WsMmg5rsjNPwxstKB3dhgzebc0+YKsM4wsddnFTkV6C0J2GHecKMtlPqMYzeL6rPmY4nw9DV3frq9nbv458SH04PdzG25QqAkqKwSak+cLWlkXJnRgszE8FUZS0DUlpfno1Idq+ny9AMAKJ7IGiXpb/NINSAVqkGnjclqEl2b9995b5Tqqa95MuNcBvnUWiqU6gv6V8STZW8R4Rugp0K6K/X7UBWaBDjOqw27075K8Rnp2UI6CnvpNaqziGSlxFoiEPDDTmkXyxQqBk8faqdhVuq/jfkFdiECJyWSNNjvrNEDJwU0RwowBsQzmZt+MF4Lcaz7OCy6Wy0CCam4ZYwxtre18M+9OTE5MSOoJ2fk1V9dZg7VuaMTjy4HzKm3VLV7fbK2E43D/0mfT32Lp/T7aGKI/7oMm5Wo3sxhv/PCSYJuxbcDBi/FUE0tXfaSMHiM4fPYZraAWNVdROmX7jbMBsFnHOfS7Z+nrvrOo0rEWZXe2kBuguQRW6lCrC4OiSeqAy712VBcEmOqjleE8Y2kDYPwjEGVx9Rawro/4DPclXgS6M72mey/+PzH7cL9bXqqP0UNNi4L2WWzuLdKWzRg0Fx8/YEYxRKBKkv9gl4pGdTgECDRxcYqedyJH8vXzzLbNW2uDwTptaQCwcmsndcOIb89yRk/I3CoR8aNcO1ObnSmObHYb4FBU1mLnb/e6fqeOChN/dUw4Zsv2CpXA1gXaIL5HvOGQ1pxGtN1u0lOsxotxaU1yALaXYwLrsZrE0xy1ZtjczffV6qfkHiw0CbHDM0hMEQI2aY8zngbRkyFnSAOmAm/fHGEQyy2F76iqHmOqjJ2L1x/Xi2eOB5YvMP0 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)(7416014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: kujRqwb4gQD9PKlmVcqK6vkAUol5EgoUWFg3HRBAw2wvWFEi3Ji482t6oiB0NrcyoILyX7ypP9o/MmvANuPDCbVlhIEPecxAHNrY1kh0XMoAJ9fDngeV+A8YIqVZ0Dl99EwPLpjzrtJjkw7epWA8YExQU3SMB+BWHz44FiGUogZQ/1gXzvCIoYFaY4WY9ktAbNWxZFzrcoCyzi2L7AvlvycOgy9az+pu1A/kZEysDc3II81EVB3JIFDy/Jsz9DlCbBfp9+qyW5gkySyLOLYctaJvxdTF7539VOtv2bkAVeI9m3YMXONQ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kF6SUP95PSzYOf2vwCfbstKl182hON8ekJqeoVNtLgJAVrIBykqSj6reFvZ2J8j2Fym1YgNgYulESWmm9fjsTawfzUZzAjwJt0umRsw/FwXXa0WjtB0o2JWu8xPTM/5sP+2m9N68QE0Wh34fXTl6u1cTbhPljRp059kFuZ3NPsusBVLS314ST/KIQSp6IgONVAqmp5g2J+aagWDSHpoYFJMyODKpEo3Nf4w== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: tRFTRBErwd/8zhbD6tEqEMUiBGWovUnOSpvtI9D0Tq8YxNMaa0OSGJRxr+4jxyJjm0jQSf2VA8/wteFpf+rp/Nyc3NKCJsi4p1Q0l9hEPjJFq7dFj+VZUTrOs5tP/Ty1T1dJ6mFQOD83bpe9FHeqkLJWSXGyF3GVZKkFaOI375J+Fqx4QiUA4ZeY5iRDIgMii2UX+m3YRIXJ3gdXFLVlS1Mb7jyFcgiSXlyIqnqwJtLX+CR+8gq4LFDJZBsk/c/RFMP3Fc6WewE92oA1I3U8hZY/fJOItlZHA9C9Pk9ZPpVkE1t8LNXZ5/z6iT8ZBg5v3HuWRaf2LdtPHEeOXD3yEUYNLqICUfVBLZL1SA98HGbjoMtwR55Yg6yGD3Zty05wgEJUh5osQLhmdX571xz0LfBv2ytBi0+6XHXPZUVA2rSo4yXWNXL9xI9li3k8IJhv8JyMGMLwxOpJZeU8DkzuLUk1cvW7azeZeGLqqEV0GY9KFK2CRcqS0DzuD7dvCKCZbMk+K7+K23TuwkAaUSamzZHmBazL7qx2qp7nVVgYBU4K7u7SaTk6liBp9TlvptObVSYM6Y/m8r/iHDhO5rTkuDdGv+fbgA2YakpKVpbC7EA= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6ed47963-c553-4172-5dde-08dcf81a2bc6 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Oct 2024 13:04:06.9387 (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: f6LKW9BeY39ISY5eLn54WkxA5+uK2qWk1oFp6d9f2dj6w0P+lYMW/KiRoq74Q3syhpGNJb4tGMXwc/KsnBgapal84MvnHDtYOtYbI5Gc+48= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR10MB6462 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-29_08,2024-10-29_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 spamscore=0 bulkscore=0 mlxscore=0 suspectscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410290099 X-Proofpoint-ORIG-GUID: eWpePnnw00gVN1KUmcU6rvKUO-Q043Vm X-Proofpoint-GUID: eWpePnnw00gVN1KUmcU6rvKUO-Q043Vm X-Rspamd-Queue-Id: C7CCE14001A X-Stat-Signature: jn5kmim9da6q9rhueyededokesfbef8x X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1730207044-797212 X-HE-Meta: U2FsdGVkX18z49Ou4l7Ij2f2RSfODWhLUYoiGVi409f3PuCovgyL4l6YObDe8cfqHiQHoqhoPM8Zqo76GmBA+FTxkH8fCtoJNmebus8+FTlplV/lwfIgUt3oM0I9dBY8eqvgyUlRK7snI3ve2fcwzm9LdZk0tASwsFsXIAz8QQvGIY2C2lPI6XiLqoj2mSv8SiDnyR39j14BuYcKQWAc3z4GZD8D7JvZfW1cqzbF9HnsWOlyXLg4Gf/SnSIluv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JW0m5K4tysOifc3SzQvrK+7mkK4lIW4Hg43AGuhqxG/q1buHYIR9alBFYGS6AgJpiBq1Y6WoOmRX/iwe62CfILL8sLk/dkt8AN3PHU1mjagUFHPc/fxzZ8ZEWPItha4UnsoKEaD4mAP3N5NHii2Iz3QIEt4bi1yRu77ROoE0CZ+uXfjsfiB14E33YkYmEMHe4KIODNtYsFpw0yAxqm144DQdItkf0vGh4EyJadV2GfrLhmy3XKK9ybYwADVtUOJQsJcr4MX3OxM6kuP1k2gaGQ== 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: Currently MTE is permitted in two circumstances (desiring to use MTE having been specified by the VM_MTE flag) - where MAP_ANONYMOUS is specified, as checked by arch_calc_vm_flag_bits() and actualised by setting the VM_MTE_ALLOWED flag, or if the file backing the mapping is shmem, in which case we set VM_MTE_ALLOWED in shmem_mmap() when the mmap hook is activated in mmap_region(). The function that checks that, if VM_MTE is set, VM_MTE_ALLOWED is also set is the arm64 implementation of arch_validate_flags(). Unfortunately, we intend to refactor mmap_region() to perform this check earlier, meaning that in the case of a shmem backing we will not have invoked shmem_mmap() yet, causing the mapping to fail spuriously. It is inappropriate to set this architecture-specific flag in general mm code anyway, so a sensible resolution of this issue is to instead move the check to arch_validate_flags() itself. This requires a modification to the arch_validate_flags() signature to pass in a pointer to the struct file associated with the mapping, however this is not too egregious as this is only used by two architectures anyway - arm64 and sparc. So this patch performs this adjustment and moves the check to arch_validate_flags() which resolves the issue. We'd ideally like to have eliminated the arch_calc_vm_flag_bits() case, but we risk inadvertently changing behaviour as we do not have mmap() flags available at the point of the arch_validate_flags() check and a MAP_ANON | MAP_HUGETLB case would be accepted for MTE currently, but a MAP_SHARED | MAP_HUGETLB would not. This is likely an oversight but we want to try to keep behaviour identical to before in this patch. So continue to check VM_MTE_ALLOWED which arch_calc_vm_flag_bits() sets if MAP_ANON. Reported-by: Jann Horn Fixes: deb0f6562884 ("mm/mmap: undo ->mmap() when arch_validate_flags() fails") Cc: stable Acked-by: Vlastimil Babka Tested-by: Mark Brown Signed-off-by: Lorenzo Stoakes Reviewed-by: Liam R. Howlett --- arch/arm64/include/asm/mman.h | 29 +++++++++++++++++++++++++---- arch/sparc/include/asm/mman.h | 5 +++-- include/linux/mman.h | 2 +- mm/mmap.c | 2 +- mm/mprotect.c | 2 +- mm/shmem.c | 3 --- 6 files changed, 31 insertions(+), 12 deletions(-) -- 2.47.0 diff --git a/arch/arm64/include/asm/mman.h b/arch/arm64/include/asm/mman.h index 9e39217b4afb..94925a0482e3 100644 --- a/arch/arm64/include/asm/mman.h +++ b/arch/arm64/include/asm/mman.h @@ -6,7 +6,9 @@ #ifndef BUILD_VDSO #include +#include #include +#include static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot, unsigned long pkey) @@ -60,15 +62,34 @@ static inline bool arch_validate_prot(unsigned long prot, } #define arch_validate_prot(prot, addr) arch_validate_prot(prot, addr) -static inline bool arch_validate_flags(unsigned long vm_flags) +static inline bool arch_validate_flags(struct file *file, unsigned long vm_flags) { if (!system_supports_mte()) return true; - /* only allow VM_MTE if VM_MTE_ALLOWED has been set previously */ - return !(vm_flags & VM_MTE) || (vm_flags & VM_MTE_ALLOWED); + if (!(vm_flags & VM_MTE)) + return true; + + /* + * We explicitly permit MAP_ANONYMOUS and shmem backed mappings to use + * MTE. We check for shmem explicitly here. + * + * The MAP_ANONYMOUS case is handled by arch_calc_vm_flag_bits() which + * explicitly sets VM_MTE_ALLOWED which we check for here also. + * + * Ideally we'd perform both checks here but existing semantics support + * hugetlb in MAP_ANONYMOUS mode but not a MAP_SHARED mapping, which is + * likely unintended but we maintain identical behaviour for + * consistency. + */ + if (vm_flags & VM_MTE_ALLOWED) + return true; + if (shmem_file(file)) + return true; + + return false; } -#define arch_validate_flags(vm_flags) arch_validate_flags(vm_flags) +#define arch_validate_flags(file, vm_flags) arch_validate_flags(file, vm_flags) #endif /* !BUILD_VDSO */ diff --git a/arch/sparc/include/asm/mman.h b/arch/sparc/include/asm/mman.h index af9c10c83dc5..d426e1f7c2c1 100644 --- a/arch/sparc/include/asm/mman.h +++ b/arch/sparc/include/asm/mman.h @@ -10,6 +10,7 @@ int sparc_mmap_check(unsigned long addr, unsigned long len); #ifdef CONFIG_SPARC64 #include +#include static inline void ipi_set_tstate_mcde(void *arg) { @@ -54,11 +55,11 @@ static inline int sparc_validate_prot(unsigned long prot, unsigned long addr) return 1; } -#define arch_validate_flags(vm_flags) arch_validate_flags(vm_flags) +#define arch_validate_flags(file, vm_flags) arch_validate_flags(file, vm_flags) /* arch_validate_flags() - Ensure combination of flags is valid for a * VMA. */ -static inline bool arch_validate_flags(unsigned long vm_flags) +static inline bool arch_validate_flags(struct file *file, unsigned long vm_flags) { /* If ADI is being enabled on this VMA, check for ADI * capability on the platform and ensure VMA is suitable diff --git a/include/linux/mman.h b/include/linux/mman.h index 8ddca62d6460..82e6488026b7 100644 --- a/include/linux/mman.h +++ b/include/linux/mman.h @@ -117,7 +117,7 @@ static inline bool arch_validate_prot(unsigned long prot, unsigned long addr) * * Returns true if the VM_* flags are valid. */ -static inline bool arch_validate_flags(unsigned long flags) +static inline bool arch_validate_flags(struct file *file, unsigned long flags) { return true; } diff --git a/mm/mmap.c b/mm/mmap.c index ab71d4c3464c..40b5858ae875 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1511,7 +1511,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, } /* Allow architectures to sanity-check the vm_flags */ - if (!arch_validate_flags(vma->vm_flags)) { + if (!arch_validate_flags(file, vma->vm_flags)) { error = -EINVAL; goto close_and_free_vma; } diff --git a/mm/mprotect.c b/mm/mprotect.c index 6f450af3252e..c6db98b893fc 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -816,7 +816,7 @@ static int do_mprotect_pkey(unsigned long start, size_t len, } /* Allow architectures to sanity-check the new flags */ - if (!arch_validate_flags(newflags)) { + if (!arch_validate_flags(vma->vm_file, newflags)) { error = -EINVAL; break; } diff --git a/mm/shmem.c b/mm/shmem.c index 4ba1d00fabda..e87f5d6799a7 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2733,9 +2733,6 @@ static int shmem_mmap(struct file *file, struct vm_area_struct *vma) if (ret) return ret; - /* arm64 - allow memory tagging on RAM-based files */ - vm_flags_set(vma, VM_MTE_ALLOWED); - file_accessed(file); /* This is anonymous shared memory if it is unlinked at the time of mmap */ if (inode->i_nlink) From patchwork Tue Oct 29 13:03:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13854908 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 17154D2AB3C for ; Tue, 29 Oct 2024 13:04:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A20056B00A3; Tue, 29 Oct 2024 09:04:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9AA906B00A4; Tue, 29 Oct 2024 09:04:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 788156B00A5; Tue, 29 Oct 2024 09:04:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 50E796B00A3 for ; Tue, 29 Oct 2024 09:04:34 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C62501411F8 for ; Tue, 29 Oct 2024 13:04:33 +0000 (UTC) X-FDA: 82726657734.19.9F2BFD4 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf29.hostedemail.com (Postfix) with ESMTP id 57149120023 for ; Tue, 29 Oct 2024 13:03:57 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=DUlKRjXa; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=qtqRIvjb; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf29.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; 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=1730206910; 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=NOpeGovjLTXmooO9NPqJLSGOV0MyRnixDvLGLhb9tgc=; b=r9MrrTu35wNJK2wVbifV14o5cAI6gKbx6+2UjDHpnUAwe4DdDdew2xOU9cp2PGU1O7VHWg 18Oz0GpeSC+CLtD5Rg6bONqjuMWu9T93r9ZEnVtTUpJkL8ae1eqakQndLG7PEi3tQd7BL8 Jdyb6Oa8eTXuyNAb4YGbkKsfoQ3McVg= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1730206910; a=rsa-sha256; cv=pass; b=r3fyY6B11z0Uv673NTb+58K2/MBmIzioG2wOjD4V8x2ZK9kqeybPMURE4ApW6sRsRPjX4x ZMmuh/oT94b6ctQW7kiR3euuYA8jRi344J1cjjseTER9P9p5r62nTSmWNzFgZBRSZ5WP2X w9B8pZqxHs3pjZWvYnfefAPLj3U/yLI= ARC-Authentication-Results: i=2; imf29.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=DUlKRjXa; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=qtqRIvjb; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf29.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49TCbsIM009791; Tue, 29 Oct 2024 13:04:19 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=NOpeGovjLTXmooO9NPqJLSGOV0MyRnixDvLGLhb9tgc=; b= DUlKRjXace8bVAkzykjcIsgEt3lShvpWt6MxRxiTkrzKj/2Zu7VnAJ4Ov5yvpEbD SjPGvyMWeBD43nOHMi6hhbjcm9N4dpS3BErKhHfkMxOlSVosYOEDgxamqCXl9eck TAZUcgw61fqRkV1QZZP3SfbYFogCfa6ttm5WEij+7qs915advIKxMRXy8k2BOzQF qxacZhqf7TV1/j+yV/Gxvtps3ucedlFTwF92oXgyctPsBuyoy7aLFVWsTYClCjwM F/25Pu4jO/umvyUxt0T+cChNlCpy3E7tW9NpBr+HyeiAMRkLFXMU3Jcq4AmDgLXi CA6SZF9gJVJ1asVro/a0sQ== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42grys5cx6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Oct 2024 13:04:18 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49TCo1aP008624; Tue, 29 Oct 2024 13:04:17 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2040.outbound.protection.outlook.com [104.47.55.40]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 42hne9krw8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Oct 2024 13:04:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KEtrW0I2sGuqMz0Rj3txYCuynfGcNOBs2vLURaeKS6RatYS3ZvFuC6l+urZoSUUsnNXycwa+Cqmf7W6JwzwEh93GL5h5wDLugVXdx8s++caohPHDGkU8xkeNK9KvlnwqnnajrXznRlxYY7I/aijT1aIwtBrJtuaL92Qi8QS3kwrj1ZKScFsLnWYfwCt85yKgg6DDjI+w8143oks8Pmhzp5FtVn8t9z03RTzV0vAl2hwx5+EMHEg3mrnrg5QdBUWxeeEwjSrdRx2F7eaE4gYBUtt0a9Ed2E57gbY+7QScqWfOkmcDR33mC9LIN3wX+ECpHCXDjgqyPQRZXAAPVwIICA== 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=NOpeGovjLTXmooO9NPqJLSGOV0MyRnixDvLGLhb9tgc=; b=CKGvch7t6y4mRcuYtLU/OBadxtx6Hv7da9mShgGYwdAYdmcaCe0SbuJJrTHPWP0/3B81+0Z4A7BIGjqDmirPf3SuDipJaQMugo3dwLFTYvQwlT7LfJ3jwBAGaSxY+K0NoSpXCGoWrJTLN/UbJOGbbn+NzFHzWOpt7Ql6SnANhgb118AQMG4OGYqf0TeLmMaGhgDfNAKeCvRa9jhAkO5X4gAO/azQLWdD8CV67ZrterbDszhTmkBCWKwjVeWXqGd314KOmDtjR7YItno+gaGMgQaeRypRNLBjSDuIUoQ5AT3BPGPaBXNJKMD9YG1FDnRSYUA1vV+DMBwwFp1+D4qowQ== 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=NOpeGovjLTXmooO9NPqJLSGOV0MyRnixDvLGLhb9tgc=; b=qtqRIvjbXYf/fklarGlHnpdCNIVdf96c2SJ+/8tgzVHZCBrsKADNp/cA+qrrkUd/4Pr0tlUSbIlq28tsFv79x6OGdE1luETEh6CekmjxgAV9QB7trhKtO/kGaYb90ROOSVSkURehzmL2NKNsNCfCMiY8eUW591hoUslXndP30bY= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by MW4PR10MB6462.namprd10.prod.outlook.com (2603:10b6:303:213::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.20; Tue, 29 Oct 2024 13:04:11 +0000 Received: from BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9]) by BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9%6]) with mapi id 15.20.8093.027; Tue, 29 Oct 2024 13:04:11 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Jann Horn , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Linus Torvalds , Peter Xu , Catalin Marinas , Will Deacon , Mark Brown , "David S . Miller" , Andreas Larsson Subject: [PATCH hotfix 6.12 v3 5/5] mm: resolve faulty mmap_region() error path behaviour Date: Tue, 29 Oct 2024 13:03:47 +0000 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO2P123CA0024.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:a6::36) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|MW4PR10MB6462:EE_ X-MS-Office365-Filtering-Correlation-Id: 5b3ab89a-5004-4184-976a-08dcf81a2e49 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|366016|1800799024; X-Microsoft-Antispam-Message-Info: x8ZzwJG/f74VhQJab1ymksESbFCWglwusHxqUU7Ji3Yl8CzR0/R6aQWfvsCSbXjGXTd6lS9HAUEo3F4JuLpSB7x2RMYjyqSqOi76xqVTUFu0p/i+xOvw6aBK6frLCVzdkpyZ+OFn57JSD+ocnD1jmFLiy61NdtlcYxCYgUfMcimrYJn1sdAUHf9aHkyDnF124bSh3a//VMG2SYV9wyWPPlgBc7li4p1XQRgiAUMJsu7//MJBnyacDsTSzTxMju7hDvZEP4OFI+O/2yxwCEm0rLCrvB6Wv47FzzQ5zBo/Mc8TamXQVplUIreZTZWfSuvBmXx/ybU7nDI18FcYS0hoa8IsdrRd+OPqhT/FrMFTYouDd/mbW9RfpP/YhgtW/x+r2/MW/bH3KfbR5Rc7nCcgBD9a7fORC7bwMc+Ua+yspbHq86WvSoDZGFirFKb1ibExF49+s8flz8uWVb4ckev6Vvl8IaWuxnIg1+befUQD64sVJ86qi4YhwKCBW5KrtB1zwazYRVnLEH2YIntYNHRPI5OgXpmTU5UMcUDmQOkR0hyf/TtHzmKKDnMdIYasZUEANa2YE02Z75BCxLT+4wQ/zQL8DiSHfe+tgBIHzquWWzXi/8MR8L3G5Azcp3Q/QwJrdLfvm8dhOKUcdCEjFwDByQ3d5VYvEacJVfcXhL6DJSsVQs882ukA/L1StWePsGkwDPsdll+qsHRt8DV0PSZsKIoKVWpnuQ5IPFuKFKMIJlE3R2dUQcLANW7zPoUbxXo1wtm400LIywfVI4H5nMG9scL/2Zet3hW24mb3Wm/VrL9YAOBHywYLUp5T4YM9R9AETlmqQsYOEF3Gq/1Gk+PAi5ET6AWSOPoKHbgpXPe8XhY6G585ze5QpZ//hoD8pKQh1dgj3igiYHNYjRgcx3SAA8b/DmO0zO0fnwguzH/UvKxlSYbXbPejGspmNwGis4EbhoTqidZpGrzR4o8FtfuFPGux2UGejF6m+ND1YHj61dOdnyONvTyl5Yuxa4yjNE7sOGo9axSvaCpYiURpSL1MR+X/HVhHlQbJw1gQaN2Eei+lrXy3AOUb7fypZYLjNDtizy2lnPy3pETynIW67193dqQtBLCxa9AcO/wHhhcUtBf5RFMOa2iRCgHXnuNNwYgU6cdTDeb0PmWDEGxUm5NA+/npz6GzUxOOgdv1mSPmCi3ws1hIuw+RjQhhzWy8PX5qv5WR1OEbkLO1hhv2SBOamV6U0CltjMzySH0454TObQjUCM8IXnntRur8lU0UWrWBY+qzM9fW1tUoRTsEY/zN0yao9tnTV8TmH7SV9Y73nS96NPL0vlvYIXC6jI272osf 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)(7416014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XKpfwsmYC7mKnRmV4XdXyDuuuG+YOTK46MJ2R+Zgnv2m7xQmk/u3kQGTLi5yGa2iUScQTzJpEimq4LV94BXTnJq7IXP9LMkTDb5UrrF6lN5eH9MlLgYfduEJTz+0L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Oy1UAGYLGO74q0OS3ot+2N8ZApxV4UeXLN3upMOTY/g= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5b3ab89a-5004-4184-976a-08dcf81a2e49 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Oct 2024 13:04:11.0375 (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: V7LiBK/9APHSLfFps7S3GxU0fkARICdxv9fyPFWcrbffvvSXUU4euUB+MIBqzAf05U9Po7YBweVic4r9dMinMCXvK2KJd5WbrGYw0CMyGBk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR10MB6462 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-29_08,2024-10-29_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 bulkscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410290099 X-Proofpoint-ORIG-GUID: 8C8GAsQ0ijpbmrqb5qCaOij2w0XVgvEu X-Proofpoint-GUID: 8C8GAsQ0ijpbmrqb5qCaOij2w0XVgvEu X-Stat-Signature: qsuj448ireeun4kbmpt355m3trcwpyft X-Rspamd-Queue-Id: 57149120023 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1730207037-897659 X-HE-Meta: U2FsdGVkX18Fx3IBjKhTXpm4TIDFxjV4QdsLy0kREkSlIMRxllGXQtJezNHAkhAQtpjL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ZMGT3uBwfQMfWbPRAkTybehRAvpFFFwEudPa+Q8JzR/Mk4533ICKkFlT4XO4BPrZxeu6kSDNfSQoT/RFoxuhhSxPY2TnImaYPMBIBYZtTnBXu9m/cCa23QfI6imGEPoiMprWlEGSt1YCZZ8V3+S597nNjcKk7bX4NFPQxjAugAKf+FDGH853BSNHM/d4K72ZydbnJKI9U092TPYlzqRdyysykHUTOv28CjG4WaSO2i6a47d3pnSvgi7xGkY1MGfTG7rql9b25kjZ6d81JjrJebhVcgNyhZzc/D88PcNaVfZelrTB3p7QzFc8UPZFEJF8cIX/UOc+Vsewp8eCwPgKcXXLHxH5+cyQgAK6iezh3K2eR4XGsxcBrZPqg6bs4Nwc1zqPTk5XCY81oJKk0M24X6Gs5CAnwxF8ODFN442GdQUXiinO7lVehZOdOdKmtlDSYNZfvSpwUsiK7HzreDE6GT8hg== 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: The mmap_region() function is somewhat terrifying, with spaghetti-like control flow and numerous means by which issues can arise and incomplete state, memory leaks and other unpleasantness can occur. A large amount of the complexity arises from trying to handle errors late in the process of mapping a VMA, which forms the basis of recently observed issues with resource leaks and observable inconsistent state. Taking advantage of previous patches in this series we move a number of checks earlier in the code, simplifying things by moving the core of the logic into a static internal function __mmap_region(). Doing this allows us to perform a number of checks up front before we do any real work, and allows us to unwind the writable unmap check unconditionally as required and to perform a CONFIG_DEBUG_VM_MAPLE_TREE validation unconditionally also. We move a number of things here: 1. We preallocate memory for the iterator before we call the file-backed memory hook, allowing us to exit early and avoid having to perform complicated and error-prone close/free logic. We carefully free iterator state on both success and error paths. 2. The enclosing mmap_region() function handles the mapping_map_writable() logic early. Previously the logic had the mapping_map_writable() at the point of mapping a newly allocated file-backed VMA, and a matching mapping_unmap_writable() on success and error paths. We now do this unconditionally if this is a file-backed, shared writable mapping. If a driver changes the flags to eliminate VM_MAYWRITE, however doing so does not invalidate the seal check we just performed, and we in any case always decrement the counter in the wrapper. We perform a debug assert to ensure a driver does not attempt to do the opposite. 3. We also move arch_validate_flags() up into the mmap_region() function. This is only relevant on arm64 and sparc64, and the check is only meaningful for SPARC with ADI enabled. We explicitly add a warning for this arch if a driver invalidates this check, though the code ought eventually to be fixed to eliminate the need for this. With all of these measures in place, we no longer need to explicitly close the VMA on error paths, as we place all checks which might fail prior to a call to any driver mmap hook. This eliminates an entire class of errors, makes the code easier to reason about and more robust. Reported-by: Jann Horn Fixes: deb0f6562884 ("mm/mmap: undo ->mmap() when arch_validate_flags() fails") Cc: stable Reviewed-by: Liam R. Howlett Reviewed-by: Vlastimil Babka Tested-by: Mark Brown Signed-off-by: Lorenzo Stoakes --- mm/mmap.c | 119 +++++++++++++++++++++++++++++------------------------- 1 file changed, 65 insertions(+), 54 deletions(-) -- 2.47.0 diff --git a/mm/mmap.c b/mm/mmap.c index 40b5858ae875..c078c73e46ed 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1358,20 +1358,18 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len, return do_vmi_munmap(&vmi, mm, start, len, uf, false); } -unsigned long mmap_region(struct file *file, unsigned long addr, +static unsigned long __mmap_region(struct file *file, unsigned long addr, unsigned long len, vm_flags_t vm_flags, unsigned long pgoff, struct list_head *uf) { struct mm_struct *mm = current->mm; struct vm_area_struct *vma = NULL; pgoff_t pglen = PHYS_PFN(len); - struct vm_area_struct *merge; unsigned long charged = 0; struct vma_munmap_struct vms; struct ma_state mas_detach; struct maple_tree mt_detach; unsigned long end = addr + len; - bool writable_file_mapping = false; int error; VMA_ITERATOR(vmi, mm, addr); VMG_STATE(vmg, mm, &vmi, addr, end, vm_flags, pgoff); @@ -1445,28 +1443,26 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vm_flags_init(vma, vm_flags); vma->vm_page_prot = vm_get_page_prot(vm_flags); + if (vma_iter_prealloc(&vmi, vma)) { + error = -ENOMEM; + goto free_vma; + } + if (file) { vma->vm_file = get_file(file); error = mmap_file(file, vma); if (error) - goto unmap_and_free_vma; - - if (vma_is_shared_maywrite(vma)) { - error = mapping_map_writable(file->f_mapping); - if (error) - goto close_and_free_vma; - - writable_file_mapping = true; - } + goto unmap_and_free_file_vma; + /* Drivers cannot alter the address of the VMA. */ + WARN_ON_ONCE(addr != vma->vm_start); /* - * Expansion is handled above, merging is handled below. - * Drivers should not alter the address of the VMA. + * Drivers should not permit writability when previously it was + * disallowed. */ - if (WARN_ON((addr != vma->vm_start))) { - error = -EINVAL; - goto close_and_free_vma; - } + VM_WARN_ON_ONCE(vm_flags != vma->vm_flags && + !(vm_flags & VM_MAYWRITE) && + (vma->vm_flags & VM_MAYWRITE)); vma_iter_config(&vmi, addr, end); /* @@ -1474,6 +1470,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr, * vma again as we may succeed this time. */ if (unlikely(vm_flags != vma->vm_flags && vmg.prev)) { + struct vm_area_struct *merge; + vmg.flags = vma->vm_flags; /* If this fails, state is reset ready for a reattempt. */ merge = vma_merge_new_range(&vmg); @@ -1491,7 +1489,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vma = merge; /* Update vm_flags to pick up the change. */ vm_flags = vma->vm_flags; - goto unmap_writable; + goto file_expanded; } vma_iter_config(&vmi, addr, end); } @@ -1500,26 +1498,15 @@ unsigned long mmap_region(struct file *file, unsigned long addr, } else if (vm_flags & VM_SHARED) { error = shmem_zero_setup(vma); if (error) - goto free_vma; + goto free_iter_vma; } else { vma_set_anonymous(vma); } - if (map_deny_write_exec(vma->vm_flags, vma->vm_flags)) { - error = -EACCES; - goto close_and_free_vma; - } - - /* Allow architectures to sanity-check the vm_flags */ - if (!arch_validate_flags(file, vma->vm_flags)) { - error = -EINVAL; - goto close_and_free_vma; - } - - if (vma_iter_prealloc(&vmi, vma)) { - error = -ENOMEM; - goto close_and_free_vma; - } +#ifdef CONFIG_SPARC64 + /* TODO: Fix SPARC ADI! */ + WARN_ON_ONCE(!arch_validate_flags(file, vm_flags)); +#endif /* Lock the VMA since it is modified after insertion into VMA tree */ vma_start_write(vma); @@ -1533,10 +1520,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, */ khugepaged_enter_vma(vma, vma->vm_flags); - /* Once vma denies write, undo our temporary denial count */ -unmap_writable: - if (writable_file_mapping) - mapping_unmap_writable(file->f_mapping); +file_expanded: file = vma->vm_file; ksm_add_vma(vma); expanded: @@ -1569,23 +1553,17 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vma_set_page_prot(vma); - validate_mm(mm); return addr; -close_and_free_vma: - vma_close(vma); - - if (file || vma->vm_file) { -unmap_and_free_vma: - fput(vma->vm_file); - vma->vm_file = NULL; +unmap_and_free_file_vma: + fput(vma->vm_file); + vma->vm_file = NULL; - vma_iter_set(&vmi, vma->vm_end); - /* Undo any partial mapping done by a device driver. */ - unmap_region(&vmi.mas, vma, vmg.prev, vmg.next); - } - if (writable_file_mapping) - mapping_unmap_writable(file->f_mapping); + vma_iter_set(&vmi, vma->vm_end); + /* Undo any partial mapping done by a device driver. */ + unmap_region(&vmi.mas, vma, vmg.prev, vmg.next); +free_iter_vma: + vma_iter_free(&vmi); free_vma: vm_area_free(vma); unacct_error: @@ -1595,10 +1573,43 @@ unsigned long mmap_region(struct file *file, unsigned long addr, abort_munmap: vms_abort_munmap_vmas(&vms, &mas_detach); gather_failed: - validate_mm(mm); return error; } +unsigned long mmap_region(struct file *file, unsigned long addr, + unsigned long len, vm_flags_t vm_flags, unsigned long pgoff, + struct list_head *uf) +{ + unsigned long ret; + bool writable_file_mapping = false; + + /* Check to see if MDWE is applicable. */ + if (map_deny_write_exec(vm_flags, vm_flags)) + return -EACCES; + + /* Allow architectures to sanity-check the vm_flags. */ + if (!arch_validate_flags(file, vm_flags)) + return -EINVAL; + + /* Map writable and ensure this isn't a sealed memfd. */ + if (file && is_shared_maywrite(vm_flags)) { + int error = mapping_map_writable(file->f_mapping); + + if (error) + return error; + writable_file_mapping = true; + } + + ret = __mmap_region(file, addr, len, vm_flags, pgoff, uf); + + /* Clear our write mapping regardless of error. */ + if (writable_file_mapping) + mapping_unmap_writable(file->f_mapping); + + validate_mm(current->mm); + return ret; +} + static int __vm_munmap(unsigned long start, size_t len, bool unlock) { int ret;