Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1038924ybh; Tue, 10 Mar 2020 13:18:38 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsJ4O2zqo87X6d91BypDyFSUwMmY8dXlOJFa4fM630Y07S2NMcJ4AjneN/wY5btkRMGtc1n X-Received: by 2002:aca:1b11:: with SMTP id b17mr2537721oib.45.1583871518071; Tue, 10 Mar 2020 13:18:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583871518; cv=none; d=google.com; s=arc-20160816; b=WgKapiDDIbY6Hwewd4R/1Ssxh1LejYu8tiJDA+CwQFKdXYnsM+OuarzAME0VyxYEoi ypjOjQWURVBLMtsm60Gj79qlkq0RakALHLanmlkQml/BpJJoLd6+t2zY4hOqh7Wb/Rux f5fHdUbxDzIHVxBF7oHVSiKi3ULmz5W/2xBZQEZESeMkXnDIzGwAoFTgW5Wm+VRASyI+ zjmlYvMAgDXlI/FWMO1kFeXMbvgHYTjLiclLKJ6fzm7jE8DIqa/Ngg89snYQKrQ+YEuY kBqoMHqFuoBtOYZdA6UHIgonLH9OJAN6r66h13/0pO/7IHqmp4V/zFOrca+cMNP+2tym 8nPg== 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=RKigTXtTZ1YImDJinI4wU2TyC7WQeMLqFQfSK2SiClo=; b=JRrZN8LQCKHgkykGQmwztsyKawn68BqPrfCF3SCf5IIToIW1HDOWFYDLTPktnrCKV6 cSxHpgbzIBrMD7QlwBdLztRr9uW5v/9v5zfr4aMhkN5xwj3Zdd4nYH1NzNPLNZ3kYeM6 uyUpPuRkZjsZbWX9fn8st+TfGaFy5cm0jbw/cpkEf6iVDGAjbSGi2k9+6zn6MXdIVZk1 T9ewL41QmtSY5O6Vwu/A8zKNm0iGiqPVKhtDdnM1wJ0Nvf6Y6XCrqTxpqYk7Z9DgMIp6 uCk7tLJCiocitVTwm6kdkNQeII+F02kmzmyOLrPtadj7x3qYWf7bOSM/wKTqfS7RsCLq 320A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=i6PwcH1Y; 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 a11si6287144oib.154.2020.03.10.13.18.20; Tue, 10 Mar 2020 13:18:38 -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=i6PwcH1Y; 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 S1726100AbgCJUSA (ORCPT + 99 others); Tue, 10 Mar 2020 16:18:00 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:33865 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726436AbgCJUSA (ORCPT ); Tue, 10 Mar 2020 16:18:00 -0400 Received: by mail-pg1-f193.google.com with SMTP id t3so6819264pgn.1 for ; Tue, 10 Mar 2020 13:17:59 -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=RKigTXtTZ1YImDJinI4wU2TyC7WQeMLqFQfSK2SiClo=; b=i6PwcH1Y6dzAld5+0ItdFH0DNwVNQDvVoI3rFkpU5glNp7p1gPAzHwUVGup1Aj6YPT mm52T1lUrybAlYpwBILDBxSuJksLBuWK9y1KWBhigTnvRKG8n9iDhSzGEkU4ueiYuSvY EiCKda6MTerB6wqJNRGHCZxbLU3xNZ5OT1LFY= 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=RKigTXtTZ1YImDJinI4wU2TyC7WQeMLqFQfSK2SiClo=; b=Bm4H2toIR7yIFOCmofnk3e/odUv0j1SsVmYv/wcY2o4Sr4msNX5euyWOFcyYgKGgXG sM6Jr6XfTJ8rprCpxvHXJMJvdLohJ2QpVQrqKfx4gdgHz818vjVRb6lVd9Ocg9k3mFzb CzpKpsjHvkwOnUBVHXgai5QE3oPpYkJJtZ3uELZZYhA7cc9cKqJUtI6pTQgNZB8aRnLB x2QOx4Xk20+77WnOfBZ+DYanoOq2/qCQPmh81CRq0KpTPdQwChH/4agYwRf9lOO2bFUS +bjwx3/JgCXQ0XPXxWyDAFsgT7LWIbO7wgGEDoDAdb2c5q5f9pC9JPXkfux7TMXCN8LW FAJQ== X-Gm-Message-State: ANhLgQ2OmtNL/josvurvG4g7nSdjRWGgfBxgt86NmbCzi9zYZWMhbVfD 2t+Qu8sjsiMYpaQy1aYk+N/Qjg== X-Received: by 2002:a65:5383:: with SMTP id x3mr22185221pgq.279.1583871478687; Tue, 10 Mar 2020 13:17:58 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id 199sm51876404pfv.81.2020.03.10.13.17.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Mar 2020 13:17:57 -0700 (PDT) Date: Tue, 10 Mar 2020 13:17:56 -0700 From: Kees Cook To: "Eric W. Biederman" Cc: Bernd Edlinger , Christian Brauner , 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: [PATCH v2 1/5] exec: Only compute current once in flush_old_exec Message-ID: <202003101317.20BD018D9@keescook> 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> <87pndm5y3l.fsf_-_@x220.int.ebiederm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87pndm5y3l.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 Sun, Mar 08, 2020 at 04:35:26PM -0500, Eric W. Biederman wrote: > > Make it clear that current only needs to be computed once in > flush_old_exec. This may have some efficiency improvements and it > makes the code easier to change. > > Signed-off-by: "Eric W. Biederman" modulo my suggestion of adding more comments (it could even be kerndoc!) that explicitly states that "me" should always be "current", yup, looks good: Reviewed-by: Kees Cook -Kees > --- > fs/exec.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/fs/exec.c b/fs/exec.c > index db17be51b112..c3f34791f2f0 100644 > --- a/fs/exec.c > +++ b/fs/exec.c > @@ -1260,13 +1260,14 @@ void __set_task_comm(struct task_struct *tsk, const char *buf, bool exec) > */ > int flush_old_exec(struct linux_binprm * bprm) > { > + struct task_struct *me = current; > int retval; > > /* > * Make sure we have a private signal table and that > * we are unassociated from the previous thread group. > */ > - retval = de_thread(current); > + retval = de_thread(me); > if (retval) > goto out; > > @@ -1294,10 +1295,10 @@ int flush_old_exec(struct linux_binprm * bprm) > bprm->mm = NULL; > > set_fs(USER_DS); > - current->flags &= ~(PF_RANDOMIZE | PF_FORKNOEXEC | PF_KTHREAD | > + me->flags &= ~(PF_RANDOMIZE | PF_FORKNOEXEC | PF_KTHREAD | > PF_NOFREEZE | PF_NO_SETAFFINITY); > flush_thread(); > - current->personality &= ~bprm->per_clear; > + me->personality &= ~bprm->per_clear; > > /* > * We have to apply CLOEXEC before we change whether the process is > @@ -1305,7 +1306,7 @@ int flush_old_exec(struct linux_binprm * bprm) > * trying to access the should-be-closed file descriptors of a process > * undergoing exec(2). > */ > - do_close_on_exec(current->files); > + do_close_on_exec(me->files); > return 0; > > out: > -- > 2.25.0 > -- Kees Cook