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=-5.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 9E15CC433DF for ; Sat, 18 Jul 2020 05:44:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7EC562083B for ; Sat, 18 Jul 2020 05:44:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="L2K9eOv3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726551AbgGRFon (ORCPT ); Sat, 18 Jul 2020 01:44:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726249AbgGRFom (ORCPT ); Sat, 18 Jul 2020 01:44:42 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41FBFC0619D3 for ; Fri, 17 Jul 2020 22:44:42 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id j18so17668369wmi.3 for ; Fri, 17 Jul 2020 22:44:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=Qx6HCNIEzxBJQ2LhKKaEe4hUhhin7nepsQjM7Mz50yk=; b=L2K9eOv37PLZ5zzDhxyHvYXOmBZEIYSnPFvn+6M/BOSl30ZW2EmcNE6MbgBqKb6uAL DtC6NoAq/Lz1bMtHCx2tiVONbDEwABL8RkFUc9xMjbVGZJJm6XNiIAqvSJj5Av9TjLxb R1ALpiGmpn4tBv98T5o6rDx16T3mD1lUkHH8s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=Qx6HCNIEzxBJQ2LhKKaEe4hUhhin7nepsQjM7Mz50yk=; b=iaybnATsopNwn22xu2bt+7oEOwxNlM9GJUDx76KZUg19jQ6WjminxA7WJY67VC9Ek1 hIAOi7HqTMchYZuTwCcNIw8qzJg8irsH29y2JOxLkokuhS7NUOWiBRBT+Ux+lOUu3LMq 3r8n2sVq8HJKns8sAoCrDqazoBa84TiJiqsS+rWMCSi1EqBENKJmoqAczJSj6sklFylS 5FY6AR1ehAlPy8VY7YChCXGEUj1/KAzSICw7FhoEOcF01ixbQ+bleXWKFvzblU8PxrD+ +yduWD8QEtW3BiTdUKxBsu5ALNKdvpUTLnQ79xXioi55Wd/AiuhoxhimDrUzi5R54RE9 6WOA== X-Gm-Message-State: AOAM532aFi6WvQK5UYxosaPt2ARyaFTvSUJdnMddtuLhtMdz5F1C4Bqh Wy8r66Q22okTx/NNR+SdGL96zg== X-Google-Smtp-Source: ABdhPJw0ezTYJ55HknbzYtiAGiiPgg1mv3dIqbd4Ja9oCyuLV1RJ6FLoKAZoykHZXDrXk5gPDvEzIQ== X-Received: by 2002:a7b:c1cc:: with SMTP id a12mr12810017wmj.112.1595051080587; Fri, 17 Jul 2020 22:44:40 -0700 (PDT) Received: from [10.136.13.65] ([192.19.228.250]) by smtp.gmail.com with ESMTPSA id w7sm17168898wmc.32.2020.07.17.22.44.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 17 Jul 2020 22:44:39 -0700 (PDT) Subject: Re: [PATCH 06/13] fs/kernel_read_file: Remove redundant size argument To: Kees Cook 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 References: <20200717174309.1164575-1-keescook@chromium.org> <20200717174309.1164575-7-keescook@chromium.org> <39b2d8af-812f-8c5e-3957-34543add0173@broadcom.com> <202007171502.22E12A4E9@keescook> From: Scott Branden Message-ID: <99c58d32-da28-79ad-2fdb-83e0ca29660a@broadcom.com> Date: Fri, 17 Jul 2020 22:44:30 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <202007171502.22E12A4E9@keescook> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org Hi Kees, On 2020-07-17 3:06 p.m., Kees Cook wrote: > 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. There is something wrong with this patch.  I apply patches 1-5 and these pass the kernel self test. Patch 6 does not pass the kernel-selftest/firmware/fw_run_tests.sh >>> 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! :) >