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.0 required=3.0 tests=BAYES_00, 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 BF679C433EC for ; Mon, 20 Jul 2020 08:34:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AA71B22482 for ; Mon, 20 Jul 2020 08:34:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728069AbgGTIeh convert rfc822-to-8bit (ORCPT ); Mon, 20 Jul 2020 04:34:37 -0400 Received: from eu-smtp-delivery-151.mimecast.com ([207.82.80.151]:54698 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728024AbgGTIeh (ORCPT ); Mon, 20 Jul 2020 04:34:37 -0400 Received: from AcuMS.aculab.com (156.67.243.126 [156.67.243.126]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-110-UvCh1H6SNg2kNCAjyiamHg-1; Mon, 20 Jul 2020 09:34:33 +0100 X-MC-Unique: UvCh1H6SNg2kNCAjyiamHg-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) by AcuMS.aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Mon, 20 Jul 2020 09:34:32 +0100 Received: from AcuMS.Aculab.com ([fe80::43c:695e:880f:8750]) by AcuMS.aculab.com ([fe80::43c:695e:880f:8750%12]) with mapi id 15.00.1347.000; Mon, 20 Jul 2020 09:34:32 +0100 From: David Laight To: 'Kees Cook' , 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 07/13] fs/kernel_read_file: Switch buffer size arg to size_t Thread-Topic: [PATCH 07/13] fs/kernel_read_file: Switch buffer size arg to size_t Thread-Index: AQHWXGHtmci88hmJCUOWA6z9jUdXWKkQJ6ZQ Date: Mon, 20 Jul 2020 08:34:32 +0000 Message-ID: <5db582d3ec08401eb4731ce3acd51561@AcuMS.aculab.com> References: <20200717174309.1164575-1-keescook@chromium.org> <20200717174309.1164575-8-keescook@chromium.org> In-Reply-To: <20200717174309.1164575-8-keescook@chromium.org> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Kees Cook > Sent: 17 July 2020 18:43 > In preparation for further refactoring of kernel_read_file*(), rename > the "max_size" argument to the more accurate "buf_size", and correct > its type to size_t. Add kerndoc to explain the specifics of how the > arguments will be used. Note that with buf_size now size_t, it can no > longer be negative (and was never called with a negative value). Adjust > callers to use it as a "maximum size" when *buf is NULL. > > Signed-off-by: Kees Cook > --- > fs/kernel_read_file.c | 34 +++++++++++++++++++++++--------- > include/linux/kernel_read_file.h | 8 ++++---- > security/integrity/digsig.c | 2 +- > security/integrity/ima/ima_fs.c | 2 +- > 4 files changed, 31 insertions(+), 15 deletions(-) > > diff --git a/fs/kernel_read_file.c b/fs/kernel_read_file.c > index dc28a8def597..e21a76001fff 100644 > --- a/fs/kernel_read_file.c > +++ b/fs/kernel_read_file.c > @@ -5,15 +5,31 @@ > #include > #include > > +/** > + * kernel_read_file() - read file contents into a kernel buffer > + * > + * @file file to read from > + * @buf pointer to a "void *" buffer for reading into (if > + * *@buf is NULL, a buffer will be allocated, and > + * @buf_size will be ignored) > + * @buf_size size of buf, if already allocated. If @buf not > + * allocated, this is the largest size to allocate. > + * @id the kernel_read_file_id identifying the type of > + * file contents being read (for LSMs to examine) > + * > + * Returns number of bytes read (no single read will be bigger > + * than INT_MAX), or negative on error. > + * > + */ That seems to be self-inconsistent. If '*buf' is NULL is both says that buf_size is ignored and is treated as a limit. To make life easier, zero should probably be treated as no-limit. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)