Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp5781ybh; Tue, 21 Jul 2020 14:51:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5dJACum52keHwWU74wDLnXkCboXv8Lj5o6Nb2kVR9PkpA1Ja8hiTSgg/RXaSmXHqyUhP2 X-Received: by 2002:a17:906:48d3:: with SMTP id d19mr26564822ejt.180.1595368285283; Tue, 21 Jul 2020 14:51:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595368285; cv=none; d=google.com; s=arc-20160816; b=ZK/JKZU1neLgbJ2ZMWJOVdiaVL0LQ5mfnBDpzaBi20ITZ7fnZZm/Nk6KfPcTKCoJUv t9kOIApsqAk5iPzIWXq8fnGGayUkD9yPjNnxZCRQnyD3QNF/U4a8AJRECXcnwXA9Vj84 elA3fwOTk4VAV0EC8LZeaDnjLG14fEls16XxCbYgGGyDYS0p/dM/suzHS2BL/CSqXLyG A2VVkkg3d9IgoDOn7rrhEPfSlDmpmYrz8K8BHAPP+QpfUY6M1r4h6qDioGb28V0aS/1U Xt3+LpoAGBQzwH5W7rb5raUeSnRl3GUp9eHeTKV5mZ8m9AFbTPjRPCXg2kH0W1z9vlt3 1L8Q== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=OtXnm3noZBXxKDQT2DLxkK+7Zl0OlFdckYgrPhu/bNI=; b=BuFj6kqYTc54D2decyisYD1g27f0eSmqJnLO0pBkCzezHymB/pShptX7DSANA1Vvnu ynWlhX/FlYx1ZzWaYhUsKwMl8bSLMPM7ZwqHNC3nB8+jV1Xzw/smSeMIzV+q3GvmdHYO SCDnOr3A3CzqKnoyJKz8nnIuW+Ssm9PS5wuu9tX4mlA1KIcQXWxoixh9NYU/AdaYQy3S vfFADiByZZLGqYLhOoyS7U895LvO2H41Ivwn+l3n37FSQHaAkjfraIL/WJ7Z6aRLLB84 hXFamOq1X8s6kXNkOV+iX7cFi3G6f0oeJWvwb/egZRc6fg42xUvl2pzHVO55DwTdSVoX Zifg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=QxWmqUb4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id lo2si11751568ejb.709.2020.07.21.14.51.02; Tue, 21 Jul 2020 14:51:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=QxWmqUb4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1731305AbgGUVuQ (ORCPT + 99 others); Tue, 21 Jul 2020 17:50:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731285AbgGUVuO (ORCPT ); Tue, 21 Jul 2020 17:50:14 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B2A5C061794 for ; Tue, 21 Jul 2020 14:50:14 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id k71so84396pje.0 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=JX54om+UOVESaHYvUTAYaBReQeII5Xp05LU3V5Hfwg5fvtPibg0NzGqnmWfkh4nwpe ++heQ2i5uLTBC4/BeULcZe3ayeh495WNgHl8KaEAjD+qjTBJ5vRYcZ1TwL8pf1H3aGf7 XISdZtai4PkOedu/dXko67jsfBrh9yLVFjvJwLAtpasjGHYJrIJPpG9SJhVJD6/PFys0 nzZLm7/MQ4KYwIBDfU525S9amMOEYo/Y9dIKGnQaP9/+OomvtynUUgT33zQAXYzATwQb ZpmOnQ0jHDoxOX8fYyEP6TTk6wWlht8F6CMPU/1YzJu/Tse0dgHl98HESFVF7InTMR3Q WakA== X-Gm-Message-State: AOAM532A2dxXbTPAVOUiBg1yndEL/Vuam6V5p65kcaBJCWcXDGy3usi8 LF3L88I/nmwvEGCpciC4XLe1Ew== 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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