Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2310983ybh; Fri, 17 Jul 2020 15:07:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzD4bHqC2x35zaK9f8X6eRgtZ0OQ7eTYd5d5y1IuX7bFjKdkNcKKhPlefmff5pwGFW8idj2 X-Received: by 2002:a50:b5e3:: with SMTP id a90mr10912095ede.381.1595023629345; Fri, 17 Jul 2020 15:07:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595023629; cv=none; d=google.com; s=arc-20160816; b=vOCI3x4r8wqqgBUu0tnbYAPld+vPlOrYrI1Jo4f6g/LfC2h2SK2eP8CR/v/mF7rL+/ rhAj9yJX0qaJgPAIAesIC56Hg7U5yzPH+uwYQOuCkApcH3rtZoByMRkl8EQDkQ2ccYsR wIJTMr1PeZAV61wPn/sWXSoLuFvYp+KINd7G5+69sHbuxTgfyOcfjnAlZ/GrHS4OvyAd d60B7APtJQx8ISgs2tPcL1pH/ov6bfiBDPc1LhKXE9RkWamIIaoaSpQsuQH4wyRUVTP1 Lcl4l3o0CzSmwe/Q+o5L4oo6RRxD0empmmeOwLpSN0endc+0EHj+iQWwKp8XXN5/mNHn cJzg== 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=q5TCCZgzdfgT0G/6PATrZpLazvHyt7WUQKrX1xrUKLk=; b=snOGjYo+1Z1Z6VohpPjwfEDxrqHofYE1kqkaJXJjkAYql03Q8X9yId63drSLMmt4lm bIMduTyBL42Z0Pvv8z2/OxoW+Lm63f+GelPIzwAB2KUNf47Jlop/Tb0qNJMZthNyvGXF Y5Ph9J3fAYiqFiNrA47EwTRt8XIzz+xMnbjQWOCSZqojk2ZxP4VyWmRSkSEqCjs9kQgq /6mapg8Z9esR/bqkw3mb9CF1ouCMl1B750OYZE2veS1HnmBhvLC0TM1pZM7nQtsJ0YzI gs1+lDcpdwzmRXZpD333kplEz6Q6vPCBQQLuOn2vBvRvnSzy46O/zgcyaXwUY+bPSipQ M3Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=EuxBM1YB; 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 bd16si5905510edb.20.2020.07.17.15.06.46; Fri, 17 Jul 2020 15:07:09 -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=EuxBM1YB; 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 S1727105AbgGQWGR (ORCPT + 99 others); Fri, 17 Jul 2020 18:06:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728001AbgGQWGP (ORCPT ); Fri, 17 Jul 2020 18:06:15 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85B49C0619D6 for ; Fri, 17 Jul 2020 15:06:15 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id md7so7005519pjb.1 for ; Fri, 17 Jul 2020 15:06:15 -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=q5TCCZgzdfgT0G/6PATrZpLazvHyt7WUQKrX1xrUKLk=; b=EuxBM1YB0vCqSrSBab3wG4+3G4l3LZB0r/Sy24DYkcIknVoRK1vd5FybG7DBoZMGK3 /CTYNU5fQj7jzV2LhEHV/rMxebd8TPxLdS/JqIf4QW3G3zlJPlZkenuoPSr3MjLle+Qt xVgyLZ3UJBffb9GcM/W4p9s1nh6pIolmqkWH8= 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=q5TCCZgzdfgT0G/6PATrZpLazvHyt7WUQKrX1xrUKLk=; b=ixie5ZT4ELSbo8X5RE4Uf2Dz+TZNKnqxiAf495kkElvegC86JtgDeszuHJMNsephnH V3lohUWLrK8ajuO6DnPTCHhgx9RnQreCQpLZ3BMdTQXW6F1MFiVW+9sKZMutZg5/oFiJ eAcxLEOJgijzCBx280D4coGeMCcQDKJrY6uVvWneKMqHprYfy7rN+6711r68FJH/yNJU 0PmPp/ya0WMUr+GeyKsrFvSYkaFQPrH/5KwcHcvG1VmPoLI7ux5/RoMbzP7QuZ64Za6J 744C4A4S8fHvoi1iD0oKOP2Pv3n1WRss5TzoxHATrve1kaMfcO9F16pGgWHAv9QWxtGc 7aKA== X-Gm-Message-State: AOAM531JZZq/Xpx8N23qKwuDGmST5VDUA0l6L9ynsniaDBaQ12AZgkn7 B1lFuQmnULeyKAH4s0UTVT4pkQ== X-Received: by 2002:a17:90a:9381:: with SMTP id q1mr4017193pjo.38.1595023574832; Fri, 17 Jul 2020 15:06:14 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id n18sm8896320pfd.99.2020.07.17.15.06.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jul 2020 15:06:13 -0700 (PDT) Date: Fri, 17 Jul 2020 15:06: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: <202007171502.22E12A4E9@keescook> References: <20200717174309.1164575-1-keescook@chromium.org> <20200717174309.1164575-7-keescook@chromium.org> <39b2d8af-812f-8c5e-3957-34543add0173@broadcom.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <39b2d8af-812f-8c5e-3957-34543add0173@broadcom.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 17, 2020 at 12:04:18PM -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 > > I don't think the size argument is redundant though. > The existing kernel_read_file functions always read the whole file. > Now, what happens if the file is bigger than the buffer. > How does kernel_read_file know it read the whole file by looking at the > return value? Yes; an entirely reasonable concern. This is why I add the file_size output argument later in the series. > > code, with callers adjusted. (VFS reads already cannot be larger than > > INT_MAX.) > > [...] > > - if (i_size > SIZE_MAX || (max_size > 0 && i_size > max_size)) { > > + if (i_size > INT_MAX || (max_size > 0 && i_size > max_size)) { > > Should this be SSIZE_MAX? No, for two reasons: then we need to change the return value and likely the callers need more careful checks, and more importantly, because the VFS already limits single read actions to INT_MAX, so limits above this make no sense. Win win! :) -- Kees Cook