From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f170.google.com ([209.85.192.170]:35505 "EHLO mail-pf0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750721AbcEQTOm (ORCPT ); Tue, 17 May 2016 15:14:42 -0400 Received: by mail-pf0-f170.google.com with SMTP id 77so9714835pfv.2 for ; Tue, 17 May 2016 12:14:42 -0700 (PDT) Date: Tue, 17 May 2016 12:14:39 -0700 From: Kees Cook To: Jonathan Corbet Cc: David Howells , Linus Torvalds , Serge Hallyn , Willy Tarreau , linux-doc@vger.kernel.org, Alexander Viro , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] exec: clarify reasoning for euid/egid reset Message-ID: <20160517191439.GA29657@www.outflux.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Sender: linux-fsdevel-owner@vger.kernel.org List-ID: This section of code initially looks redundant, but is required. This improves the comment to explain more clearly why the reset is needed. Signed-off-by: Kees Cook Acked-by: Serge E. Hallyn --- v2: - clarified example as a setuid script, dhowells --- fs/exec.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/exec.c b/fs/exec.c index c4010b8207a1..a98b21d47385 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1387,7 +1387,12 @@ static void bprm_fill_uid(struct linux_binprm *bprm) kuid_t uid; kgid_t gid; - /* clear any previous set[ug]id data from a previous binary */ + /* + * Since this can be called multiple times (via prepare_binprm), + * we must clear any previous work done when setting set[ug]id + * bits from any earlier bprm->file uses (for example when run + * first for a setuid script then again for its interpreter). + */ bprm->cred->euid = current_euid(); bprm->cred->egid = current_egid(); -- 2.6.3 -- Kees Cook Chrome OS & Brillo Security