From patchwork Fri Mar 20 20:27:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Edlinger X-Patchwork-Id: 11450301 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 37D821668 for ; Fri, 20 Mar 2020 20:27:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 048722072C for ; Fri, 20 Mar 2020 20:27:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 048722072C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=hotmail.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 394DD6B0072; Fri, 20 Mar 2020 16:27:31 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 36C1A6B0073; Fri, 20 Mar 2020 16:27:31 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 281926B0074; Fri, 20 Mar 2020 16:27:31 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0007.hostedemail.com [216.40.44.7]) by kanga.kvack.org (Postfix) with ESMTP id 0FFD26B0072 for ; Fri, 20 Mar 2020 16:27:31 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id BAB5B180AD801 for ; Fri, 20 Mar 2020 20:27:30 +0000 (UTC) X-FDA: 76616875860.14.shake28_75278af2580b X-Spam-Summary: 2,0,0,9b86cdafa871906d,d41d8cd98f00b204,bernd.edlinger@hotmail.de,,RULES_HIT:41:355:379:800:854:960:988:989:1260:1261:1277:1311:1313:1314:1345:1359:1381:1437:1515:1516:1518:1535:1541:1593:1594:1683:1711:1730:1747:1777:1792:2194:2199:2393:2559:2562:2895:3138:3139:3140:3141:3142:3352:3865:3866:3867:3868:3871:4118:5007:6737:6738:7652:10004:10400:11026:11473:11658:11914:12043:12048:12160:12296:12297:12438:12519:12555:12760:12895:13069:13311:13357:14096:14097:14181:14394:14721:21080:21444:21627:21789:21990:30054:30055,0,RBL:40.92.74.91:@hotmail.de:.lbl8.mailshell.net-66.100.201.100 62.18.114.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: shake28_75278af2580b X-Filterd-Recvd-Size: 7920 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-oln040092074091.outbound.protection.outlook.com [40.92.74.91]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Fri, 20 Mar 2020 20:27:30 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KfTTtTDLzVGlP6IpxttbO3bF26EF55KTvi1mKHJRQbpjkIKZ1XD7rWquAvsIggfef252zUg0cdLeXNen8amacgG0fPGgGZwujIMhecKPJ5oGAc9k0mGYGXPY/7Vg/6i08rq7NOPgH5AqcKcy+dlJkBSVtxDYYCXzg+Jtr8jxSLITJ1V4y6M2Y9wKhyyquv8TrXmge8wyy1Y64vqjPHHGMgNuri+GnxC+Fuy6XyUatdnYp5FpK6AkYzfnIYuBCWDqp8Qis7HOSf0P9jdiYhvKOTyUnkhQXcmEG8DplWEKk924p1YQiydAgo8TMrvOQHKg1tWubog3DfFP54NQQ370cw== 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=HJmRER3UcnVdcj+aJDElOb9vgVkrVlofI7o1Kn1NZ+g=; b=OjvuwOsfgwXe/Bi2GoUO5lzHvitaMKZFxNo88ttaeA1VJ5EwZyehC5oRfASu2kwUqEJ0BwpXKq6JyU+gOfR5pwadb7T+VrqJlI/zb7auHTLCuCfZsT1PvqRapTf1iLEVjdithSDit7T31hhdUlG+Jf7Z9Utg78IelKwpLjelet0ZhPJAS+x6fMW+gygO4gOAoQacT9I82UlQn3a4JWomxQBbBR397C9mSdYt4wDG5zyQ9q3e9SvKQnlbpnTmvyP/g0iArOMi7VUo3KqUQT4M2o9p+YWuVLEg4amMcms2F1aGHbOvj+Bop2OS8Lp4bCwbhYX7+LZBkzRtcEA6VAdHig== 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 DB3EUR04FT027.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0c::37) by DB3EUR04HT111.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0c::350) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2814.13; Fri, 20 Mar 2020 20:27:28 +0000 Received: from AM6PR03MB5170.eurprd03.prod.outlook.com (10.152.24.52) by DB3EUR04FT027.mail.protection.outlook.com (10.152.24.122) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2814.13 via Frontend Transport; Fri, 20 Mar 2020 20:27:28 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:56C330A9A70DB96EE735B408EEFA331D3C2CA990C9D56D6C00ADCC5B62BA98E2;UpperCasedChecksum:40BFEC8257A7B82F6AC6470234101DDC8AAE1F51F1F06FA13E5E4BA5789D764A;SizeAsReceived:9415;Count:49 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.2835.017; Fri, 20 Mar 2020 20:27:28 +0000 From: Bernd Edlinger Subject: [PATCH v6 11/16] proc: Use new infrastructure to fix deadlocks in execve To: Greg Kroah-Hartman , Kirill Tkhai , "Eric W. Biederman" , 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 , 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: <077b63b7-6f5e-aa8e-bf96-a586b481cc46@hotmail.de> Message-ID: Date: Fri, 20 Mar 2020 21:27:24 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 In-Reply-To: <077b63b7-6f5e-aa8e-bf96-a586b481cc46@hotmail.de> Content-Language: en-US X-ClientProxiedBy: ZR0P278CA0019.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:1c::6) To AM6PR03MB5170.eurprd03.prod.outlook.com (2603:10a6:20b:ca::23) X-Microsoft-Original-Message-ID: <60c281a3-5bd0-f01b-60b4-398221fffe5c@hotmail.de> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [192.168.1.101] (92.77.140.102) by ZR0P278CA0019.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:1c::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2835.18 via Frontend Transport; Fri, 20 Mar 2020 20:27:26 +0000 X-Microsoft-Original-Message-ID: <60c281a3-5bd0-f01b-60b4-398221fffe5c@hotmail.de> X-TMN: [8o2JbL35JfHG0CF/Web1fABngrpEmOdV] X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 49 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: cdc9e6e5-2ba8-4d82-2482-08d7cd0d1bca X-MS-TrafficTypeDiagnostic: DB3EUR04HT111: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: f+r5n9VUw8/8dIYTVPwzSuxAoiqy0i1lWKx7X4I6i5tR1PYdAnWgmOPcbXUmo1HlMc7oozVdm2GSC7vHKlLMCut0OKM1LFBvKFFfxhGTKXubi1xC1B8CS67Xz2qWlS31C1FjKfmuk9DnjI4vAuMf3ks+I0KKexXy2RI3tPNTUP6C911F/D4CzY6yaYiSUiUx X-MS-Exchange-AntiSpam-MessageData: n+mZZ6uXUYaPFGdRojpj8SG9eSTGW3cNDDoMytoIZ+8yVLRZ86E45SQH2br9uEgTixeRPDQYusUz5p4E+iK81RPW7+EMH+HoJ9unb+JPTBE2Cn2qURpVQIz8OY9+I7BfK0e1fVRmXIg1pbiFniJtGA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: cdc9e6e5-2ba8-4d82-2482-08d7cd0d1bca X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Mar 2020 20:27:28.3484 (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: DB3EUR04HT111 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: 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 --- 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 c7c6427..fed76abf 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -405,11 +405,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; @@ -417,7 +417,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