Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4521664ybb; Tue, 7 Apr 2020 09:04:21 -0700 (PDT) X-Google-Smtp-Source: APiQypKJXr9UDu8wgiO3ZqJKFbthtUQ+mSxVHiSZFOTBK0nsvHhOA2eEQdiEmmnmDDE82cFxFZAk X-Received: by 2002:aca:49d8:: with SMTP id w207mr2345043oia.85.1586275461320; Tue, 07 Apr 2020 09:04:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586275461; cv=none; d=google.com; s=arc-20160816; b=YC36CXm6UfVFKg7laJ6RHuZ5QKcut7abldOHh+7ACjEzjK20ilyFpZDmuTljmBI669 dTx4OtCc7P1KLrTkHdCgnzxahgZWoh6HrmZGs6a1sxGz73bV5Z527I0HOdOiorCODXJp cEQG8LHp4orM7XEd0szO5m6uc1O4kxvR3lK7MUL1t5gP8e6PO4sYMi1l4OCYAgMSV+NE FsK9+q6FSc9aNAlwdcoCf+sE3LKACe65sD8X3XlAtfqbJrI8DdR+IK9Frrkg3Z7oCpHH 91+ZK5I+GiYStQdney8pbLMvss6+UJ1PxNmtG6ycu2MS4u3alcoAGS3t2skV4NZbbPbK VQEg== 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 :dkim-signature; bh=bCeukKbud7C3clm1zbpVpVwgv+8wge+9QzRvJl6XRts=; b=kYonBx4htxCIFNhQ/DNXL4Ql9Hl1h2m83HPmfxpyoaCDHy/Tg3DU0AdTwCDfJ37pHb 8ltmpvl7dqTrZzHzopArfN/bDdcJuhw8la/13O9GyZl3fGVqvvtWw9fdU6smXgKTrXTk BfS+JkDPZbotSpkX5gbOMY2jTsiHvhK1MmP12ox6YKOAfO7WHRUGGXSdrPfmXllEzTDJ 8aOIzrfFfxqTCGwjnWemfcZ8Ci2iF4qa02VyRJf6xedT5t17922N3IzZCFY94V00rmdT ce6q8FPw4reOzqXnTX/OMAVemqHB7hjWlTmwQF8h4svebfAbTDUn+oYFXXJqMb9b5/Mx Bnfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YsRiZ1dE; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k39si1242842otk.255.2020.04.07.09.03.58; Tue, 07 Apr 2020 09:04: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; dkim=pass header.i=@chromium.org header.s=google header.b=YsRiZ1dE; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727877AbgDGQCf (ORCPT + 99 others); Tue, 7 Apr 2020 12:02:35 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:45676 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726889AbgDGQCf (ORCPT ); Tue, 7 Apr 2020 12:02:35 -0400 Received: by mail-pg1-f195.google.com with SMTP id o26so1918493pgc.12 for ; Tue, 07 Apr 2020 09:02:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=bCeukKbud7C3clm1zbpVpVwgv+8wge+9QzRvJl6XRts=; b=YsRiZ1dEtXgjSAtNUNsyT8zEGLIAz3phRF7UE6EXjeNzS9J0E3WHCS/cxlySz3B1hB beXyhRyr5Vk8avGeXgB4i2pOGSJo2Op9/bw15THjx0x8D6P3f8qLao8/5qGSocrLL2dK 6gWtCI6r6N0mXiPIrVCBTw1mAwiBEjLBqdRH8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=bCeukKbud7C3clm1zbpVpVwgv+8wge+9QzRvJl6XRts=; b=IjqAq33b1XvvvgAotjr60zHJbocxv3hsL3DG9o7q+Aw56zziPVdOmLNoEW8by7AXpH AJwqmPaTdB9LZdUcn3lma3RR6eqWcfQGmCsYFNXtyUD/M282F3z7+tNWmL5PpXMeJfnG ih63mb979TF4h2jGUx7966ld9BEb9ZqLGXqBcEuPswMwYgE2vLiZSJYk97VazF14h/UK g3wG3yii7lj0m7uqfhpuuJ1XPagyawNPgxbdBLXNITsEdl7e6fWv1rQYxLrbGPhZERYW 7p2kTKvW6SxigriQ8LkvOfLNPARCfxVTaB5/VooH2XGzCAijZsAztZ5R8hHsCvOxEzoy b+Cg== X-Gm-Message-State: AGi0PuZx5YCE9+96CC9vxGJGWLqLXpdOnS92vvRrqTFCsOeuVNR2frOf BgxKvgwl19GOIlXZab4nA8sAfA== X-Received: by 2002:aa7:94a5:: with SMTP id a5mr3266386pfl.67.1586275354262; Tue, 07 Apr 2020 09:02:34 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id z63sm13623706pgd.12.2020.04.07.09.02.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 09:02:33 -0700 (PDT) Date: Tue, 7 Apr 2020 09:02:32 -0700 From: Kees Cook To: "Eric W. Biederman" Cc: Linus Torvalds , Bernd Edlinger , Linux Kernel Mailing List , Alexey Gladkov , Oleg Nesterov , Jann Horn , Christian Brauner Subject: Re: [PATCH 2/3] exec: Make unlocking exec_update_mutex explict Message-ID: <202004070902.5D36F15E@keescook> References: <87blobnq02.fsf@x220.int.ebiederm.org> <87lfnda3w3.fsf@x220.int.ebiederm.org> <87wo6s3wxd.fsf_-_@x220.int.ebiederm.org> <87imic3wtz.fsf_-_@x220.int.ebiederm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87imic3wtz.fsf_-_@x220.int.ebiederm.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 06, 2020 at 08:31:52PM -0500, Eric W. Biederman wrote: > > With install_exec_creds updated to follow immediately after > setup_new_exec, the failure of unshare_sighand is the only > code path where exec_update_mutex is held but not explicitly > unlocked. > > Update that code path to explicitly unlock exec_update_mutex. > > Remove the unlocking of exec_update_mutex from free_bprm. > > Signed-off-by: "Eric W. Biederman" Reviewed-by: Kees Cook -Kees > --- > fs/exec.c | 6 +++--- > include/linux/binfmts.h | 3 +-- > 2 files changed, 4 insertions(+), 5 deletions(-) > > diff --git a/fs/exec.c b/fs/exec.c > index d55710a36056..28c87020da9b 100644 > --- a/fs/exec.c > +++ b/fs/exec.c > @@ -1318,7 +1318,7 @@ int flush_old_exec(struct linux_binprm * bprm) > */ > retval = unshare_sighand(me); > if (retval) > - goto out; > + goto out_unlock; > > set_fs(USER_DS); > me->flags &= ~(PF_RANDOMIZE | PF_FORKNOEXEC | PF_KTHREAD | > @@ -1335,6 +1335,8 @@ int flush_old_exec(struct linux_binprm * bprm) > do_close_on_exec(me->files); > return 0; > > +out_unlock: > + mutex_unlock(&me->signal->exec_update_mutex); > out: > return retval; > } > @@ -1451,8 +1453,6 @@ static void free_bprm(struct linux_binprm *bprm) > { > free_arg_pages(bprm); > if (bprm->cred) { > - if (bprm->called_exec_mmap) > - mutex_unlock(¤t->signal->exec_update_mutex); > mutex_unlock(¤t->signal->cred_guard_mutex); > abort_creds(bprm->cred); > } > diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h > index a345d9fed3d8..6f564b9ad882 100644 > --- a/include/linux/binfmts.h > +++ b/include/linux/binfmts.h > @@ -47,8 +47,7 @@ struct linux_binprm { > secureexec:1, > /* > * Set by flush_old_exec, when exec_mmap has been called. > - * This is past the point of no return, when the > - * exec_update_mutex has been taken. > + * This is past the point of no return. > */ > called_exec_mmap:1; > #ifdef __alpha__ > -- > 2.25.0 > -- Kees Cook