Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2033072iof; Tue, 7 Jun 2022 17:37:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwjjIOHqv8khLQpINJ6BQzf50lsm4ZpTCArZuV+Eu9bPykOU7BFbA/6hXaJoeDtqnYOTVMa X-Received: by 2002:a63:dd17:0:b0:3fd:695e:8728 with SMTP id t23-20020a63dd17000000b003fd695e8728mr16075780pgg.70.1654648637342; Tue, 07 Jun 2022 17:37:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654648637; cv=none; d=google.com; s=arc-20160816; b=0uOIa90WREx4Fmq5+nkgDg28NCmvNZQQ5Cs9DktpPhI2Kxx00uNXo+8AEDdx6U5BIx 0/cNmwO7aYMfgpdLL1J7U5IAbSJWBgEtoyYywRga4JHz1UXjvLnmoykI/2F5noKYR4Yb XaoFYNtFC2U+kCo9VUNUB1x366T1yeEMRp6t0syAVAsUftOa8VXtFXtUCAFj2g7Avbsc b4OhntTooPbEjs56eJwkL0wLDlbxB2qqOuUZZHS6UCjLLGLCJZt06RWi2N3zBHFDSjNP WJn4VjDJHG8f44CLnWYECAFb04DgD+GW+zr0a8RSlcRC6gRuq2ytRYAryJVkPhfgzVVo /HPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=pufS40r/uX2ZtSB9s8FIZ6SlwwrSkU1jYicxPJP0Dvk=; b=tf4FN/o36vi4J3oF+PcvrCiFlrD11LJRDWNu+a7Raw2i5Ssxa0WvdPB9EVcOPg+23K rGP0C2fkFu5f5+xJdoPnKAGtl5gYk3Rz+BWYLXsSN5nAOnbK8IwewrvpWNkUmoRIB+dM LCeZ2M1W/5tcZllEojRDhlLaQG4jjVH42+bgsTWALpOabbNlakemmvvgSnGEBAf4nf2I HZB6RwB82tOkjR8oWlODrKvHICHS+dOlLdcb4Ul6HehYYyGy2G91dZlRo5koICw6ToQC 91Te/lzyBptW8grQ1MrjBu1kvEKSF1yR0JFoV1j7DV/q7Lx51+W6PFGF2axXYhmtdYxz +7mA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b="EI/3FnfD"; 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 Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id pg5-20020a17090b1e0500b001e887404411si10955531pjb.8.2022.06.07.17.37.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 17:37:17 -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=@soleen.com header.s=google header.b="EI/3FnfD"; 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1DA851DBD4B; Tue, 7 Jun 2022 17:27:38 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344661AbiFGPyH (ORCPT + 99 others); Tue, 7 Jun 2022 11:54:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344566AbiFGPxI (ORCPT ); Tue, 7 Jun 2022 11:53:08 -0400 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96435255A6 for ; Tue, 7 Jun 2022 08:52:56 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id fu3so34592823ejc.7 for ; Tue, 07 Jun 2022 08:52:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=pufS40r/uX2ZtSB9s8FIZ6SlwwrSkU1jYicxPJP0Dvk=; b=EI/3FnfDm7xULUdj70TuQ6pbIIND9Ooo8uGbWhUrAbDTViCBtm4wpTdixdKFNo4aCK f1yE8jNnKNNOTXbuS4EI/9GbcqVUEVRKTQAMSj3vIvvF7eKo91aVzAsh+nLIzVm54tDG z01TQWwsfS6Mcq+/5BW/nW49mcHHd4TAfDhm5S3Bd3Ge5bxjx8cLjrLZ2URBEjFD9ZrX ZQ+oyGHvCBvbSRIasswi2yzcD8CmeiaKpp1BdunZwyBJmGWKE5c8hKDc4LWDi+6Wy66h urZhDietLh4l7fsCWLfQixf/BNyrrizYPXwqKUq0kF6CmoqighGAY+ed/Cz//ADdglzR FC/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=pufS40r/uX2ZtSB9s8FIZ6SlwwrSkU1jYicxPJP0Dvk=; b=Hl1fHvfOywAf3j8cNa4V3qt/FqBOpJXTal6be26O5nlLIptu5Re/bnTROVA5gMCJ8+ uRK1CeE6k48jtDlwWy8Mv4I8XaREzgvgDzJ3bckNF6H5hXbI5S3vt5mkgndI+OuaKRiB LUVXP+gRA41oXutKid1WaD6u1sspi4d7U1VHfiHwM+o35z1Q6lkQgUWH9WUSPZ3qcE4V Q+GtVj5zSBB+pzXaNeBwzMdgdQbrdG3T4xmz7CCEnG4lbfp8yhrk7IrrgiysDCJcFHBQ Q+NC3YOdRZJSyaMPKik4jcsVdKs0BgRVG/mdEltKdQz2Pf3aWpm/XzHJiNPilxMW6y8H KGAQ== X-Gm-Message-State: AOAM531Lnf2nEix9hr0aX+J+vgn/H1LmybGwXqKDDY5ajqVXCvMv4Bu/ xokahcIGDjBH71FmXqHSv34ftLW7y6yS7amtW4jMug== X-Received: by 2002:a17:907:90c8:b0:711:c8e1:7109 with SMTP id gk8-20020a17090790c800b00711c8e17109mr12331055ejb.492.1654617176082; Tue, 07 Jun 2022 08:52:56 -0700 (PDT) MIME-Version: 1.0 References: <20220527025535.3953665-1-pasha.tatashin@soleen.com> <20220527025535.3953665-2-pasha.tatashin@soleen.com> In-Reply-To: From: Pasha Tatashin Date: Tue, 7 Jun 2022 11:52:18 -0400 Message-ID: Subject: Re: [PATCH v2 1/2] fs/kernel_read_file: Allow to read files up-to ssize_t To: Baoquan He Cc: Sasha Levin , "Eric W. Biederman" , rburanyi@google.com, Greg Thelen , viro@zeniv.linux.org.uk, kexec mailing list , linux-fsdevel@vger.kernel.org, LKML Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,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=no 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 Sun, Jun 5, 2022 at 10:45 PM Baoquan He wrote: > > 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. > > If we really met initramfs bigger than 2G, it's reasonable to increase > the limit. While wondering why we should take sszie_t, but not size_t. ssize_t instead of size_t so we can return errors as negative values. Pasha > > > > > 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 > > >