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=-10.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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 0CECDC433EC for ; Tue, 21 Jul 2020 21:50:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DC106206E3 for ; Tue, 21 Jul 2020 21:50:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="QxWmqUb4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731308AbgGUVuQ (ORCPT ); Tue, 21 Jul 2020 17:50:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731263AbgGUVuO (ORCPT ); Tue, 21 Jul 2020 17:50:14 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BB0DC0619DC for ; Tue, 21 Jul 2020 14:50:14 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id w17so10819731ply.11 for ; Tue, 21 Jul 2020 14:50:14 -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:content-transfer-encoding:in-reply-to; bh=OtXnm3noZBXxKDQT2DLxkK+7Zl0OlFdckYgrPhu/bNI=; b=QxWmqUb4mKG2PuotWYPk5fcI5SbheLjPXQNjK35Lvm1Rv0TkWL9JoKot+e9NVXKCjD bF2yDtMqkz/MjgDZRxRrGXn8IHqBpE5MhsfMYdLw9ROIFyzGb5thGHNx2S2TsaxXTswb JB/Ot61RL6lf9nWssczNzhB3lEhtblNukhlmw= 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:content-transfer-encoding :in-reply-to; bh=OtXnm3noZBXxKDQT2DLxkK+7Zl0OlFdckYgrPhu/bNI=; b=VO0UrYYlBXLVRwhxu6y0QrUYy29E93JnUxDVe0cJWIKHCfKLgX+sI4OZ5+nvQqXpm/ NAUdNQ9eh/4JejG5luxKqbo7NIwZc6kXyKXd2Zx3k6CXcv3+AMfKsG0R2bpbkDdZj2GP a4DOaowGa6Yc5XZ6mwtcEzifA692OrcEIVy9qmNpeSdTsE7NBbKXOyrR7M3EB63e3Yyj N3xZojgr4FjT87hKpi+55nm490F2yLopFELd1cqgp/tCQ/EGzPGXem+yoHIENAvdm0eu W1HvDMB5T1VHYCHQ9ULP6gMOKdsd4IKVB9w2Nu2u2rrXN9lqKrlLsG7TXJxtR3sp3nDK xesw== X-Gm-Message-State: AOAM531ZSLi7l5uVjNqsyf4IZGSB6/SSNdXv85xhPjkrkAkAHpwARTg+ xSZzUW3pIH1qTIsIL2xbn5U88g== X-Google-Smtp-Source: ABdhPJwThYgowVNirnJUeV2auYuVRnMMUOdvkl7oi/bwggJZNAnaWjQtvFFq/bSqv6h8Tu8fyOWxUQ== X-Received: by 2002:a17:90a:2749:: with SMTP id o67mr6971010pje.183.1595368213884; Tue, 21 Jul 2020 14:50:13 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id j5sm21062058pfa.5.2020.07.21.14.50.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jul 2020 14:50:13 -0700 (PDT) Date: Tue, 21 Jul 2020 14:50:12 -0700 From: Kees Cook To: Scott Branden Cc: Mimi Zohar , Matthew Wilcox , James Morris , Luis Chamberlain , Greg Kroah-Hartman , "Rafael J. Wysocki" , Alexander Viro , Jessica Yu , Dmitry Kasatkin , "Serge E. Hallyn" , Casey Schaufler , "Eric W. Biederman" , Peter Zijlstra , Matthew Garrett , David Howells , Mauro Carvalho Chehab , Randy Dunlap , "Joel Fernandes (Google)" , KP Singh , Dave Olsthoorn , Hans de Goede , Peter Jones , Andrew Morton , Stephen Boyd , Paul Moore , Stephen Smalley , linux-security-module@vger.kernel.org, linux-integrity@vger.kernel.org, selinux@vger.kernel.org, linux-fsdevel@vger.kernel.org, kexec@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 06/13] fs/kernel_read_file: Remove redundant size argument Message-ID: <202007211449.E211351@keescook> References: <20200717174309.1164575-1-keescook@chromium.org> <20200717174309.1164575-7-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On Tue, Jul 21, 2020 at 02:43:07PM -0700, Scott Branden wrote: > On 2020-07-17 10:43 a.m., Kees Cook wrote: > > In preparation for refactoring kernel_read_file*(), remove the redundant > > "size" argument which is not needed: it can be included in the return > > code, with callers adjusted. (VFS reads already cannot be larger than > > INT_MAX.) > > > > Signed-off-by: Kees Cook > > --- > > drivers/base/firmware_loader/main.c | 8 ++++---- > > fs/kernel_read_file.c | 20 +++++++++----------- > > include/linux/kernel_read_file.h | 8 ++++---- > > kernel/kexec_file.c | 13 ++++++------- > > kernel/module.c | 7 +++---- > > security/integrity/digsig.c | 5 +++-- > > security/integrity/ima/ima_fs.c | 5 +++-- > > 7 files changed, 32 insertions(+), 34 deletions(-) > > > > diff --git a/drivers/base/firmware_loader/main.c b/drivers/base/firmware_loader/main.c > > index d4a413ea48ce..ea419c7d3d34 100644 > > --- a/drivers/base/firmware_loader/main.c > > +++ b/drivers/base/firmware_loader/main.c > > @@ -462,7 +462,7 @@ fw_get_filesystem_firmware(struct device *device, struct fw_priv *fw_priv, > > size_t in_size, > > const void *in_buffer)) > > { > > - loff_t size; > > + size_t size; > > int i, len; > > int rc = -ENOENT; > > char *path; > > @@ -494,10 +494,9 @@ fw_get_filesystem_firmware(struct device *device, struct fw_priv *fw_priv, > > fw_priv->size = 0; > > /* load firmware files from the mount namespace of init */ > > - rc = kernel_read_file_from_path_initns(path, &buffer, > > - &size, msize, > > + rc = kernel_read_file_from_path_initns(path, &buffer, msize, > > READING_FIRMWARE); > > - if (rc) { > > + if (rc < 0) { > > if (rc != -ENOENT) > > dev_warn(device, "loading %s failed with error %d\n", > > path, rc); > > @@ -506,6 +505,7 @@ fw_get_filesystem_firmware(struct device *device, struct fw_priv *fw_priv, > > path); > > continue; > > } > > + size = rc; > Change fails to return 0.  Need rc = 0; here. Oh nice; good catch! I'll fix this. -- Kees Cook