Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2275301iof; Wed, 8 Jun 2022 01:08:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfVqCldCKN0FlpojFJMcWYLxMqk7T1j8Zyntr60Knf6xMC7QIufiO2cCkkLC6Ki7GPgUrB X-Received: by 2002:a05:6a00:cd2:b0:51c:28b5:1573 with SMTP id b18-20020a056a000cd200b0051c28b51573mr11899788pfv.59.1654675706829; Wed, 08 Jun 2022 01:08:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654675706; cv=none; d=google.com; s=arc-20160816; b=YBMyN+huQZM792MGRiy2c+BR7y87X98z+CSuhqJJ/F9XJO4wNtvtV3oR3AF+tSQzwa btuuNfK/nG8DvzncnEq9OLSgYDiUnX23eEAox/sdVJhy4AxtlBx5px9Z+DvJdeeAf8E2 ZUP+PwBxuCsYVGpqjxggl4lDwoumEAv31OZRz3+dvkFelyjPRox4g47/kv8fuRDHPvdU Ml275dbjfclsv1YP4pbUBrlOr8AvSIuArx6JwqIvRhGBgibfGHpb/R1OyjDPZ8cdzLte oin2GEdpDs8F7zJI2OMqpBghg0WEVt39IPAq5wpjG6AadGsJJtjraKqh4ENk9VIw4VHc YCTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=DYVGlTfcixWRpDZ+Xnrns02OLERH2O9N67sLNCT2XaM=; b=CD+XYKWInNRpMPgN784QMCxihnrN8d6xpii5+im01xygMgGTsedBkLQpZ8qultXA25 Bh0zYL2iye4+vh+IsjMt0V2to//qfI9JHj0ddGa4SZOLjTOUpSSAJCWch2vL+TjB/tuP U4C4UTTK/hoqE4wIphO70LurKrddszcJcCipJ8nK3+ycnGYGcKwFYlGfaIfTCdmzBdCM f5KhC1d8f+/9GG2le34Rb9ESkbIu7gEFxs2OWZbZlrGbBaPYzjf3z//0a7VM4SK6RRQK 4sdQAVhAI0qa2AzMFyQz/BTBRyzow3KvVUQc2FgGABtTal8wwjq1D6NmgJjw2vnzGgpC cnTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Gn1bh9+k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id u17-20020a056a00125100b0051bbb4fb4a0si5605666pfi.15.2022.06.08.01.08.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 01:08:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Gn1bh9+k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D6B0F268550; Wed, 8 Jun 2022 00:39:24 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230179AbiFHEsV (ORCPT + 99 others); Wed, 8 Jun 2022 00:48:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231179AbiFHEr1 (ORCPT ); Wed, 8 Jun 2022 00:47:27 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9727D24802E for ; Tue, 7 Jun 2022 18:06:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654650333; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=DYVGlTfcixWRpDZ+Xnrns02OLERH2O9N67sLNCT2XaM=; b=Gn1bh9+kVoBH9IbG9htA+A+Zsm38/dVUwlQpCxRys/zDq8nMwRvfVx1OM0NdZHqU7EzATF rrfOeLJMU/dq4YuaHy752jn6ovCpaTA8HJqwJ3XCirKUwkcL9iZPG1QOw5xtAqhSDZ4KFL 1zJFbJzz0LWYMDD1bvJaFXx+w2YK2dA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-98-H_xe-6JtPiCty6iROnStrQ-1; Tue, 07 Jun 2022 20:58:59 -0400 X-MC-Unique: H_xe-6JtPiCty6iROnStrQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 50D12800124; Wed, 8 Jun 2022 00:58:59 +0000 (UTC) Received: from localhost (ovpn-12-81.pek2.redhat.com [10.72.12.81]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 783F6492C3B; Wed, 8 Jun 2022 00:58:58 +0000 (UTC) Date: Wed, 8 Jun 2022 08:58:54 +0800 From: Baoquan He To: Pasha Tatashin Cc: sashal@kernel.org, ebiederm@xmission.com, rburanyi@google.com, akpm@linux-foundation.org, gthelen@google.com, viro@zeniv.linux.org.uk, kexec@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/2] fs/kernel_read_file: Allow to read files up-to ssize_t Message-ID: References: <20220527025535.3953665-1-pasha.tatashin@soleen.com> <20220527025535.3953665-2-pasha.tatashin@soleen.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220527025535.3953665-2-pasha.tatashin@soleen.com> X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/27/22 at 02:55am, Pasha Tatashin wrote: > Currently, the maximum file size that is supported is 2G. This may be > too small in some cases. For example, kexec_file_load() system call > loads initramfs. In some netboot cases initramfs can be rather large. > > Allow to use up-to ssize_t bytes. The callers still can limit the > maximum file size via buf_size. LGTM, Acked-by: Baoquan He > > Signed-off-by: Pasha Tatashin > --- > fs/kernel_read_file.c | 38 ++++++++++++++++---------------- > include/linux/kernel_read_file.h | 32 +++++++++++++-------------- > include/linux/limits.h | 1 + > 3 files changed, 36 insertions(+), 35 deletions(-) > > diff --git a/fs/kernel_read_file.c b/fs/kernel_read_file.c > index 1b07550485b9..5d826274570c 100644 > --- a/fs/kernel_read_file.c > +++ b/fs/kernel_read_file.c > @@ -29,15 +29,15 @@ > * change between calls to kernel_read_file(). > * > * Returns number of bytes read (no single read will be bigger > - * than INT_MAX), or negative on error. > + * than SSIZE_MAX), or negative on error. > * > */ > -int kernel_read_file(struct file *file, loff_t offset, void **buf, > - size_t buf_size, size_t *file_size, > - enum kernel_read_file_id id) > +ssize_t kernel_read_file(struct file *file, loff_t offset, void **buf, > + size_t buf_size, size_t *file_size, > + enum kernel_read_file_id id) > { > loff_t i_size, pos; > - size_t copied; > + ssize_t copied; > void *allocated = NULL; > bool whole_file; > int ret; > @@ -58,7 +58,7 @@ int kernel_read_file(struct file *file, loff_t offset, void **buf, > goto out; > } > /* The file is too big for sane activities. */ > - if (i_size > INT_MAX) { > + if (i_size > SSIZE_MAX) { > ret = -EFBIG; > goto out; > } > @@ -124,12 +124,12 @@ int kernel_read_file(struct file *file, loff_t offset, void **buf, > } > EXPORT_SYMBOL_GPL(kernel_read_file); > > -int kernel_read_file_from_path(const char *path, loff_t offset, void **buf, > - size_t buf_size, size_t *file_size, > - enum kernel_read_file_id id) > +ssize_t kernel_read_file_from_path(const char *path, loff_t offset, void **buf, > + size_t buf_size, size_t *file_size, > + enum kernel_read_file_id id) > { > struct file *file; > - int ret; > + ssize_t ret; > > if (!path || !*path) > return -EINVAL; > @@ -144,14 +144,14 @@ int kernel_read_file_from_path(const char *path, loff_t offset, void **buf, > } > EXPORT_SYMBOL_GPL(kernel_read_file_from_path); > > -int kernel_read_file_from_path_initns(const char *path, loff_t offset, > - void **buf, size_t buf_size, > - size_t *file_size, > - enum kernel_read_file_id id) > +ssize_t kernel_read_file_from_path_initns(const char *path, loff_t offset, > + void **buf, size_t buf_size, > + size_t *file_size, > + enum kernel_read_file_id id) > { > struct file *file; > struct path root; > - int ret; > + ssize_t ret; > > if (!path || !*path) > return -EINVAL; > @@ -171,12 +171,12 @@ int kernel_read_file_from_path_initns(const char *path, loff_t offset, > } > EXPORT_SYMBOL_GPL(kernel_read_file_from_path_initns); > > -int kernel_read_file_from_fd(int fd, loff_t offset, void **buf, > - size_t buf_size, size_t *file_size, > - enum kernel_read_file_id id) > +ssize_t kernel_read_file_from_fd(int fd, loff_t offset, void **buf, > + size_t buf_size, size_t *file_size, > + enum kernel_read_file_id id) > { > struct fd f = fdget(fd); > - int ret = -EBADF; > + ssize_t ret = -EBADF; > > if (!f.file || !(f.file->f_mode & FMODE_READ)) > goto out; > diff --git a/include/linux/kernel_read_file.h b/include/linux/kernel_read_file.h > index 575ffa1031d3..90451e2e12bd 100644 > --- a/include/linux/kernel_read_file.h > +++ b/include/linux/kernel_read_file.h > @@ -35,21 +35,21 @@ static inline const char *kernel_read_file_id_str(enum kernel_read_file_id id) > return kernel_read_file_str[id]; > } > > -int kernel_read_file(struct file *file, loff_t offset, > - void **buf, size_t buf_size, > - size_t *file_size, > - enum kernel_read_file_id id); > -int kernel_read_file_from_path(const char *path, loff_t offset, > - void **buf, size_t buf_size, > - size_t *file_size, > - enum kernel_read_file_id id); > -int kernel_read_file_from_path_initns(const char *path, loff_t offset, > - void **buf, size_t buf_size, > - size_t *file_size, > - enum kernel_read_file_id id); > -int kernel_read_file_from_fd(int fd, loff_t offset, > - void **buf, size_t buf_size, > - size_t *file_size, > - enum kernel_read_file_id id); > +ssize_t kernel_read_file(struct file *file, loff_t offset, > + void **buf, size_t buf_size, > + size_t *file_size, > + enum kernel_read_file_id id); > +ssize_t kernel_read_file_from_path(const char *path, loff_t offset, > + void **buf, size_t buf_size, > + size_t *file_size, > + enum kernel_read_file_id id); > +ssize_t kernel_read_file_from_path_initns(const char *path, loff_t offset, > + void **buf, size_t buf_size, > + size_t *file_size, > + enum kernel_read_file_id id); > +ssize_t kernel_read_file_from_fd(int fd, loff_t offset, > + void **buf, size_t buf_size, > + size_t *file_size, > + enum kernel_read_file_id id); > > #endif /* _LINUX_KERNEL_READ_FILE_H */ > diff --git a/include/linux/limits.h b/include/linux/limits.h > index b568b9c30bbf..f6bcc9369010 100644 > --- a/include/linux/limits.h > +++ b/include/linux/limits.h > @@ -7,6 +7,7 @@ > #include > > #define SIZE_MAX (~(size_t)0) > +#define SSIZE_MAX ((ssize_t)(SIZE_MAX >> 1)) > #define PHYS_ADDR_MAX (~(phys_addr_t)0) > > #define U8_MAX ((u8)~0U) > -- > 2.36.1.124.g0e6072fb45-goog >