Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp6520590ybi; Wed, 29 May 2019 09:00:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqwECaWljEm7B9KX6+/8LjsBYSGSScCImizfdb3mrKxo5rUextRZy0bIxQzVLmTiZ4N3QQI1 X-Received: by 2002:a63:4f16:: with SMTP id d22mr97234355pgb.148.1559145644623; Wed, 29 May 2019 09:00:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559145644; cv=none; d=google.com; s=arc-20160816; b=KkXv5MJY+SBGCd/KOntnTI5mmCcCZwbfDS9CbkdzAsAQ0B5iPcFnErCKP4QZqqEtf9 Or8yNXZ7MVMCPzg3gBg7O41917DNi11lJS8F9y61AtsfQF2fp1lsB3owcQhhDJAaDHKz laBzZPCmdfTDs51vxs3jKH1i62IoDsChYuFVjOVkSyvRJrFeR20gsi+PgVpafwtA5rj7 2d69pHaLXKqcPhZxV/ojr29qwZ++NHIfM/TKzWzKUpmDte3wxOR2ZzVG/kem80MF3iZo M1UxyPtnMAEjP25eCtt/MAG9yxW01u+mjJ9087NE8OMH53Q2nC5cfXUCX1bN4+mPH9HJ dp4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:mime-version:user-agent :message-id:in-reply-to:date:references:cc:to:from; bh=WwcTnIfo5gnrrthR+gaw4ulDjhk+n906kdHcKACpZY4=; b=rdCLn4N3moMKJ2PxmMTlPHPOgw4+ihdKsxf6v690L6YVejliFVla6ZE2QFp+S/htoU 8XCisZo37fI5tE81SRfxWhZyswksFIrZUznE8E24jcg7p2wWSzav39pcPHiJAsaFI+Kl 9rGmEIXgU19c18rZnjK2uR4YuOBprbrdiwY9ix0KssuOVvUuqMQLAV0YMwea/mzFZlBR 0fubK0DgAsG91eWO75416LTemivgKvBX2T+Q8/mXEeb/3k+c5YXjpdFtv5gChF3HbZcd 1vZwGVxOjK+EBSXv1Cj7PHUmDwq58WxrQVMNFOBeDSR6Dh8opREbIYTbEjNMKLxV4sYF Rv9Q== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 36si2371pgx.477.2019.05.29.09.00.26; Wed, 29 May 2019 09:00:44 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726396AbfE2P7O (ORCPT + 99 others); Wed, 29 May 2019 11:59:14 -0400 Received: from out01.mta.xmission.com ([166.70.13.231]:56652 "EHLO out01.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726062AbfE2P7N (ORCPT ); Wed, 29 May 2019 11:59:13 -0400 Received: from in02.mta.xmission.com ([166.70.13.52]) by out01.mta.xmission.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.87) (envelope-from ) id 1hW0yt-0000xT-LR; Wed, 29 May 2019 09:59:11 -0600 Received: from ip72-206-97-68.om.om.cox.net ([72.206.97.68] helo=x220.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.87) (envelope-from ) id 1hW0ys-0007IP-SG; Wed, 29 May 2019 09:59:11 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Jann Horn Cc: Oleg Nesterov , Andrew Morton , Kees Cook , David Howells , linux-kernel@vger.kernel.org References: <20190529113157.227380-1-jannh@google.com> Date: Wed, 29 May 2019 10:59:06 -0500 In-Reply-To: <20190529113157.227380-1-jannh@google.com> (Jann Horn's message of "Wed, 29 May 2019 13:31:57 +0200") Message-ID: <87v9xtz1yt.fsf@xmission.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1hW0ys-0007IP-SG;;;mid=<87v9xtz1yt.fsf@xmission.com>;;;hst=in02.mta.xmission.com;;;ip=72.206.97.68;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1+HZZhP+I6gkJd2bJSMtuTonAEQcH3Rs7I= X-SA-Exim-Connect-IP: 72.206.97.68 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on sa06.xmission.com X-Spam-Level: * X-Spam-Status: No, score=1.7 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE,LotsOfNums_01,T_TM2_M_HEADER_IN_MSG,T_TooManySym_01, T_TooManySym_02,XMSubLong autolearn=disabled version=3.4.2 X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.4999] * 0.7 XMSubLong Long Subject * 1.2 LotsOfNums_01 BODY: Lots of long strings of numbers * 0.0 T_TM2_M_HEADER_IN_MSG BODY: No description available. * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa06 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_02 5+ unique symbols in subject * 0.0 T_TooManySym_01 4+ unique symbols in subject X-Spam-DCC: XMission; sa06 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: *;Jann Horn X-Spam-Relay-Country: X-Spam-Timing: total 420 ms - load_scoreonly_sql: 0.04 (0.0%), signal_user_changed: 2.8 (0.7%), b_tie_ro: 1.98 (0.5%), parse: 0.80 (0.2%), extract_message_metadata: 10 (2.5%), get_uri_detail_list: 1.84 (0.4%), tests_pri_-1000: 12 (2.7%), tests_pri_-950: 1.22 (0.3%), tests_pri_-900: 1.00 (0.2%), tests_pri_-90: 27 (6.5%), check_bayes: 26 (6.1%), b_tokenize: 7 (1.7%), b_tok_get_all: 10 (2.4%), b_comp_prob: 2.2 (0.5%), b_tok_touch_all: 4.5 (1.1%), b_finish: 0.58 (0.1%), tests_pri_0: 351 (83.5%), check_dkim_signature: 0.50 (0.1%), check_dkim_adsp: 6 (1.5%), poll_dns_idle: 0.45 (0.1%), tests_pri_10: 2.3 (0.5%), tests_pri_500: 10 (2.3%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH] ptrace: restore smp_rmb() in __ptrace_may_access() X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Jann Horn writes: > Restore the read memory barrier in __ptrace_may_access() that was deleted > a couple years ago. Also add comments on this barrier and the one it pairs > with to explain why they're there (as far as I understand). My bad. When I made that change I could not figure out what that barrier was for, and it did not appear necessary. Do you happen to know of any real world problems? Reviewed-by: "Eric W. Biederman" If no one else would prefer to pick this up I will grab it. I have another bug fix I already queueing for 5.2-rcX. Thank you, Eric > > Fixes: bfedb589252c ("mm: Add a user_ns owner to mm_struct and fix ptrace permission checks") > Cc: stable@vger.kernel.org > Signed-off-by: Jann Horn > --- > (I have no clue whatsoever what the relevant tree for this is, but I > guess Oleg is the relevant maintainer?) > > kernel/cred.c | 9 +++++++++ > kernel/ptrace.c | 10 ++++++++++ > 2 files changed, 19 insertions(+) > > diff --git a/kernel/cred.c b/kernel/cred.c > index 45d77284aed0..07e069d00696 100644 > --- a/kernel/cred.c > +++ b/kernel/cred.c > @@ -450,6 +450,15 @@ int commit_creds(struct cred *new) > if (task->mm) > set_dumpable(task->mm, suid_dumpable); > task->pdeath_signal = 0; > + /* > + * If a task drops privileges and becomes nondumpable, > + * the dumpability change must become visible before > + * the credential change; otherwise, a __ptrace_may_access() > + * racing with this change may be able to attach to a task it > + * shouldn't be able to attach to (as if the task had dropped > + * privileges without becoming nondumpable). > + * Pairs with a read barrier in __ptrace_may_access(). > + */ > smp_wmb(); > } > > diff --git a/kernel/ptrace.c b/kernel/ptrace.c > index 5710d07e67cf..e54452c2954b 100644 > --- a/kernel/ptrace.c > +++ b/kernel/ptrace.c > @@ -324,6 +324,16 @@ static int __ptrace_may_access(struct task_struct *task, unsigned int mode) > return -EPERM; > ok: > rcu_read_unlock(); > + /* > + * If a task drops privileges and becomes nondumpable (through a syscall > + * like setresuid()) while we are trying to access it, we must ensure > + * that the dumpability is read after the credentials; otherwise, > + * we may be able to attach to a task that we shouldn't be able to > + * attach to (as if the task had dropped privileges without becoming > + * nondumpable). > + * Pairs with a write barrier in commit_creds(). > + */ > + smp_rmb(); > mm = task->mm; > if (mm && > ((get_dumpable(mm) != SUID_DUMP_USER) &&