Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp227656ybh; Tue, 10 Mar 2020 23:34:22 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsaVEAhnfY8ajMh1Lhcz3TVY4xWtu/+8WIygekkYOeXgMdA4qgjOKBEygh8Rc6fg5mIIlKo X-Received: by 2002:a9d:6457:: with SMTP id m23mr1194179otl.162.1583908462014; Tue, 10 Mar 2020 23:34:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1583908462; cv=pass; d=google.com; s=arc-20160816; b=XR3x6EySUTw0IEY7+NQE5nBX5dFl9y6fTkrvlEgPlRW9obUw9QF1pCL7Ez3Bd64kM1 MtsqFVbCHQ1A45KacqWHPeiEP463/XhIA01V+G++8pDnAK4GKfe7wxzc6kCkqnlEbcad ec8oDc9YKdEZvWZdmLB5MIVblTcrO4xtaA/JPZK+Bzt/eoUbDvtpaDBlBWatFOxEa4DM OGqyKcsKMWU3qxXiWKP7N2ty+d8iYTqq+7ClD+h/ZoTHM2ywzvgZh1tMp3bdASqThUSQ +WCA6imBokXy8ZyqznKzWW1+an1UTwh6vUAf7rjDHpNCkY0spVWzrXPYzX1aeCTMcRxB zTQw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:in-reply-to:user-agent:date:message-id:from :references:cc:to:subject; bh=hy2oJALEc5rzaRAd9jlN7dgF3YpzFHwMOZPWzaYkvX8=; b=CXYlkMyM6s8rQ0VWsVoTlpbLSsYXWUirD2sjcOqD71gytSd2mnPveJ0ZnP2ARTYCfZ lOBrbsQWcVoSqgW0BDl9s4RlvRncUIqBhY6HMeFy227FSqZmQXDZrLujuFMxFkiYEgBz jfrUOmiXaGrp+V14J+vrzJUf2HrM5vU+g5P84o5xFUb7XjZs1O+5Z35FZJcgONM+0G7m 4oAhhqXA6UAqnE7lFyHoT/94Tj4Q2AJgaE3b/arYyipWVz7kuUin86rVdM/ksRZ9yw8q Ew95UlpfRbGgFWox65ddqEeklDt1oJIF5p/0uxgjF1sblSwg/lkNQE2A/uQ8RKU67QUS K0kg== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=hotmail.de dkim=pass dkdomain=hotmail.de dmarc=pass fromdomain=hotmail.de); spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l20si670205otn.37.2020.03.10.23.34.09; Tue, 10 Mar 2020 23:34:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=hotmail.de dkim=pass dkdomain=hotmail.de dmarc=pass fromdomain=hotmail.de); spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728209AbgCKGdn (ORCPT + 99 others); Wed, 11 Mar 2020 02:33:43 -0400 Received: from mail-oln040092072109.outbound.protection.outlook.com ([40.92.72.109]:36565 "EHLO EUR03-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725976AbgCKGdn (ORCPT ); Wed, 11 Mar 2020 02:33:43 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BkQoyodOGuanQqn60XJdSuIGNIs45f03IhjyrDsXdDbSIXfuUJcS600Rx8jrFVL/lPzIJ1t2fIcLPIsKRvkt6hzIMQ5ToctS7v+zX7OIXUDZGMpBhR/dxuFM/+mbgwknsKmoG5xyAIThlCCFmn1BU6uUta8rOGuhcUrZur/CR0rKVAjQfPTxt7MK9jWhhAYkQYCpgJw0ns9ku2asV1gNExAU347JxkJtL2bPCLUCQkLXT89Fl4U6HEm0ohLAPe92y+hdFLxTeQoV9uv38dppeY9YeR9cNywu0DPEb+9YWT2i6VwF4GdXabxKKarvCTiJ/a8TJrIYy6niCl7tl2K4gQ== 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=hy2oJALEc5rzaRAd9jlN7dgF3YpzFHwMOZPWzaYkvX8=; b=UXrphSl8pY0asCOaJdEvc/0khUwZ2aPNI8+6NjKgfOxl5SuzF093oGocGFVbusBbLcceT8r2ULt4q38JQEqBeWpWduSGYOSP/heQPzThADhyjKZzZAPVCaxVAOLpVwDcuSuZaZqaeR1CMseikbwJkSeVjrzbM4P+cVj+BYziVf5kuHXIdvG6NwbEZehh9lk+9cKmFz42iLVJ2wtWQGB/S92zht0amnNed5gQq7gVcOi/40tdXsc9TkoFwvfgKfPtI07f+vXsVlZ36aAIYi912BO3ib+rD9CJhaMyIcrB87u+CzwblRwOsO7roEfqxD8m6nsR4fMsOmfVriKk2wMFCg== 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 DB5EUR03FT044.eop-EUR03.prod.protection.outlook.com (2a01:111:e400:7e0a::35) by DB5EUR03HT066.eop-EUR03.prod.protection.outlook.com (2a01:111:e400:7e0a::489) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2814.13; Wed, 11 Mar 2020 06:33:37 +0000 Received: from AM6PR03MB5170.eurprd03.prod.outlook.com (10.152.20.58) by DB5EUR03FT044.mail.protection.outlook.com (10.152.21.167) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2814.13 via Frontend Transport; Wed, 11 Mar 2020 06:33:37 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:9AA8DFA6C3A9D231681078A0264FE7C5FBEBCC42E563BD0A5AAD11D2D2E43FB4;UpperCasedChecksum:66486F57FF7ACD5D0388A7B1F71234B9E9C2C1BE88299172EF692828864231CD;SizeAsReceived:10301;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; Wed, 11 Mar 2020 06:33:37 +0000 Subject: Re: [PATCH v2 5/5] exec: Add a exec_update_mutex to replace cred_guard_mutex To: "Eric W. Biederman" , Jann Horn Cc: Christian Brauner , Kees Cook , 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: <87v9nlii0b.fsf@x220.int.ebiederm.org> <87a74xi4kz.fsf@x220.int.ebiederm.org> <87r1y8dqqz.fsf@x220.int.ebiederm.org> <87tv32cxmf.fsf_-_@x220.int.ebiederm.org> <87v9ne5y4y.fsf_-_@x220.int.ebiederm.org> <87zhcq4jdj.fsf_-_@x220.int.ebiederm.org> <87wo7roq2c.fsf@x220.int.ebiederm.org> <87k13roigf.fsf@x220.int.ebiederm.org> From: Bernd Edlinger Message-ID: Date: Wed, 11 Mar 2020 07:33:35 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 In-Reply-To: <87k13roigf.fsf@x220.int.ebiederm.org> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit X-ClientProxiedBy: AM0PR06CA0043.eurprd06.prod.outlook.com (2603:10a6:208:aa::20) To AM6PR03MB5170.eurprd03.prod.outlook.com (2603:10a6:20b:ca::23) X-Microsoft-Original-Message-ID: <08352807-ae9f-368a-10a8-0d284f7510ac@hotmail.de> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [192.168.1.101] (92.77.140.102) by AM0PR06CA0043.eurprd06.prod.outlook.com (2603:10a6:208:aa::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2814.13 via Frontend Transport; Wed, 11 Mar 2020 06:33:35 +0000 X-Microsoft-Original-Message-ID: <08352807-ae9f-368a-10a8-0d284f7510ac@hotmail.de> X-TMN: [IKTO541afmV/36yuJTHQVWsz8qLIFX6S] X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 50 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 585b81e9-adc5-4e44-76a4-08d7c586210a X-MS-TrafficTypeDiagnostic: DB5EUR03HT066: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xK7OpJJS8zwMqLWYqI2c0TOpKAxTlKPMIWVgvnhSfKX/f1I7LQ4IPWv+z2uU413o7USqSFvcMHro8SmLl/O9TNUi+ZwwVkfzacevSZam64DNTxUjpQ3LLBOAN66084UGGXXCglABKNDxy3HSbXuv5xPV1cWpYRK2KvRRaKvn/e3pMQ/YcnNUj6jvbbeVe3vB X-MS-Exchange-AntiSpam-MessageData: DqAC6CZ4s6U6h9IMUICg4ejxyShJTUELeTZpgzZkzTnZRym9NrkwWspoLdn+Q+LCJtNXUI0Od+XNS7P+2IZfe86tkTm+lFfWGP7uT5sG7bbqiZUzYu4JKy4CQqjp/+qLHc1qVPhsxCl6hAAQ/hKURw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 585b81e9-adc5-4e44-76a4-08d7c586210a X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2020 06:33:37.0625 (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: DB5EUR03HT066 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/11/20 1:15 AM, Eric W. Biederman wrote: > Jann Horn writes: > >> On Tue, Mar 10, 2020 at 10:33 PM Eric W. Biederman >> wrote: >>> Jann Horn writes: >>>> On Sun, Mar 8, 2020 at 10:41 PM Eric W. Biederman wrote: >>>>> The cred_guard_mutex is problematic. The cred_guard_mutex is held >>>>> over the userspace accesses as the arguments from userspace are read. >>>>> The cred_guard_mutex is held of PTRACE_EVENT_EXIT as the the other >>>>> threads are killed. The cred_guard_mutex is held over >>>>> "put_user(0, tsk->clear_child_tid)" in exit_mm(). >>>>> >>>>> Any of those can result in deadlock, as the cred_guard_mutex is held >>>>> over a possible indefinite userspace waits for userspace. >>>>> >>>>> Add exec_update_mutex that is only held over exec updating process >>>>> with the new contents of exec, so that code that needs not to be >>>>> confused by exec changing the mm and the cred in ways that can not >>>>> happen during ordinary execution of a process. >>>>> >>>>> The plan is to switch the users of cred_guard_mutex to >>>>> exec_udpate_mutex one by one. This lets us move forward while still >>>>> being careful and not introducing any regressions. >>>> [...] >>>>> @@ -1034,6 +1035,11 @@ static int exec_mmap(struct mm_struct *mm) >>>>> return -EINTR; >>>>> } >>>>> } >>>>> + >>>>> + ret = mutex_lock_killable(&tsk->signal->exec_update_mutex); >>>>> + if (ret) >>>>> + return ret; >>>> >>>> We're already holding the old mmap_sem, and now nest the >>>> exec_update_mutex inside it; but then while still holding the >>>> exec_update_mutex, we do mmput(), which can e.g. end up in ksm_exit(), >>>> which can do down_write(&mm->mmap_sem) from __ksm_exit(). So I think >>>> at least lockdep will be unhappy, and I'm not sure whether it's an >>>> actual problem or not. >>> >>> Good point. I should double check the lock ordering here with mmap_sem. >>> It doesn't look like mmput takes mmap_sem >> >> You sure about that? mmput() -> __mmput() -> ksm_exit() -> >> __ksm_exit() -> down_write(&mm->mmap_sem) >> >> Or also: mmput() -> __mmput() -> khugepaged_exit() -> >> __khugepaged_exit() -> down_write(&mm->mmap_sem) >> >> Or is there a reason why those paths can't happen? > > Clearly I didn't look far enough. > > I will adjust this so that exec_update_mutex is taken before mmap_sem. > Anything else is just asking for trouble. > Note that vm_access does also mmput under the exec_update_mutex. So I don't see a huge problem here. But maybe I missed something. Bernd.