Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2397424ioo; Sat, 28 May 2022 12:20:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBDgd2q9G/GnX7UtDaMb9PTVHhTTpYAVjekpoCIK+Gx0Hi/GOj0i9m1HXzPJO8rSvOcw3U X-Received: by 2002:a17:902:f605:b0:14d:9e11:c864 with SMTP id n5-20020a170902f60500b0014d9e11c864mr48886099plg.54.1653765625598; Sat, 28 May 2022 12:20:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653765625; cv=none; d=google.com; s=arc-20160816; b=Ym1mGxdWwUjGBC+kUTUhc5C62cGzeOx/527CmgFuu8H3oitwUJx40Sj+063gfIk4S6 g9orO6hI+sLWC3j4IW80e/vPOFK7xh/AWpYXLZDVNOjj2mRCz1G6GhwAXrtubu0s3Vxm /EVdo4XFVnESXMrzdrthLKhon6ykFviP6360RbMfbJieaAaWRQUtptUpQODJuf4HhRkY PwC9oXzVxtPtSe5IWAyTlSbBVDSfcARgfa1nio5ObCmQUYZiyLh6mXh+RJKbUqDsmnc9 7oB0kH1vJD5GtYgfj42LNDuXUH7P9vnlSqIVIAd2IGFYOnOTHOVj7f9nUgAWDnIdzqVQ mCxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=ySBNZU6lTetRSaVW2fEw2gpViA/ZXifxYmfC+h6QNCw=; b=t2woIaqY3+z+wU2+EUdNS/Tw+m6PeZOpk7U4ENYk0oZn2D+Pfs4+CB596R+LlfAxcC 9uaq77lsS1Tmqw1GoINaFDHRX1FbBCIMvNL22D6zvHGLlDZBqcWdqrytQvP1XDOvynEm VDV/a1AxA37MInkUXM9ZeslWCWM2ruLrX0GHh+LcJ+QBZoRosjJx28aT16TftNpbMoI9 LwMfwQswwHsNOBgs/8dr54FR3b0caOCxDZ4nFd0rofgJ4pfxOAHngcEzHv1bNk2Lz3vr w/vRDJRPG4bK3YzEuSnJjG7WYIWF6ln22dK9tKkiG8mNiiQZJq8huS2zRXwe1jzAe4tx TCJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b=cUeNnxsR; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id lb17-20020a17090b4a5100b001d9752b43absi8523245pjb.137.2022.05.28.12.20.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 May 2022 12:20:25 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b=cUeNnxsR; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 2AB474991C; Sat, 28 May 2022 11:52:36 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237670AbiE0Czx (ORCPT + 99 others); Thu, 26 May 2022 22:55:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237424AbiE0Czm (ORCPT ); Thu, 26 May 2022 22:55:42 -0400 Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [IPv6:2607:f8b0:4864:20::82d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 873CDEAD03 for ; Thu, 26 May 2022 19:55:40 -0700 (PDT) Received: by mail-qt1-x82d.google.com with SMTP id bl14so2892910qtb.1 for ; Thu, 26 May 2022 19:55:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ySBNZU6lTetRSaVW2fEw2gpViA/ZXifxYmfC+h6QNCw=; b=cUeNnxsRG8t2Qzja4DgxxM1AK7sikwqYFTt3KXNyL4gP/pZf6DkawTnReOw+19ZKHg GhvXpFpkN6ImwQTJuQANnzTQWTXa1cZlKIhJ75EOhY+ycqi7LxV2riuaRCDuQQ4d2aHy Zt+Izf1V5ozjavOPXzVHtJYwKa8Bzb8eD5vyAeL1VLaZbMMBAAlxDTogm9AKxWJ/qTPX H8ASzCQCqkhd1ALBs7zfI/ft4Awy2kaRLeNf4LxTbBxZ7OLEZMNC1FjwimmIrjWzJbCf y1pRVKENcyFRHoHSGT0H1/BA0Vb6PhUsREKRwuCqMNbZu8QuXIUY9kXhPW8pZFPz7f0h /NfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ySBNZU6lTetRSaVW2fEw2gpViA/ZXifxYmfC+h6QNCw=; b=4QO2wgsfNC0m5J3wIuGRm9sZyCGpTxXpJL89VrpnlVFVQZ/QpfgnCPGFmTAJ3WpqOW u/K87PXq38SEEesb4NZ/l9Pki+JEbhdQWpu+Q5Jsj3lnt80N+2YCx1Ndq61tO/FX0Vw1 9Q9TP4u7xaRGV+GAJYEtgMIMRXtClYZ4U7Qaj0cdXDf4DADH30cGYXRvM+BCQ67Q6PII 2W4/BMEJPYePdhOj/t4AKYYM326PukQvu2cFWnarVn79mEARQdkBrL3zAhfA/9N8ro0Q eK9PcdhdxRQTHpZ5OqMD3KqIOj7OH7eZ82THJvzBPiRi83+PZHfGsjhGIGT3z3NL6ouQ x3bA== X-Gm-Message-State: AOAM531Kvk5putJIbJPjDg35S3W1JoqqQiEPPIiiGprn6nDLDbbwpLHK KE+5cwC8DXM/oeq5rowwv/qWnQ== X-Received: by 2002:ac8:5b15:0:b0:2f3:ea22:d265 with SMTP id m21-20020ac85b15000000b002f3ea22d265mr31701014qtw.453.1653620139658; Thu, 26 May 2022 19:55:39 -0700 (PDT) Received: from soleen.c.googlers.com.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id r129-20020ae9dd87000000b0069fc13ce224sm2129672qkf.85.2022.05.26.19.55.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 May 2022 19:55:39 -0700 (PDT) From: Pasha Tatashin To: pasha.tatashin@soleen.com, sashal@kernel.org, ebiederm@xmission.com, rburanyi@google.com, gthelen@google.com, viro@zeniv.linux.org.uk, kexec@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] fs/kernel_read_file: Allow to read files up-to ssize_t Date: Fri, 27 May 2022 02:55:34 +0000 Message-Id: <20220527025535.3953665-2-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.36.1.124.g0e6072fb45-goog In-Reply-To: <20220527025535.3953665-1-pasha.tatashin@soleen.com> References: <20220527025535.3953665-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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. 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