From patchwork Tue Mar 10 17:45:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Edlinger X-Patchwork-Id: 11429981 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8DA9114E3 for ; Tue, 10 Mar 2020 17:45:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6E49622525 for ; Tue, 10 Mar 2020 17:45:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726530AbgCJRpS (ORCPT ); Tue, 10 Mar 2020 13:45:18 -0400 Received: from mail-oln040092073033.outbound.protection.outlook.com ([40.92.73.33]:20294 "EHLO EUR04-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726414AbgCJRpS (ORCPT ); Tue, 10 Mar 2020 13:45:18 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gQZVl/1n/5UYx0y4NOGyFbjmxgEBUJ6uczThMreoCeXfSJLiPK8FtnGvwIm/j7TiXD9yV959v87qydwyRvIupUyjcqys6r+NXM6FTAtcam5M2kvk7mB8YafFve1oGeKBZ+n86lAZ8tDNTcnQpjC0x8pGGOlriElTyjztCrWUIE1U42n3OuZ7LqxBvteQ5Vj0GSToZTiAjk6e7R/SiiTv4raf2GOFXlh7HUUIAskfja0XFvP/o4iKzn0HBgNVlXI6oYXoT9Ur1VhrnrOztmfGAO00NWyoz8kgA3Cf5hY0gmdWKB4AuJrh4flfEWFyrJuIldVzhT1OWRyfzQWPxynBJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KzW+vQiK0ldXBGN1Gu1zo93EbVuHDeiMyTvYP/RCPok=; b=ndfMms03pIShl9Jagnl2Y+jE9uQ50YPvwZ5z57agv/yPvDxTU/jbvXN6cekIkV9haRnHX6U2Z18HdjhTdcnWhT1lGcCeRYmeYN20TI+rvL/wrvEc9T61AX6R4a6j68rlB0lQvz9rrdUwYmzOpiInbIiwrnOgQj4O46FU9nQCnx1yyh9xSC5Dqs5zFfvs2q2/kqt5+mLdxrcoicInxMriC4NW4K5sp1bX9tHD2feGz+Y99P8gwEEOhw62CPapUwzf/2SClKn3n5UUevJLxff+TVEmTzJci25vGob9Q00hyON4cqQ0HXAXcY7tc95jaxBAcNWwL2Lopte220VOnMHRnA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=hotmail.de; dmarc=pass action=none header.from=hotmail.de; dkim=pass header.d=hotmail.de; arc=none Received: from VI1EUR04FT026.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0e::39) by VI1EUR04HT138.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0e::146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.11; Tue, 10 Mar 2020 17:45:14 +0000 Received: from AM6PR03MB5170.eurprd03.prod.outlook.com (10.152.28.55) by VI1EUR04FT026.mail.protection.outlook.com (10.152.28.127) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.11 via Frontend Transport; Tue, 10 Mar 2020 17:45:14 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:B58AEAFA45C949DEBE05B6186D4DBF3A704E14AB315E4E49940646D624D8F720;UpperCasedChecksum:D4166CB02D7CDD15B20499B717F39622D99747916CD714472EDDFFCD7D29679A;SizeAsReceived:10317;Count:50 Received: from AM6PR03MB5170.eurprd03.prod.outlook.com ([fe80::1956:d274:cab3:b4dd]) by AM6PR03MB5170.eurprd03.prod.outlook.com ([fe80::1956:d274:cab3:b4dd%6]) with mapi id 15.20.2793.013; Tue, 10 Mar 2020 17:45:14 +0000 From: Bernd Edlinger Subject: [PATCH 1/4] kernel/kcmp.c: Use new infrastructure to fix deadlocks in execve To: "Eric W. Biederman" Cc: Christian Brauner , Kees Cook , Jann Horn , Jonathan Corbet , Alexander Viro , Andrew Morton , Alexey Dobriyan , Thomas Gleixner , Oleg Nesterov , Frederic Weisbecker , Andrei Vagin , Ingo Molnar , "Peter Zijlstra (Intel)" , Yuyang Du , David Hildenbrand , Sebastian Andrzej Siewior , Anshuman Khandual , David Howells , James Morris , Greg Kroah-Hartman , Shakeel Butt , Jason Gunthorpe , Christian Kellner , Andrea Arcangeli , Aleksa Sarai , "Dmitry V. Levin" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-mm@kvack.org" , "stable@vger.kernel.org" , "linux-api@vger.kernel.org" References: <87tv32cxmf.fsf_-_@x220.int.ebiederm.org> <87v9ne5y4y.fsf_-_@x220.int.ebiederm.org> <87zhcq4jdj.fsf_-_@x220.int.ebiederm.org> <878sk94eay.fsf@x220.int.ebiederm.org> <87r1y12yc7.fsf@x220.int.ebiederm.org> <87k13t2xpd.fsf@x220.int.ebiederm.org> <87d09l2x5n.fsf@x220.int.ebiederm.org> <871rq12vxu.fsf@x220.int.ebiederm.org> <877dzt1fnf.fsf@x220.int.ebiederm.org> <875zfcxlwy.fsf@x220.int.ebiederm.org> Message-ID: Date: Tue, 10 Mar 2020 18:45:11 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 In-Reply-To: <875zfcxlwy.fsf@x220.int.ebiederm.org> Content-Language: en-US X-ClientProxiedBy: ZR0P278CA0020.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:1c::7) To AM6PR03MB5170.eurprd03.prod.outlook.com (2603:10a6:20b:ca::23) X-Microsoft-Original-Message-ID: <030a2087-f995-327b-ac8f-3e2a0fda1c37@hotmail.de> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [192.168.1.101] (92.77.140.102) by ZR0P278CA0020.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:1c::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.15 via Frontend Transport; Tue, 10 Mar 2020 17:45:12 +0000 X-Microsoft-Original-Message-ID: <030a2087-f995-327b-ac8f-3e2a0fda1c37@hotmail.de> X-TMN: [wZuXIGcgdH2Q8W6qKNBoXYGYM/eVthBC] X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 50 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 99a48d4d-ff98-45a9-c82e-08d7c51ac9a5 X-MS-TrafficTypeDiagnostic: VI1EUR04HT138: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PdIIkda5kaGr6lCbIVe8507xJuc7fBfMn0QYZmW8k4t3Q3MbCWDJMMDiWdMmLtl2PFE/YUWOV1FNDYwyRFfzv2vwYeeLLX4U6AlNjdNlzH+bhhOshoQajl8XBjMVIFCeII80crHptCTpj0uLg6yiqXWHj5saLcQQbtl7rsNNXmUiYqStr3jojGpkIk1swnji X-MS-Exchange-AntiSpam-MessageData: HXLp8eDJv28UtDSkPAAw0rFQcA0ga+EyhrywohzN1kVn0SSi/oegskaWg6Gr4IT9WANm82RyL0ANRHysmEbj+7+qV1s92Cl2DdD5/lj9bCJT0x2UzbSqhrIgG6/7OfnS8+SnsUVr7GQJwQY2LY27eg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 99a48d4d-ff98-45a9-c82e-08d7c51ac9a5 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2020 17:45:14.2359 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1EUR04HT138 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This changes kcmp_epoll_target to use the new exec_update_mutex instead of cred_guard_mutex. This should be safe, as the credentials are only used for reading, and furthermore ->mm and ->sighand are updated on execve, but only under the new exec_update_mutex. Signed-off-by: Bernd Edlinger --- kernel/kcmp.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel/kcmp.c b/kernel/kcmp.c index a0e3d7a..b3ff928 100644 --- a/kernel/kcmp.c +++ b/kernel/kcmp.c @@ -173,8 +173,8 @@ static int kcmp_epoll_target(struct task_struct *task1, /* * One should have enough rights to inspect task details. */ - ret = kcmp_lock(&task1->signal->cred_guard_mutex, - &task2->signal->cred_guard_mutex); + ret = kcmp_lock(&task1->signal->exec_update_mutex, + &task2->signal->exec_update_mutex); if (ret) goto err; if (!ptrace_may_access(task1, PTRACE_MODE_READ_REALCREDS) || @@ -229,8 +229,8 @@ static int kcmp_epoll_target(struct task_struct *task1, } err_unlock: - kcmp_unlock(&task1->signal->cred_guard_mutex, - &task2->signal->cred_guard_mutex); + kcmp_unlock(&task1->signal->exec_update_mutex, + &task2->signal->exec_update_mutex); err: put_task_struct(task1); put_task_struct(task2); From patchwork Tue Mar 10 17:45:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Edlinger X-Patchwork-Id: 11429985 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A551214E3 for ; Tue, 10 Mar 2020 17:45:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 855DF22522 for ; Tue, 10 Mar 2020 17:45:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726899AbgCJRpj (ORCPT ); Tue, 10 Mar 2020 13:45:39 -0400 Received: from mail-oln040092075065.outbound.protection.outlook.com ([40.92.75.65]:26510 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726436AbgCJRpj (ORCPT ); Tue, 10 Mar 2020 13:45:39 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=L61N0EpFZVhcAGZNAUTWe3t9jAQh6h71YDzxG3GiXnvp7B4TO3FFCUtkLXdxjGwPL+DKK5KFLZVcT5oLkzX0POsnd2eEqn2VSbcqJO/dFNwdhfSdMBe8c8eCJ3WU7D6cGmKQiCt0hDx+2fambNZA1juKt9lTZlAxO3EsW9NcxnfM1vVeLik8v5UQ93tnrwrQZsqxGmf3/oW5H4lVOjNS+Om0E4WsazorLY3QCem7ZtwvSILIwRHDt3cg7yDIzxqpPuZsILH0vzBCR1q75v3KCudvQQYiOXC02qXUfX1qizskt3tK7FcSdenIcyb5P1iklAIUe8RxXnKZJsmEHa+jsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RYx/eGMQRk15p5KGn00JKRBBncFFuzv3ujSL4CsQZpM=; b=EXsEyXMGWkxyHsb9kJYmr5PnYiHtIKC0VwGUyf6dwBbSS8xvAEgmug7b8+/UVvE802ZLH58YpoaYU9ZCfNdwV4ro51obCF2zurEJTH98J7Vzjelo4t4JDMSGzydC50AIu1WcbAJ8xRH+zooBPZ7McKKPyjMuwh+58mc8QKtk0qM60tbPOzVsK3JEOI+hkzm9CmfDkiUpvMJdw8nPRb1ZewVehxNV+pqAhxsCbQTtCLuwPyPsNF6NUXTggEhxr8QG+TFqCjwIH6SnGNuLmLWlSiBZME0BMfDzt8Q0urTZxM6KHi7+kr104IdEUEaLAoOeeNVrsUocaDqIhHzrVxkKGA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=hotmail.de; dmarc=pass action=none header.from=hotmail.de; dkim=pass header.d=hotmail.de; arc=none Received: from VI1EUR04FT026.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0e::39) by VI1EUR04HT214.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0e::340) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.11; Tue, 10 Mar 2020 17:45:35 +0000 Received: from AM6PR03MB5170.eurprd03.prod.outlook.com (10.152.28.55) by VI1EUR04FT026.mail.protection.outlook.com (10.152.28.127) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.11 via Frontend Transport; Tue, 10 Mar 2020 17:45:35 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:709DA8CC4D739A346F6F10415B77C549C2C75E51CF8174E86C50DAD72C3A9D6D;UpperCasedChecksum:A17C6A373AF089981264002FD010737C4107A98A0BEEFBD59F21DD3FA2E8BA2A;SizeAsReceived:10315;Count:50 Received: from AM6PR03MB5170.eurprd03.prod.outlook.com ([fe80::1956:d274:cab3:b4dd]) by AM6PR03MB5170.eurprd03.prod.outlook.com ([fe80::1956:d274:cab3:b4dd%6]) with mapi id 15.20.2793.013; Tue, 10 Mar 2020 17:45:35 +0000 From: Bernd Edlinger Subject: [PATCH 2/4] proc: Use new infrastructure to fix deadlocks in execve To: "Eric W. Biederman" Cc: Christian Brauner , Kees Cook , Jann Horn , Jonathan Corbet , Alexander Viro , Andrew Morton , Alexey Dobriyan , Thomas Gleixner , Oleg Nesterov , Frederic Weisbecker , Andrei Vagin , Ingo Molnar , "Peter Zijlstra (Intel)" , Yuyang Du , David Hildenbrand , Sebastian Andrzej Siewior , Anshuman Khandual , David Howells , James Morris , Greg Kroah-Hartman , Shakeel Butt , Jason Gunthorpe , Christian Kellner , Andrea Arcangeli , Aleksa Sarai , "Dmitry V. Levin" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-mm@kvack.org" , "stable@vger.kernel.org" , "linux-api@vger.kernel.org" References: <87tv32cxmf.fsf_-_@x220.int.ebiederm.org> <87v9ne5y4y.fsf_-_@x220.int.ebiederm.org> <87zhcq4jdj.fsf_-_@x220.int.ebiederm.org> <878sk94eay.fsf@x220.int.ebiederm.org> <87r1y12yc7.fsf@x220.int.ebiederm.org> <87k13t2xpd.fsf@x220.int.ebiederm.org> <87d09l2x5n.fsf@x220.int.ebiederm.org> <871rq12vxu.fsf@x220.int.ebiederm.org> <877dzt1fnf.fsf@x220.int.ebiederm.org> <875zfcxlwy.fsf@x220.int.ebiederm.org> Message-ID: Date: Tue, 10 Mar 2020 18:45:32 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 In-Reply-To: <875zfcxlwy.fsf@x220.int.ebiederm.org> Content-Language: en-US X-ClientProxiedBy: ZR0P278CA0035.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:1c::22) To AM6PR03MB5170.eurprd03.prod.outlook.com (2603:10a6:20b:ca::23) X-Microsoft-Original-Message-ID: <4dedec91-5e43-7ab6-31f6-0c4d4c0b961e@hotmail.de> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [192.168.1.101] (92.77.140.102) by ZR0P278CA0035.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:1c::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.15 via Frontend Transport; Tue, 10 Mar 2020 17:45:33 +0000 X-Microsoft-Original-Message-ID: <4dedec91-5e43-7ab6-31f6-0c4d4c0b961e@hotmail.de> X-TMN: [LVSYAfv/7I+AspDEth9Kxn0HT/mwPT3U] X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 50 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: b2ab4bba-4122-4fc8-38ff-08d7c51ad618 X-MS-TrafficTypeDiagnostic: VI1EUR04HT214: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vo2uMPUIIfj1yyvT3Xy0XHDknalHYieujECBOOVKUv6tA4N34c+kC2nf/gquQqEAlTZ7/UALtAm0dT2ztA5LgSwLNX+DeydeSP6yX/HGFDKKKKPFGYZPDvW3gQfHvKFYqsH788Hl8ehKOGlqnWB8LLyYkwK6CuyAz145FMx/ZsRF9B54U+wVzVt0BHfrJhbB X-MS-Exchange-AntiSpam-MessageData: dstz6T4CN9AkqZrg8y0kV0yO5Y8uR9XpzwTiYYjO16n0O/oVPuOa69DiH81/WGJA+ScjyodBxSM4EIWfwJ7ErQ2lWMQN8GqZR3AUaaZvYud2bYKkfYTvea8RLQhFi31R38+gi+xTNYoFBCE0y2+zgA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: b2ab4bba-4122-4fc8-38ff-08d7c51ad618 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2020 17:45:35.0846 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1EUR04HT214 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This changes lock_trace to use the new exec_update_mutex instead of cred_guard_mutex. This fixes possible deadlocks when the trace is accessing /proc/$pid/stack for instance. This should be safe, as the credentials are only used for reading, and task->mm is updated on execve under the new exec_update_mutex. Signed-off-by: Bernd Edlinger Reviewed-by: Kees Cook --- fs/proc/base.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index ebea950..4fdfe4f 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -403,11 +403,11 @@ static int proc_pid_wchan(struct seq_file *m, struct pid_namespace *ns, static int lock_trace(struct task_struct *task) { - int err = mutex_lock_killable(&task->signal->cred_guard_mutex); + int err = mutex_lock_killable(&task->signal->exec_update_mutex); if (err) return err; if (!ptrace_may_access(task, PTRACE_MODE_ATTACH_FSCREDS)) { - mutex_unlock(&task->signal->cred_guard_mutex); + mutex_unlock(&task->signal->exec_update_mutex); return -EPERM; } return 0; @@ -415,7 +415,7 @@ static int lock_trace(struct task_struct *task) static void unlock_trace(struct task_struct *task) { - mutex_unlock(&task->signal->cred_guard_mutex); + mutex_unlock(&task->signal->exec_update_mutex); } #ifdef CONFIG_STACKTRACE From patchwork Tue Mar 10 17:45:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Edlinger X-Patchwork-Id: 11429989 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8A46C92A for ; Tue, 10 Mar 2020 17:45:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6AFD3222C3 for ; Tue, 10 Mar 2020 17:45:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727077AbgCJRpz (ORCPT ); Tue, 10 Mar 2020 13:45:55 -0400 Received: from mail-oln040092074100.outbound.protection.outlook.com ([40.92.74.100]:26357 "EHLO EUR04-DB3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726436AbgCJRpy (ORCPT ); Tue, 10 Mar 2020 13:45:54 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bKgzFyPeDRQvAqZbHDTA6PC1nkisjfygtDL7xDQwxcs8c6kW0bEHLUdg4+WxQKfxoE/MXpC6KV/FvSyY5G6dvHD3mmg1nK5lg9aHJGO1EGU0CaIa+NayBBFRGKT/7fSjA3OKJDpYKq2V2Jv+b4PYFf8ZkY1/pZgR+OT3pYdJU74yXeLWFv3jJn2Fq6qeTbtzMiyd/pTSXCnVYOHxyxXYc11QqJCTC+bktozkO1qhbrdzzbKPTPhKbLb0aym6Vy1IhHiKnI+jC1sgs+/3FOnAJ68WB1QtzsF34DJxI17encF4CGaGYIihfpr1TeEBiS6WLwtJjdIFvXj/fU6YD4jjtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KOA+i8XcR3dkQpEfOU6A2i9UgdiEg1obJk7wzBeLiTw=; b=Aba/3kK5VOQWmRrWRs38dX1EjIyEUV8wL57CbvHTjem8V9bBN9Dv0TuzxNmGcoOo6/HC6abv77QQVGTiHZi4TqpLmEblUhIMJlWBdfezOKK/BbHslEb0ClBWkHkZqH40PbP4m/ExUmyaUGvXqeDgPPtkMys8G1Tvnu1oQThrC0Ev+97PmbYWBdfBSZN9+H1L1+/9TdfN4gBWKlIs9peRjwiN7AKOzYfd2rwMgCBBrBJSnRmvWhK1AmGGLV9oXMNQJ3CIDkWigN5sWtOa3YXs6K4ZXFWJGoa1CxUE/YmLftgo1Wm0pxYL4wHIxsL8I16nxXHPoySXLBX+Ge06wkk2zg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=hotmail.de; dmarc=pass action=none header.from=hotmail.de; dkim=pass header.d=hotmail.de; arc=none Received: from VI1EUR04FT026.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0e::3b) by VI1EUR04HT244.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0e::347) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.11; Tue, 10 Mar 2020 17:45:50 +0000 Received: from AM6PR03MB5170.eurprd03.prod.outlook.com (10.152.28.55) by VI1EUR04FT026.mail.protection.outlook.com (10.152.28.127) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.11 via Frontend Transport; Tue, 10 Mar 2020 17:45:50 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:4AE4C90853D8DDB61D15FD78AD842565F3BCC514A17005AD0DC52AEA26DFE82C;UpperCasedChecksum:93DC566E0BA2CB19E0B93FC62F35DC63F7A4E0955B4D558E5F3153D195CD6EA1;SizeAsReceived:10341;Count:50 Received: from AM6PR03MB5170.eurprd03.prod.outlook.com ([fe80::1956:d274:cab3:b4dd]) by AM6PR03MB5170.eurprd03.prod.outlook.com ([fe80::1956:d274:cab3:b4dd%6]) with mapi id 15.20.2793.013; Tue, 10 Mar 2020 17:45:50 +0000 From: Bernd Edlinger Subject: [PATCH 3/4] proc: io_accounting: Use new infrastructure to fix deadlocks in execve To: "Eric W. Biederman" Cc: Christian Brauner , Kees Cook , Jann Horn , Jonathan Corbet , Alexander Viro , Andrew Morton , Alexey Dobriyan , Thomas Gleixner , Oleg Nesterov , Frederic Weisbecker , Andrei Vagin , Ingo Molnar , "Peter Zijlstra (Intel)" , Yuyang Du , David Hildenbrand , Sebastian Andrzej Siewior , Anshuman Khandual , David Howells , James Morris , Greg Kroah-Hartman , Shakeel Butt , Jason Gunthorpe , Christian Kellner , Andrea Arcangeli , Aleksa Sarai , "Dmitry V. Levin" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-mm@kvack.org" , "stable@vger.kernel.org" , "linux-api@vger.kernel.org" References: <87tv32cxmf.fsf_-_@x220.int.ebiederm.org> <87v9ne5y4y.fsf_-_@x220.int.ebiederm.org> <87zhcq4jdj.fsf_-_@x220.int.ebiederm.org> <878sk94eay.fsf@x220.int.ebiederm.org> <87r1y12yc7.fsf@x220.int.ebiederm.org> <87k13t2xpd.fsf@x220.int.ebiederm.org> <87d09l2x5n.fsf@x220.int.ebiederm.org> <871rq12vxu.fsf@x220.int.ebiederm.org> <877dzt1fnf.fsf@x220.int.ebiederm.org> <875zfcxlwy.fsf@x220.int.ebiederm.org> Message-ID: Date: Tue, 10 Mar 2020 18:45:47 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 In-Reply-To: <875zfcxlwy.fsf@x220.int.ebiederm.org> Content-Language: en-US X-ClientProxiedBy: ZR0P278CA0028.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:1c::15) To AM6PR03MB5170.eurprd03.prod.outlook.com (2603:10a6:20b:ca::23) X-Microsoft-Original-Message-ID: <300abca9-375c-58ec-5cef-cbf1406a4464@hotmail.de> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [192.168.1.101] (92.77.140.102) by ZR0P278CA0028.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:1c::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.14 via Frontend Transport; Tue, 10 Mar 2020 17:45:48 +0000 X-Microsoft-Original-Message-ID: <300abca9-375c-58ec-5cef-cbf1406a4464@hotmail.de> X-TMN: [XCvP3XhmcvfDfjTzxvAK99X2UOOLZOyp] X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 50 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: efb675c5-cbfb-4af6-12cd-08d7c51adf22 X-MS-TrafficTypeDiagnostic: VI1EUR04HT244: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /ZXrqPBjWbqOhkxrLTTusV/4/SaJoZmBMpE69amyQ2X7XgH6Wkmjuksf9e4l+mL34VfzmRAPiDoWPbzpD6lOt8nTC47JMpm2FnosaaJORYu7nakXyXB5rGhJM1723qUr5kPkPdFJDmfpqfa2UUSxIKbuU1B9NXAH8xAV2M1SY/1pmMGbKSL9KHI0Gsi1j3BY X-MS-Exchange-AntiSpam-MessageData: XUVtpUlamwAcWN3pgCDDxgnnyUIjSy/DoS3WNkkxjMEC5PMbEKiFoca7ABgSePO8N+zF7Lu4HcdIarJVa9FTb1sDw2iBVjG2Zc9sOu37RDb5Ha5tDA8wDlFpEpchBxs2uLif+MKQ/wZBjXIpF5/5Mg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: efb675c5-cbfb-4af6-12cd-08d7c51adf22 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2020 17:45:50.2526 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1EUR04HT244 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This changes do_io_accounting to use the new exec_update_mutex instead of cred_guard_mutex. This fixes possible deadlocks when the trace is accessing /proc/$pid/io for instance. This should be safe, as the credentials are only used for reading. Signed-off-by: Bernd Edlinger --- fs/proc/base.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index 4fdfe4f..529d0c6 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -2770,7 +2770,7 @@ static int do_io_accounting(struct task_struct *task, struct seq_file *m, int wh unsigned long flags; int result; - result = mutex_lock_killable(&task->signal->cred_guard_mutex); + result = mutex_lock_killable(&task->signal->exec_update_mutex); if (result) return result; @@ -2806,7 +2806,7 @@ static int do_io_accounting(struct task_struct *task, struct seq_file *m, int wh result = 0; out_unlock: - mutex_unlock(&task->signal->cred_guard_mutex); + mutex_unlock(&task->signal->exec_update_mutex); return result; } From patchwork Tue Mar 10 17:45:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Edlinger X-Patchwork-Id: 11429993 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2A7D614E3 for ; Tue, 10 Mar 2020 17:46:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0C0D221D7E for ; Tue, 10 Mar 2020 17:46:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727126AbgCJRqG (ORCPT ); Tue, 10 Mar 2020 13:46:06 -0400 Received: from mail-oln040092073084.outbound.protection.outlook.com ([40.92.73.84]:31187 "EHLO EUR04-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726436AbgCJRqF (ORCPT ); Tue, 10 Mar 2020 13:46:05 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aTnb3zN2prC4Va3XgJIxKCFmt2RiY8azHtlcpueaWf777smX+ZVE2IFP6H10W3bjqWvJEUpjYyChe7H5kweBT3LzyyEbQ/vRDCGQA/Ev9OdHQHckBAXgU9fmX4rpDDrq/xzHrr8Er6T5uOJgt4HtFDvjpVfWXhDMTvNLVnGLUDDoyQvwK78eAUADeCbAVkmPbrehR0XYwFEljodjGI9TdNd/3t/HIkeKSLHeD++Zy/vZPhkiD1h9Ozl/b9n8sIsCe0g5JvtET9BMcmflYEUpL4mlHtu0o7KVNT6emPrBkbuYSsVSyzJrcofQFcjQ8F54BaaC3JYwqCwgwuGk/XAsCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=olnWKl/qROPBG2YSqCrVe3w/cuXB3vs2TZn2SEBQtS4=; b=R60ja+hO2CPqQV5wf6Jd8O9OJM9U9LPOIdU+JvQRsl7FZM2HGV85sF0A5SWa6nc14Vh7pBdc4RFyf0q9cF0HbsjeOewg8/nx12N2g+ke30m4rYegSLMRth94cUTsrWUvul0WpQxPh1XPJhUP9gdEa49Kt6Rjr39Ki25M0/Ax4yskALEK0Qp8rDl5Kc7vZ2Lq294d7NMszoWtc5yx1Mj1Edt/zvfWGXAailoYqHbrZQHNrfsQaFuACa8b6s3EQfoC8lR1NlMvoxhnZ4FBKcF/idoZG/qkXmROFp3D9Mb2p6Gg9ICHFUBr0Pq8FJoYvduct94hN4BGnCZGuRpyutVjpQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=hotmail.de; dmarc=pass action=none header.from=hotmail.de; dkim=pass header.d=hotmail.de; arc=none Received: from VI1EUR04FT026.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0e::34) by VI1EUR04HT049.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0e::71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.11; Tue, 10 Mar 2020 17:45:59 +0000 Received: from AM6PR03MB5170.eurprd03.prod.outlook.com (10.152.28.55) by VI1EUR04FT026.mail.protection.outlook.com (10.152.28.127) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.11 via Frontend Transport; Tue, 10 Mar 2020 17:45:59 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:157065CD350ECAB81667C96E5C20CAA90097A96A3C94C657D26C18E03AAAE564;UpperCasedChecksum:792CF835DAF8018F691592D716FE310F3AD2DB5F98FFECBD57CA01097CC3E226;SizeAsReceived:10287;Count:50 Received: from AM6PR03MB5170.eurprd03.prod.outlook.com ([fe80::1956:d274:cab3:b4dd]) by AM6PR03MB5170.eurprd03.prod.outlook.com ([fe80::1956:d274:cab3:b4dd%6]) with mapi id 15.20.2793.013; Tue, 10 Mar 2020 17:45:59 +0000 From: Bernd Edlinger Subject: [PATCH 4/4] perf: Use new infrastructure to fix deadlocks in execve To: "Eric W. Biederman" Cc: Christian Brauner , Kees Cook , Jann Horn , Jonathan Corbet , Alexander Viro , Andrew Morton , Alexey Dobriyan , Thomas Gleixner , Oleg Nesterov , Frederic Weisbecker , Andrei Vagin , Ingo Molnar , "Peter Zijlstra (Intel)" , Yuyang Du , David Hildenbrand , Sebastian Andrzej Siewior , Anshuman Khandual , David Howells , James Morris , Greg Kroah-Hartman , Shakeel Butt , Jason Gunthorpe , Christian Kellner , Andrea Arcangeli , Aleksa Sarai , "Dmitry V. Levin" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-mm@kvack.org" , "stable@vger.kernel.org" , "linux-api@vger.kernel.org" References: <87tv32cxmf.fsf_-_@x220.int.ebiederm.org> <87v9ne5y4y.fsf_-_@x220.int.ebiederm.org> <87zhcq4jdj.fsf_-_@x220.int.ebiederm.org> <878sk94eay.fsf@x220.int.ebiederm.org> <87r1y12yc7.fsf@x220.int.ebiederm.org> <87k13t2xpd.fsf@x220.int.ebiederm.org> <87d09l2x5n.fsf@x220.int.ebiederm.org> <871rq12vxu.fsf@x220.int.ebiederm.org> <877dzt1fnf.fsf@x220.int.ebiederm.org> <875zfcxlwy.fsf@x220.int.ebiederm.org> Message-ID: Date: Tue, 10 Mar 2020 18:45:56 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 In-Reply-To: <875zfcxlwy.fsf@x220.int.ebiederm.org> Content-Language: en-US X-ClientProxiedBy: FRYP281CA0005.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::15) To AM6PR03MB5170.eurprd03.prod.outlook.com (2603:10a6:20b:ca::23) X-Microsoft-Original-Message-ID: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [192.168.1.101] (92.77.140.102) by FRYP281CA0005.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.15 via Frontend Transport; Tue, 10 Mar 2020 17:45:57 +0000 X-Microsoft-Original-Message-ID: X-TMN: [PsiCRHURkwuV3QcRtzZCs1L6kQTGErPj] X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 50 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 4169ac3b-8718-4076-5a5c-08d7c51ae47b X-MS-TrafficTypeDiagnostic: VI1EUR04HT049: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6V61Vwd71eCV5/xyqr6zFGWGkmdr0e/2xpXtwaqSADHJnCfjSq5tp0f+zozp1GpwgWCF23E5eYpBtYEOD6HiFcoTdii9XjpbkyP+/Si0MDbHUEVE5j5nT4T9iMJ3VlylqLSfT8Tk5ogmNDHNRhAHZkVJjuibHp9Hc9aL44OesT3ysLdMr/xVtT5ZcskSlKDt X-MS-Exchange-AntiSpam-MessageData: ZVT8iy5lQXVmz7CVP9D2H8Ed7OsWTSXwudkpB0jQF3LLZyNBmXjvv8l5ji3Fu5pnZh8sL+9tJw7u0581+WfG2gbDhAtuVhitJrkqaoAy6YuJSgPRCBcq0OiiC1Qo19OLJ2pDrEQTNBN1qa5ZGFs9/w== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4169ac3b-8718-4076-5a5c-08d7c51ae47b X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2020 17:45:59.2303 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1EUR04HT049 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This changes perf_event_set_clock to use the new exec_update_mutex instead of cred_guard_mutex. This should be safe, as the credentials are only used for reading. Signed-off-by: Bernd Edlinger --- kernel/events/core.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index 2173c23..c37f6eb 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -1248,7 +1248,7 @@ static void put_ctx(struct perf_event_context *ctx) * function. * * Lock order: - * cred_guard_mutex + * exec_update_mutex * task_struct::perf_event_mutex * perf_event_context::mutex * perf_event::child_mutex; @@ -11254,14 +11254,14 @@ static int perf_event_set_clock(struct perf_event *event, clockid_t clk_id) } if (task) { - err = mutex_lock_interruptible(&task->signal->cred_guard_mutex); + err = mutex_lock_interruptible(&task->signal->exec_update_mutex); if (err) goto err_task; /* * Reuse ptrace permission checks for now. * - * We must hold cred_guard_mutex across this and any potential + * We must hold exec_update_mutex across this and any potential * perf_install_in_context() call for this new event to * serialize against exec() altering our credentials (and the * perf_event_exit_task() that could imply). @@ -11550,7 +11550,7 @@ static int perf_event_set_clock(struct perf_event *event, clockid_t clk_id) mutex_unlock(&ctx->mutex); if (task) { - mutex_unlock(&task->signal->cred_guard_mutex); + mutex_unlock(&task->signal->exec_update_mutex); put_task_struct(task); } @@ -11586,7 +11586,7 @@ static int perf_event_set_clock(struct perf_event *event, clockid_t clk_id) free_event(event); err_cred: if (task) - mutex_unlock(&task->signal->cred_guard_mutex); + mutex_unlock(&task->signal->exec_update_mutex); err_task: if (task) put_task_struct(task); @@ -11891,7 +11891,7 @@ static void perf_event_exit_task_context(struct task_struct *child, int ctxn) /* * When a child task exits, feed back event values to parent events. * - * Can be called with cred_guard_mutex held when called from + * Can be called with exec_update_mutex held when called from * install_exec_creds(). */ void perf_event_exit_task(struct task_struct *child)