From patchwork Thu Sep 26 15:10:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13813447 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 70EDFCDE012 for ; Thu, 26 Sep 2024 15:10:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BD3346B0093; Thu, 26 Sep 2024 11:10:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B82D76B0095; Thu, 26 Sep 2024 11:10:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9AE2E6B0096; Thu, 26 Sep 2024 11:10:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 7794A6B0093 for ; Thu, 26 Sep 2024 11:10:52 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 1546E1A185A for ; Thu, 26 Sep 2024 15:10:52 +0000 (UTC) X-FDA: 82607226744.12.C477733 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf22.hostedemail.com (Postfix) with ESMTP id DA1A8C0013 for ; Thu, 26 Sep 2024 15:10:47 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=Wh8Ej3rO; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="AbrFF/zX"; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf22.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=1727363327; 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: references:dkim-signature; bh=dx7Ixwkr/KUEau1xEFPhQX22TfVClPzx5j37lGF3y8o=; b=UY9aW/Hi4J6eZeYFATXvYL1VHo6AorTrdvgbbgg7y35RtTQHJudLpXR7tE1YOhX35OP8i/ vbRmGNLzKC7STV54hftmcpywvsXkdUlO/q+qIaBDzfxi4mqtzb9WYMAjlPf1lJ4CRfqnmu 6GQwk2I5LmARFq3wZHeA3U6fhrxuNjI= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1727363327; a=rsa-sha256; cv=pass; b=JvL3JZlH6Mathw/ewJ3Fg6ny7Idu+xkY3cKuqYfQ0x7e1wG/suQndKp2l7K206G9L9Y1Iy wT8/2JUC5SukgXvY32od7FmeNLVRgv7fTME2YA2FLEjcl6uWMm/5aB5exEktKWxhNapxxt cIfkRdseXczMg+fmxWZpfSlOg8SniGM= ARC-Authentication-Results: i=2; imf22.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=Wh8Ej3rO; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="AbrFF/zX"; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf22.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 (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48QEXakw027081; Thu, 26 Sep 2024 15:10:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:content-transfer-encoding :content-type:mime-version; s=corp-2023-11-20; bh=dx7Ixwkr/KUEau 1xEFPhQX22TfVClPzx5j37lGF3y8o=; b=Wh8Ej3rOerazPlRBpSGgg8E/FeK60z +fGYFlpsvC9mtAPRny21ci6M+RAhaqRaGLxlfND3UcZjGf1BtIJrJOevpNaOsqQs rzce20VVyb+C+Ynk7SXluX+yQlAJWlePhGXhCeQrQq6N8DaTuV46VY+mD0wgv3YW MX0U+ThzvS5nP3eYjk1ualAoXWaaHpQfYHyJCxvNogToKkSpuezHGhsU+opDAKWg ERK5T+fQHcVopxU8Ndi/piNNnliCHSgb+eihmWxF1rcPelGNAjknljc/wjp/KYSV KusOc0X1UDufUE4gIupxszmleOXRe0JD3ePPkfCB4O2TFLg0eflKiuaA== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41smjdau12-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 26 Sep 2024 15:10:31 +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 48QEMFQC025269; Thu, 26 Sep 2024 15:10:31 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam04lp2045.outbound.protection.outlook.com [104.47.73.45]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 41smkcafq8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 26 Sep 2024 15:10:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cvi6+DRsggnTrSIN7tgk9aghVN4vEoMOtQL+VvRXr708tkzocKxyMm8ufM+/MAVO5uLbkzMJUtuJjJmMdQhrsMqjDHn4DFnaozV7ybEu9iDRfLopsIW6Q56JtiPICvPN6GsA0xW06WiKGwv1juSD+xQX/JybbcorUn796IoLIa2T80DYkOTNbWLzTvDIphzb/wMxudEqzixErZPf2KSQRmBSN86WmIaHT4GGX0luUExO+1gvH26l3E55jVNyjDgt+O8VMx1SSepQX36yLTW3UjTWk3oTkoIjnLB92zo6Km7LT3A8wIgdPlm8EceKnY7Ty8men5GJPdy19pLKq9cvcw== 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=dx7Ixwkr/KUEau1xEFPhQX22TfVClPzx5j37lGF3y8o=; b=nIrXz4pvXRcYdxswGq38mBA9i/s4xmiZG87AjalndGi4Xix1DiglOZcdNPMoX2bfo3z4/gVHUIOf6N/J52A0nUCeWHlcpuzUZiUYbLoujXSGNGsIyVlx+Tt5nUArZcNjGKjPDkkSbJHAkhDRZ1RtAzmmJ80XwrdNSw1FmJtuh/zeWG/GAWV+NzEBLsjioBOExfAq89SADllM0R1l6Utmd6JdsO2Mnj5ei2tgo0xBQC3eI/IuwJ8YeVjusxPibfQ0Jw9E8v95b+9Kw6TKEsidQco8KQNrGYTSUUcfMoEeeZuHdGKfsjdtALNEXLQvyOaVh7DKq3ZTRaMRJXiRfjjTwA== 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=dx7Ixwkr/KUEau1xEFPhQX22TfVClPzx5j37lGF3y8o=; b=AbrFF/zXd7dDEZ1J6GX2yUk36i5qlsZErGhDPf4FQ210E6o9mtAPh5AHs8v/dvpGRAmRWbK2rjG1QR5Ap9ra2Mb4aEMMSiM/o+cGvFpHmWIVnr0GieiZRkiJmsu9Wf7uwpPowg9MxqGWtO6VNMDgIY2QMmth02lSxYQoAyHGzms= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by DS0PR10MB7342.namprd10.prod.outlook.com (2603:10b6:8:f9::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.8; Thu, 26 Sep 2024 15:10:28 +0000 Received: from SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e]) by SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e%5]) with mapi id 15.20.8005.010; Thu, 26 Sep 2024 15:10:28 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: Vlastimil Babka , "Liam R . Howlett" , Suren Baghdasaryan , Arnd Bergmann , Shakeel Butt , linux-api@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Minchan Kim , Christian Brauner , pedro.falcato@gmail.com Subject: [PATCH v3] mm/madvise: unrestrict process_madvise() for current process Date: Thu, 26 Sep 2024 16:10:19 +0100 Message-ID: <20240926151019.82902-1-lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.46.0 X-ClientProxiedBy: LO4P123CA0613.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:314::19) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5613:EE_|DS0PR10MB7342:EE_ X-MS-Office365-Filtering-Correlation-Id: 3aa983de-3ba8-4a00-9d58-08dcde3d5ada X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|7416014|376014|10070799003|1800799024; X-Microsoft-Antispam-Message-Info: Ucp+1kjdmjrR8NiQNY6fMooiHCctOKzxBduaup9iz4vJCXz3Fx2xImynG6cKT+qCuS+H5uyFnwuLyeFVY6ykEEr5pw0/b22EvzfPw/hKZRysgmcjC6PFHyJrI1KnAexgxM12NpPxIeu0dAd0zciuLe9RQWNos93t7xy04UHxZhyERaUn2ZG3mUVH4qQQBXIgyTtoBNbFcIzqdOGj5Mz+awxUQfUqZ6Sk9ARJaFQisGFx2oUzIoPO4L1ZQCb5vtNQ+WOXMSAzmzlJ9JxeTj+h30i2YPyk4PBa+M0aGUxt0FJXIOsw9XBFU4XPa7HW/5SRNkRxVg1Q48/lcW8Y4gZAQ+4B1X7N25aW3dqaxNhvMWO01N5GhOPQsdGPZBOPy2dcI27Qm80crd1rm7/W8bPw3jBfRYiNbCaplHneuvUuapDVG/MH7aUkWcKBrmBVy9PnLexkKRiNKEn7Ga7YGzUSo7HYGeBmHOvmKUJaoAJce9LfenSBiBVKYCHlymahdntYU0IGVtjcUifwm5SPVB15htg+rW6NjnOgnW0PnL7E9LCiQluzkdRH/wz96ke+ttOJcL0DCvFX5VAaqMSOxc2085UcVLU/M5lhEnpAfWg67fBP+U0Ci3GKNAhkzCJrRmeUKiDQL+g5Xi+E5MysVnN+1SDKkNakE9pJD67rtmgaAvqpzsOcPjuEriJAQ5DkHSv+J2bPZUwk9kZctT8P98kEUTcc7EF8GFQdm+CWTGLKiwKcSHOaHW8iVbnS70FZwH4Z1MdEA9xENTL/YMJhNvW39a4VGpwyBi6S+rcSGU3SVa/DQQVLvOujOuaI5WWafdxElbpRl+ENjUAKf0uciTPwtmdNTQkWm4nvxE9iH3GVVs4RoJaKGrwvsziJE5BvX2iGOlz6wdZciM/yVBbiPCNGviyktYQJOFOxywoJppt5jmWOLgwsnwjxlWROd1xSJygTTr/aGqpF5dpD9jJyD/EWsHPoUQ4GKlWc1C91IvKb5QsRMY7Wu6aYZq2KTO3Sdxla3vWYGX4/hUJO2RPFxLk0xBOjcgmFlSXY5DqX3ajmyZkFsSziLNsKew7mr0dCFL7IA2+m7tMJQD3WjFxmXdckAGAC1vQlHrZaGi5RiYe7VVmiB8+BFHv99RGeot2hgfh4L7xYbOorRhHCMw/TduqIHteBAHN9k+1awDUyy20lrFX69Ps4FZ0Da5xTBLwerl3i/VFjfwd01X7OVYnZCDoDyoOHrb1ibXUgUOa3aPOzYObDBVujXOVlAu0CG/50PXmW4hEs3v+gz0N0O/Jy/q4SZk8sGi/A6Ax262OhNBuUb/k= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR10MB5613.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(7416014)(376014)(10070799003)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: qzm5d09xl6NBZG4HppzIJLdqguIszjWDCvT7P0VnLST+e4VfVp61UNFIXTm3rTtmOcXyGPfipNmaqaab/jVfcm+LmxCMjb9dgY6cupdWldKkqDz3PMGueDKCDh5zZnyoWKWKPXuCv8ZVOZs8927cJTwwSs3QV7JBL1phPtTnAM5tWofTGewbxxmB5Nn7x5hTKENEqzPBo7fZ3MiNjG/m6kMKp5kmz+BuBhomaNL3AZ/TBjG0hTAevl6wvmzIP997GfSpjaqN5sTDrvaAVb5TqETjce2yq8R5BcSUzJCW21G/vkDMS4HXw8PQkxLg4dQe452BeNT9HStrWrRbr6BTcnMLGIsqvK495OfZS7bl3G8apHyOnRpchLE6BBT0l6zlp1pItVlIKLHLCUhIV7pbRpPTjolFbNiWX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+LWjpsyK/+HeI2S3nnFQa4XLv9fZNSNnWoxLEn+Nb67QkC4wj5VThQryfyKJ852Km14Caubm7sFKAv+YO6IUUJSxp6B2wjCGg/9dB+eFaJqSRWWmIhksRBbX3QaYPFsgf28QkpGVIPAmCx4owJC3NY9z8KZI/r9BP+bQeFEcd0mdxI0SI9oqmXBghJlpoHw8A== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: c9Gx2M/3k5APJMrFmoyLYULKF3cc5bZnm9cKe2hJEZC7ekFoLIiNqmhl8125XXDPrJefJHoxGhYk9cg+b4GFgZCffpx8QKPxKc5BBZ4DsbASLV0PsVvT2t//aAjYeRMuYqoDLjljYGn8zxdoYdnphwDv2LUDXnDT2eEAq8nCkwh7Das1xLmyXP+rCAxxqMv2LhFamYli06PMlC3VpClH16cafZ7YAEEau9lupCyAeHfYDN6W6b5Br1Y7kRS4kjAQVs+6byn0onhLTqxVc7EnNRzYVNrAgj2tK+icddLT4rH/uMUMgG4d2Hu4z85Bk9x13TRqCFQB7fjr6ljhDcoK737wwY2uUDpIFz9ZfNAh0q3CwQxD9HRe4oNYd4lW/x5o7Oy7hGiWhkt2kzPETu1STpf8iEfhtZUaSiY2kHf26P+DWi5Ty0ZxgQplXtL6JN7ShvV88hgSbQE4qrUUUdnUtoTbIqKLYb39iN2EuzIM/62GPvhb+2JgaH+DH2iWGny4mPjnRGM/X4sGtgC2uqbbmuItQgrl7Q4Kv34sO9UA1S0i3zgCaEXtsuTZuo5IeIwaygpLbp9yUki4cf49DmCgsLrK8yCjeQsglX+SsAYPnjk= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3aa983de-3ba8-4a00-9d58-08dcde3d5ada X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Sep 2024 15:10:28.1358 (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: E03oWH73txup22zxUxwTdSIeRK/f4fiSvky47xoQphbUCInQmGKUKjWfEfiqXSIoeTebHB+NDnZ25SmagguW6CvrGKbd4fWLJQO95t1CVVs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB7342 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-26_04,2024-09-26_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 suspectscore=0 mlxlogscore=999 adultscore=0 mlxscore=0 bulkscore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2408220000 definitions=main-2409260105 X-Proofpoint-ORIG-GUID: yWo1eSCGuw4RVpK28_4sP2lbvrlF5jKQ X-Proofpoint-GUID: yWo1eSCGuw4RVpK28_4sP2lbvrlF5jKQ X-Rspamd-Queue-Id: DA1A8C0013 X-Stat-Signature: sgg1sjm8n83o8g4fr1ey64gq4qqft9gp X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1727363447-242598 X-HE-Meta: U2FsdGVkX18P29cvd0kgh3EEj7Aup+IKwj23qChGvmllkxGUREo9ypHU3sONPHSts3M6WHisfXYdsfvnJSAf3Dijnq39IviM5WYp6wLmECky3rXDKQ5zALqrGg0kPvHS4GFb0oYIotZFJt9BQq4zKYXe5codV5pfUkuBES3gGZJZ8b/UTzzJ2OnnsUZvkgqbDSlI1VitBKn59b3DY7zR7bxCifFqZnwT6XI/kW5qzumjWMKrLGCcbx3hqm5NafDfVhTRDVn0DX5x6qrylHxqVRegoaEBCk3N7QlUp5YFMqzR61ac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ZHXxTcSUkHsWLaCHZvT2PLwYQxe0x5FQRuk2QpjVvvo8CIPHMg05qkJFn8Qjsvt9/MUvap2VnSzso2ayIbnoUqARc/YgUxTeb+4MtCXODfiTU5vZA1XnDsDxbrJsRBhPmVogccl9PCN4ljVYVNmdifnZosED1NGnNlv7uJGBDboDIjQYSGYqSkgsqLxJToLCOq9qf9XioxxKpbxYj4Q3Kcwg43Ia0RKwcx/YHIj3HRQKNMyAJDNgWKn5EZieSr+uxbEEo387UOECHYz/Fl+n1aL 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 process_madvise() call was introduced in commit ecb8ac8b1f14 ("mm/madvise: introduce process_madvise() syscall: an external memory hinting API") as a means of performing madvise() operations on another process. However, as it provides the means by which to perform multiple madvise() operations in a batch via an iovec, it is useful to utilise the same interface for performing operations on the current process rather than a remote one. Commit 22af8caff7d1 ("mm/madvise: process_madvise() drop capability check if same mm") removed the need for a caller invoking process_madvise() on its own pidfd to possess the CAP_SYS_NICE capability, however this leaves the restrictions on operation in place. Resolve this by only applying the restriction on operations when accessing a remote process. Moving forward we plan to implement a simpler means of specifying this condition other than needing to establish a self pidfd, perhaps in the form of a sentinel pidfd. Also take the opportunity to refactor the system call implementation abstracting the vectorised operation. Signed-off-by: Lorenzo Stoakes Acked-by: Shakeel Butt Acked-by: Vlastimil Babka --- v3: * Avoid introducing PR_MADV_SELF and defer a non-pidfd version until later. v2: * Fix silly mistake referencing unassigned mm variable. * Add PR_MADV_SELF to architecture-specific mman headers. https://lore.kernel.org/linux-mm/9cf0e96d-287f-4749-ba85-8414c06aa54c@lucifer.local/ v1: https://lore.kernel.org/all/cover.1727106751.git.lorenzo.stoakes@oracle.com/ mm/madvise.c | 55 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 19 deletions(-) -- 2.46.0 diff --git a/mm/madvise.c b/mm/madvise.c index 50d223ab3894..e871a72a6c32 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -1208,7 +1208,8 @@ madvise_behavior_valid(int behavior) } } -static bool process_madvise_behavior_valid(int behavior) +/* Can we invoke process_madvise() on a remote mm for the specified behavior? */ +static bool process_madvise_remote_valid(int behavior) { switch (behavior) { case MADV_COLD: @@ -1477,6 +1478,28 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior) return do_madvise(current->mm, start, len_in, behavior); } +/* Perform an madvise operation over a vector of addresses and lengths. */ +static ssize_t vector_madvise(struct mm_struct *mm, struct iov_iter *iter, + int behavior) +{ + ssize_t ret = 0; + size_t total_len; + + total_len = iov_iter_count(iter); + + while (iov_iter_count(iter)) { + ret = do_madvise(mm, (unsigned long)iter_iov_addr(iter), + iter_iov_len(iter), behavior); + if (ret < 0) + break; + iov_iter_advance(iter, iter_iov_len(iter)); + } + + ret = (total_len - iov_iter_count(iter)) ? : ret; + + return ret; +} + SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec, size_t, vlen, int, behavior, unsigned int, flags) { @@ -1486,7 +1509,6 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec, struct iov_iter iter; struct task_struct *task; struct mm_struct *mm; - size_t total_len; unsigned int f_flags; if (flags != 0) { @@ -1504,11 +1526,6 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec, goto free_iov; } - if (!process_madvise_behavior_valid(behavior)) { - ret = -EINVAL; - goto release_task; - } - /* Require PTRACE_MODE_READ to avoid leaking ASLR metadata. */ mm = mm_access(task, PTRACE_MODE_READ_FSCREDS); if (IS_ERR(mm)) { @@ -1516,26 +1533,26 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec, goto release_task; } + /* + * We need only perform this check if we are attempting to manipulate a + * remote process's address space. + */ + if (mm != current->mm && !process_madvise_remote_valid(behavior)) { + ret = -EINVAL; + goto release_mm; + } + /* * Require CAP_SYS_NICE for influencing process performance. Note that - * only non-destructive hints are currently supported. + * only non-destructive hints are currently supported for remote + * processes. */ if (mm != current->mm && !capable(CAP_SYS_NICE)) { ret = -EPERM; goto release_mm; } - total_len = iov_iter_count(&iter); - - while (iov_iter_count(&iter)) { - ret = do_madvise(mm, (unsigned long)iter_iov_addr(&iter), - iter_iov_len(&iter), behavior); - if (ret < 0) - break; - iov_iter_advance(&iter, iter_iov_len(&iter)); - } - - ret = (total_len - iov_iter_count(&iter)) ? : ret; + ret = vector_madvise(mm, &iter, behavior); release_mm: mmput(mm);