Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp3624989ybf; Tue, 3 Mar 2020 09:17:55 -0800 (PST) X-Google-Smtp-Source: ADFU+vs4oFJAbgPcLUGbuV5lS8WI8VAmkefJsysfj1v9QPr+Dkjtks+/awShqVVbzAMow7+LTv8K X-Received: by 2002:a05:6830:154b:: with SMTP id l11mr1764865otp.57.1583255875700; Tue, 03 Mar 2020 09:17:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583255875; cv=none; d=google.com; s=arc-20160816; b=A9HqySwQL3KYyWLC2Bn6VXyvEPrsq8xllRCh/9eGgopBFMnQXPDIB86wZHz+Zo0zuG 3zUauzJnhSg9SvOhhzqtsy9+SEAVPGygA7E2i05rBErWjnn9LcpYFrfalOiTaslaU6Qg WBa2cWB0yN+37Hk8nyTWhBYiciYEFDkZteUbhCIY+ZXA6lFF6LhgPNsh/F1DflBkDafK U5R/FfKyIT8m7xJ0ifytenkaPj45Newa169ghP/qTWAReOoQ605ITzbfn9UON8Wu4GH7 CCfYWUzlZoSppE1ReDmQlbUK+derJtTqbfbbCe4Fn6fX1YUljBHG7wynbaJn+M+Ov5kr h+7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=pLsGvA8fwkCmpgRYlONBULWcX4Mbh15rY3pOszkJYNs=; b=SCqLfw9cUYs/nnn58H7vZgUo4vRco/vmDQWFS4xof+2dhLH3IyN5pZpFGUkyKxymrO cczNPD4jzzgQdwVeTsGk4B9uEApkFaUjyz5TUUmmpFyoOnGnZ2fgQIRlcr/FcSZXVGzn 8fnoCKsiqZIhAF11/+wCnLEcxdlw50qjMOOgBLz3zDxtflnaRFp4tX25XbrmUYTL6bZY 1dfTNq+pLuI52o53HoVNj7PrYLOpR4/8FGZE14PiEUg7DwheSYHR+Bq9jy2rTOCHdalk eS6/ftucg6gRHjcDqFOtYK+BpURZFYfUKx6VHUNop8qP77sn+5jhqcv7mCQ2bgploLKv p5bw== ARC-Authentication-Results: i=1; mx.google.com; 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 b8si8844255oib.193.2020.03.03.09.17.42; Tue, 03 Mar 2020 09:17:55 -0800 (PST) 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; 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 S1730500AbgCCRBu (ORCPT + 99 others); Tue, 3 Mar 2020 12:01:50 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:49495 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727175AbgCCRBu (ORCPT ); Tue, 3 Mar 2020 12:01:50 -0500 Received: from ip5f5bf7ec.dynamic.kabel-deutschland.de ([95.91.247.236] helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1j9Aus-0005Fy-RG; Tue, 03 Mar 2020 17:01:10 +0000 Date: Tue, 3 Mar 2020 18:01:09 +0100 From: Christian Brauner To: Bernd Edlinger Cc: "Eric W. Biederman" , 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" Subject: Re: [PATCHv5] exec: Fix a deadlock in ptrace Message-ID: <20200303170109.y6q2acgydyzuh3mp@wittgenstein> References: <875zfmloir.fsf@x220.int.ebiederm.org> <87v9nmjulm.fsf@x220.int.ebiederm.org> <202003021531.C77EF10@keescook> <20200303085802.eqn6jbhwxtmz4j2x@wittgenstein> <87v9nlii0b.fsf@x220.int.ebiederm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 03, 2020 at 04:48:01PM +0000, Bernd Edlinger wrote: > On 3/3/20 4:18 PM, Eric W. Biederman wrote: > > Bernd Edlinger writes: > > > >> This fixes a deadlock in the tracer when tracing a multi-threaded > >> application that calls execve while more than one thread are running. > >> > >> I observed that when running strace on the gcc test suite, it always > >> blocks after a while, when expect calls execve, because other threads > >> have to be terminated. They send ptrace events, but the strace is no > >> longer able to respond, since it is blocked in vm_access. > >> > >> The deadlock is always happening when strace needs to access the > >> tracees process mmap, while another thread in the tracee starts to > >> execve a child process, but that cannot continue until the > >> PTRACE_EVENT_EXIT is handled and the WIFEXITED event is received: > > > > A couple of things. > > > > Why do we think it is safe to change the behavior exposed to userspace? > > Not the deadlock but all of the times the current code would not > > deadlock? > > > > Especially given that this is a small window it might be hard for people > > to track down and report so we need a strong argument that this won't > > break existing userspace before we just change things. > > > > Hmm, I tend to agree. > > > Usually surveying all of the users of a system call that we can find > > and checking to see if they might be affected by the change in behavior > > is difficult enough that we usually opt for not being lazy and > > preserving the behavior. > > > > This patch is up to two changes in behavior now, that could potentially > > affect a whole array of programs. Adding linux-api so that this change > > in behavior can be documented if/when this change goes through. > > > > One is PTRACE_ACCESS possibly returning EAGAIN, yes. > > We could try to restrict that behavior change to when any > thread is ptraced when execve starts, can't be too complicated. > > > But the other is only SYS_seccomp returning EAGAIN, when a different > thread of the current process is calling execve at the same time. > > I would consider it completely impossible to have any user-visual effect, > since de_thread is just terminating all threads, including the thread > where the -EAGAIN was returned, so we will never know what happened. I think if we risk a user-space facing change we should try the simple thing first before making the fix more convoluted? But it's a tough call... > > > > If you can split the documentation and test fixes out into separate > > patches that would help reviewing this code, or please make it explicit > > that the your are changing documentation about behavior that is changing > > with this patch. > > > > I am not sure if I have touched the right user documentation. > > I only saw a document referring to a non-existent "current->cred_replace_mutex" > I haven't digged the git history, but that must be pre-historic IMHO. > It appears to me that is some developer documentation, but it's nevertheless > worth to keep up to date when the code changes. > > So where would I add the possibility for PTRACE_ATTACH to return -EAGAIN ? Since that would be a potentially user-visible change it would make the most sense to add it to man ptrace(2) if/when we land this change. For developers, placing a comment in kernel/ptrace.c:ptrace_attach() would make the most sense? We already have something about exec protection in there. Christian