Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752585AbdGSAyB (ORCPT ); Tue, 18 Jul 2017 20:54:01 -0400 Received: from out01.mta.xmission.com ([166.70.13.231]:53394 "EHLO out01.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751906AbdGSAx7 (ORCPT ); Tue, 18 Jul 2017 20:53:59 -0400 From: ebiederm@xmission.com (Eric W. Biederman) To: Kees Cook Cc: Andrew Morton , David Howells , John Johansen , "Serge E. Hallyn" , Paul Moore , Stephen Smalley , Casey Schaufler , Tetsuo Handa , James Morris , Andy Lutomirski , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org References: <1500416736-49829-1-git-send-email-keescook@chromium.org> <1500416736-49829-10-git-send-email-keescook@chromium.org> Date: Tue, 18 Jul 2017 19:45:52 -0500 In-Reply-To: <1500416736-49829-10-git-send-email-keescook@chromium.org> (Kees Cook's message of "Tue, 18 Jul 2017 15:25:30 -0700") Message-ID: <874lu9b6f3.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=1dXdFN-0003eu-VQ;;;mid=<874lu9b6f3.fsf@xmission.com>;;;hst=in01.mta.xmission.com;;;ip=67.3.213.87;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1+idXTgzC9T0sMp5ndyxIk02k4ANzviH28= X-SA-Exim-Connect-IP: 67.3.213.87 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.0 TVD_RCVD_IP Message was received from an IP address * 0.7 XMSubLong Long Subject * 0.0 T_TM2_M_HEADER_IN_MSG BODY: No description available. * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa02 1397; Body=1 Fuz1=1 Fuz2=1] * 0.1 XMSolicitRefs_0 Weightloss drug X-Spam-DCC: XMission; sa02 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ;Kees Cook X-Spam-Relay-Country: X-Spam-Timing: total 5713 ms - load_scoreonly_sql: 0.09 (0.0%), signal_user_changed: 3.6 (0.1%), b_tie_ro: 2.3 (0.0%), parse: 1.43 (0.0%), extract_message_metadata: 33 (0.6%), get_uri_detail_list: 4.8 (0.1%), tests_pri_-1000: 14 (0.2%), tests_pri_-950: 2.2 (0.0%), tests_pri_-900: 1.78 (0.0%), tests_pri_-400: 42 (0.7%), check_bayes: 39 (0.7%), b_tokenize: 17 (0.3%), b_tok_get_all: 10 (0.2%), b_comp_prob: 5 (0.1%), b_tok_touch_all: 3.2 (0.1%), b_finish: 0.85 (0.0%), tests_pri_0: 706 (12.4%), check_dkim_signature: 1.07 (0.0%), check_dkim_adsp: 5 (0.1%), tests_pri_500: 4903 (85.8%), poll_dns_idle: 4887 (85.5%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH v3 09/15] exec: Correct comments about "point of no return" 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 in01.mta.xmission.com) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3179 Lines: 79 Kees Cook writes: > In commit 221af7f87b97 ("Split 'flush_old_exec' into two functions"), > the comment about the point of no return should have stayed in > flush_old_exec() since it refers to "bprm->mm = NULL;" line, but prior > changes in commits c89681ed7d0e ("remove steal_locks()"), and > fd8328be874f ("sanitize handling of shared descriptor tables in failing > execve()") made it look like it meant the current->sas_ss_sp line instead. > > The comment was referring to the fact that once bprm->mm is NULL, all > failures from a binfmt load_binary hook (e.g. load_elf_binary), will > get SEGV raised against current. Move this comment and expand the > explanation a bit, putting it above the assignment this time, and add > details about the true nature of "point of no return" being the call > to flush_old_exec() itself. > > This also removes an erroneous commet about when credentials are being > installed. That has its own dedicated function, install_exec_creds(), > which carries a similar (and correct) comment, so remove the bogus comment > where installation is not actually happening. Acked-by: "Eric W. Biederman" > > Cc: David Howells > Cc: Eric W. Biederman > Signed-off-by: Kees Cook > --- > fs/exec.c | 16 +++++++++++++--- > 1 file changed, 13 insertions(+), 3 deletions(-) > > diff --git a/fs/exec.c b/fs/exec.c > index 53ffa739fb58..f9480d3e0b82 100644 > --- a/fs/exec.c > +++ b/fs/exec.c > @@ -1258,6 +1258,12 @@ void __set_task_comm(struct task_struct *tsk, const char *buf, bool exec) > perf_event_comm(tsk, exec); > } > > +/* > + * Calling this is the point of no return. None of the failures will be > + * seen by userspace since either the process is already taking a fatal > + * signal (via de_thread() or coredump), or will have SEGV raised > + * (after exec_mmap()) by search_binary_handlers (see below). > + */ > int flush_old_exec(struct linux_binprm * bprm) > { > int retval; > @@ -1285,7 +1291,13 @@ int flush_old_exec(struct linux_binprm * bprm) > if (retval) > goto out; > > - bprm->mm = NULL; /* We're using it now */ > + /* > + * After clearing bprm->mm (to mark that current is using the > + * prepared mm now), we have nothing left of the original > + * process. If anything from here on returns an error, the check > + * in search_binary_handler() will SEGV current. > + */ > + bprm->mm = NULL; > > set_fs(USER_DS); > current->flags &= ~(PF_RANDOMIZE | PF_FORKNOEXEC | PF_KTHREAD | > @@ -1339,7 +1351,6 @@ void setup_new_exec(struct linux_binprm * bprm) > > arch_pick_mmap_layout(current->mm); > > - /* This is the point of no return */ > current->sas_ss_sp = current->sas_ss_size = 0; > > if (uid_eq(current_euid(), current_uid()) && gid_eq(current_egid(), current_gid())) > @@ -1357,7 +1368,6 @@ void setup_new_exec(struct linux_binprm * bprm) > */ > current->mm->task_size = TASK_SIZE; > > - /* install the new credentials */ > if (!uid_eq(bprm->cred->uid, current_euid()) || > !gid_eq(bprm->cred->gid, current_egid())) { > current->pdeath_signal = 0;