From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9B84C48BDF for ; Tue, 15 Jun 2021 19:33:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8D2C46128B for ; Tue, 15 Jun 2021 19:33:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230212AbhFOTfk (ORCPT ); Tue, 15 Jun 2021 15:35:40 -0400 Received: from out02.mta.xmission.com ([166.70.13.232]:41654 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230012AbhFOTfe (ORCPT ); Tue, 15 Jun 2021 15:35:34 -0400 Received: from in02.mta.xmission.com ([166.70.13.52]) by out02.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1ltEoR-00FcZ9-Jh; Tue, 15 Jun 2021 13:33:27 -0600 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95] helo=email.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1ltEoQ-00FCWx-Iw; Tue, 15 Jun 2021 13:33:27 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Andrei Vagin Cc: linux-kernel@vger.kernel.org, Kees Cook , linux-fsdevel@vger.kernel.org References: <20210615162346.16032-1-avagin@gmail.com> Date: Tue, 15 Jun 2021 14:33:20 -0500 In-Reply-To: <20210615162346.16032-1-avagin@gmail.com> (Andrei Vagin's message of "Tue, 15 Jun 2021 09:23:46 -0700") Message-ID: <877diuq5xb.fsf@disp2133> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1ltEoQ-00FCWx-Iw;;;mid=<877diuq5xb.fsf@disp2133>;;;hst=in02.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX18fPznuT9OQnyAy9vxmYnMlBimMoJi+D8s= X-SA-Exim-Connect-IP: 68.227.160.95 X-SA-Exim-Mail-From: ebiederm@xmission.com Subject: Re: [PATCH] exec/binfmt_script: trip zero bytes from the buffer X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Andrei Vagin writes: > Without this fix, if we try to run a script that contains only the > interpreter line, the interpreter is executed with one extra empty > argument. > > The code is written so that i_end has to be set to the end of valuable > data in the buffer. Out of curiosity how did you spot this change in behavior? > Fixes: ccbb18b67323 ("exec/binfmt_script: Don't modify bprm->buf and then return -ENOEXEC") > Cc: "Eric W. Biederman" > Signed-off-by: Andrei Vagin > --- > fs/binfmt_script.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/fs/binfmt_script.c b/fs/binfmt_script.c > index 1b6625e95958..e242680f96e1 100644 > --- a/fs/binfmt_script.c > +++ b/fs/binfmt_script.c > @@ -68,6 +68,9 @@ static int load_script(struct linux_binprm *bprm) > if (!next_terminator(i_end, buf_end)) > return -ENOEXEC; > i_end = buf_end; > + /* Trim zero bytes from i_end */ > + while (i_end[-1] == 0) > + i_end--; > } > /* Trim any trailing spaces/tabs from i_end */ > while (spacetab(i_end[-1]))