Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1575064ybh; Mon, 20 Jul 2020 01:36:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx50T4P3GxeOJpv8asGCg37XysVrHdlTorivO29VwVIGXCc0p2X2xFc/rNDHFybilxhHT4D X-Received: by 2002:a17:906:d116:: with SMTP id b22mr19158665ejz.250.1595234191984; Mon, 20 Jul 2020 01:36:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595234191; cv=none; d=google.com; s=arc-20160816; b=Xd/mpx4LP7kK/a/OoOoCSjT25Ku8NNd+W9GwNGqzSB2PIFNj601JzFoaZ6MJxXU/9N UmIZZqf5fkQP0cjvNpYG5YtmBUEExH14/DAtKsQtYWh5kda3FSpnWvwDhFQUKiZh7xdg zWJqR/tmHEVSVpRZgyygJOCG3I4hvjwrUcHP0lcu+rdXTN6VTiyxM0f1hend6BdE4r/0 zjQj54Ssy6y7Ohpsm1x0ekIMohWuRtr8Epj60FepXWFH5IY+cAC/ysR9ucxLSjJiCzIY a00sN6YJnepxL63M+424ryemGtPDmxqN7f3boOce7+siVsRtj4u8WaaUDiIkw1njyXH1 n2Ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from; bh=G7ehZOYNoBeFgMJV/Dgj7veZrkMcEdqM3QPmi/irLsw=; b=Bf8eiDutYLW6s6dT75LS+ulpCQ8HTd2paIbRvnzEcfCy+OUYhIBX6+ri0EgIYJqlRc rm9RAwLVzKHMsFZLb/gPgM5l+SBoCYELSMLbE7UXd67mfDn2wpPnvSZ7NqoFtlTD9w6+ wkh5w6l9ZtG/i2lZmPQ0d63VBryWtVmASZWqAViZ5h9mYR5+QiQgRPc7ngD4Bks4DYBt rN/AilWTHhofFXS2ohw+z/joKI8LRAxJZ1wmeOvQy6qbp5wHTp44lAbhN3d7d3UuCbuB Ygv0Wc7sRCuP6oj1w/llUe0w0wakvS4cJ9ymVCcz7tQ1y0GW4zsumPoAStkBhrHN9Xwp mmZA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j3si10169954edt.8.2020.07.20.01.36.09; Mon, 20 Jul 2020 01:36:31 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728080AbgGTIei convert rfc822-to-8bit (ORCPT + 99 others); Mon, 20 Jul 2020 04:34:38 -0400 Received: from eu-smtp-delivery-151.mimecast.com ([207.82.80.151]:21996 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728063AbgGTIeh (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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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)