From patchwork Wed May 29 17:43:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10967383 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6D9EC76 for ; Wed, 29 May 2019 17:43:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5FD8C2000A for ; Wed, 29 May 2019 17:43:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 50C4C28A61; Wed, 29 May 2019 17:43:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D915C28917 for ; Wed, 29 May 2019 17:43:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726520AbfE2Rnd (ORCPT ); Wed, 29 May 2019 13:43:33 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:33882 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726205AbfE2Rnc (ORCPT ); Wed, 29 May 2019 13:43:32 -0400 Received: by mail-wr1-f66.google.com with SMTP id f8so2421338wrt.1; Wed, 29 May 2019 10:43:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7z+URgKWKe9baBNXTRuiwAT8xxeo4lu6F54jeoU5vwA=; b=KirtEW/OGmn/qiY+9wme5Gh5KIVAoljOuFx+nMJamoVSeYIrxdiMzYn5QLUjJMNJI6 uozf24MrBZM0dh6RM6ilar+ioPNQplygnIYbQIwa/ooqLWPqBuBrhlnV2e3V9HQ4h/U9 XehykFGHiUsLCVmkzhfm/g2TAxLfNksM6q/YBky875wc79vfxcR/woBE98CUs3G1oZJD YwkLoRKuk/Piz4QruovX3eZYqXkGG8szNks90JbPDg8zJiAYTUAqJ/4w4TO0qDTuFFAn jrtwm0R+s8pM5yemqSKfFpK++gJfbK3DIbyxZfQfY74slW/PepSLQZFSEs5z6x0xMAoU +5gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7z+URgKWKe9baBNXTRuiwAT8xxeo4lu6F54jeoU5vwA=; b=ddMImk2vUJtWqV1qabtcdIqysuUbwayZ5EOFZHOAlumZ4lzec7wM03HWvnIPIAuN5Y xT+QLeu1KJ21CZOu04ElVQxkpYtITOR1VMwBWBzb5Ow3kw9e7DYa3uUefljVwr+nHODU 1Q8NqsdPCr2UlFtVzgRNODb9zn1xXOjUdTTW6ivfR/S6D7BuWbrORrSYz8wYxvlXvYKr pAzrVjuc84GWH0vPiF8dAtIGi9F0BnCay0cReA6sIDBs+TkY86d9jDgLahun0OkLJpF5 n6NR3Cu2SgefkAO8NPieQpO6Baq0NS+b/0T+Boc5WBgYcQwz0sopHnQ2zbdqQrYfmJqD KXDA== X-Gm-Message-State: APjAAAUQ8O8/W7qf6gvnsogKDFVx6LjS4qXdHha4UlNruS68uWBXEriY o1OcyO9vQ1l5ponwQ/iZH64= X-Google-Smtp-Source: APXvYqyjgzK5zYt1nLkJV1PTASxLCO9v2WEdLQlqLK3u4kKgGoubOcok7hkiDoMtwj/6Q0nO7aqF6A== X-Received: by 2002:adf:8bc5:: with SMTP id w5mr41103202wra.132.1559151809932; Wed, 29 May 2019 10:43:29 -0700 (PDT) Received: from localhost.localdomain ([5.102.238.208]) by smtp.gmail.com with ESMTPSA id k125sm31702wmb.34.2019.05.29.10.43.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 May 2019 10:43:29 -0700 (PDT) From: Amir Goldstein To: "Darrick J . Wong" Cc: Dave Chinner , Christoph Hellwig , linux-xfs@vger.kernel.org, Olga Kornievskaia , Luis Henriques , Al Viro , linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, ceph-devel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, Dave Chinner Subject: [PATCH v3 01/13] vfs: introduce generic_copy_file_range() Date: Wed, 29 May 2019 20:43:05 +0300 Message-Id: <20190529174318.22424-2-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190529174318.22424-1-amir73il@gmail.com> References: <20190529174318.22424-1-amir73il@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Dave Chinner Right now if vfs_copy_file_range() does not use any offload mechanism, it falls back to calling do_splice_direct(). This fails to do basic sanity checks on the files being copied. Before we start adding this necessarily functionality to the fallback path, separate it out into generic_copy_file_range(). generic_copy_file_range() has the same prototype as ->copy_file_range() so that filesystems can use it in their custom ->copy_file_range() method if they so choose. Signed-off-by: Dave Chinner Signed-off-by: Amir Goldstein Reviewed-by: Darrick J. Wong --- fs/read_write.c | 35 ++++++++++++++++++++++++++++++++--- include/linux/fs.h | 3 +++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index c543d965e288..676b02fae589 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1565,6 +1565,36 @@ COMPAT_SYSCALL_DEFINE4(sendfile64, int, out_fd, int, in_fd, } #endif +/** + * generic_copy_file_range - copy data between two files + * @file_in: file structure to read from + * @pos_in: file offset to read from + * @file_out: file structure to write data to + * @pos_out: file offset to write data to + * @len: amount of data to copy + * @flags: copy flags + * + * This is a generic filesystem helper to copy data from one file to another. + * It has no constraints on the source or destination file owners - the files + * can belong to different superblocks and different filesystem types. Short + * copies are allowed. + * + * This should be called from the @file_out filesystem, as per the + * ->copy_file_range() method. + * + * Returns the number of bytes copied or a negative error indicating the + * failure. + */ + +ssize_t generic_copy_file_range(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + size_t len, unsigned int flags) +{ + return do_splice_direct(file_in, &pos_in, file_out, &pos_out, + len > MAX_RW_COUNT ? MAX_RW_COUNT : len, 0); +} +EXPORT_SYMBOL(generic_copy_file_range); + /* * copy_file_range() differs from regular file read and write in that it * specifically allows return partial success. When it does so is up to @@ -1632,9 +1662,8 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, goto done; } - ret = do_splice_direct(file_in, &pos_in, file_out, &pos_out, - len > MAX_RW_COUNT ? MAX_RW_COUNT : len, 0); - + ret = generic_copy_file_range(file_in, pos_in, file_out, pos_out, len, + flags); done: if (ret > 0) { fsnotify_access(file_in); diff --git a/include/linux/fs.h b/include/linux/fs.h index f7fdfe93e25d..ea17858310ff 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1889,6 +1889,9 @@ extern ssize_t vfs_readv(struct file *, const struct iovec __user *, unsigned long, loff_t *, rwf_t); extern ssize_t vfs_copy_file_range(struct file *, loff_t , struct file *, loff_t, size_t, unsigned int); +extern ssize_t generic_copy_file_range(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + size_t len, unsigned int flags); extern int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, loff_t *count, From patchwork Wed May 29 17:43:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10967391 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EC909933 for ; Wed, 29 May 2019 17:43:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DDFAA2856E for ; Wed, 29 May 2019 17:43:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DBFEC288DA; Wed, 29 May 2019 17:43:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 496F52856E for ; Wed, 29 May 2019 17:43:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727003AbfE2Rng (ORCPT ); Wed, 29 May 2019 13:43:36 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:45616 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725917AbfE2Rne (ORCPT ); Wed, 29 May 2019 13:43:34 -0400 Received: by mail-wr1-f67.google.com with SMTP id b18so2360045wrq.12; Wed, 29 May 2019 10:43:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+W6U4ETnLrYkikxbMk/wh3iIEZoEwtztQ/QLH5NUi74=; b=ifWmmDQAHCoqZv+08IMNQwcl3vT3mFrhJwtgx0agF0t1rv94ZjdJ+1/Qz2ZzkxgdRB /Y26IvD4wlwQG9KgP9CXtHCTvmJRonYuD82WRCqSW3cVVLKQUSD06tAHq1E4g1bc5WM8 gJQX28nF2uFE2SQ5owL/3qfbYYlT8++wQSY5mtq7/YeujWf6vskMAhyiT3hdreh/2RU8 eMgDzSvHQY6YdZUg3117teWUwhTRKSBCJzYnnM08WvqGBtL00+xkBqVhkG2f9H8xZrDF C8p8tKwIYlc3zdB2mBorWe4t1CLUi6V2xrJNrDzA8/6PGo+6fki/LBFdp+it0PsRhlMP aigQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+W6U4ETnLrYkikxbMk/wh3iIEZoEwtztQ/QLH5NUi74=; b=WDAWwTxJhOkmdehPyIcikBf1V2AKRPzQEgatP3mc00/wdlMcGCbBc8HD8IsZ+PSm8r 0uN4WYzodEI3FXH1mnS4LHZ5vQi6B2jiSNvIw7GhJk6mpY4g+8DQZa0iu2nmAub97/4r TqIVDvqYK9QkikW/zUnbyv0ck/Csn4ZsIJ7TlWXok/07j7wUzf5Ojf42Lav7hYJsG6P6 qD8v7sbbq6pTcBqSllA4PPbuWYHU9UBsMbEPzcz4bDugoig0+tWvoZdVQX5n3ldkq+2O M/C8cA+9eP9/L3/iSegeH9smYLIW8zNKg5pcWUOzU5vkBRkANallu47IRqfAQhK19FX0 vAMg== X-Gm-Message-State: APjAAAVXl5mOeRvssX/Yfm7wNb00zM7kRdW3QcdpZUdNVNzeKi19lVcn d0vcVHhjhYDTlmuOU3NY3NU= X-Google-Smtp-Source: APXvYqxXy6efjOTuKd1UtXyaOx74f+byvZTB6d49G9ysXIZOw2+uyuPsS68sOCEIr723KC7lixtdDw== X-Received: by 2002:a05:6000:110:: with SMTP id o16mr2703551wrx.200.1559151811898; Wed, 29 May 2019 10:43:31 -0700 (PDT) Received: from localhost.localdomain ([5.102.238.208]) by smtp.gmail.com with ESMTPSA id k125sm31702wmb.34.2019.05.29.10.43.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 May 2019 10:43:31 -0700 (PDT) From: Amir Goldstein To: "Darrick J . Wong" Cc: Dave Chinner , Christoph Hellwig , linux-xfs@vger.kernel.org, Olga Kornievskaia , Luis Henriques , Al Viro , linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, ceph-devel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, Dave Chinner Subject: [PATCH v3 02/13] vfs: no fallback for ->copy_file_range Date: Wed, 29 May 2019 20:43:06 +0300 Message-Id: <20190529174318.22424-3-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190529174318.22424-1-amir73il@gmail.com> References: <20190529174318.22424-1-amir73il@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Dave Chinner Now that we have generic_copy_file_range(), remove it as a fallback case when offloads fail. This puts the responsibility for executing fallbacks on the filesystems that implement ->copy_file_range and allows us to add operational validity checks to generic_copy_file_range(). Rework vfs_copy_file_range() to call a new do_copy_file_range() helper to execute the copying callout, and move calls to generic_file_copy_range() into filesystem methods where they currently return failures. [Amir] overlayfs is not responsible of executing the fallback. It is the responsibility of the underlying filesystem. Signed-off-by: Dave Chinner Signed-off-by: Amir Goldstein Reviewed-by: Darrick J. Wong --- fs/ceph/file.c | 21 ++++++++++++++++++--- fs/cifs/cifsfs.c | 4 ++++ fs/fuse/file.c | 21 ++++++++++++++++++--- fs/nfs/nfs4file.c | 20 +++++++++++++++++--- fs/read_write.c | 25 ++++++++++++++++--------- 5 files changed, 73 insertions(+), 18 deletions(-) diff --git a/fs/ceph/file.c b/fs/ceph/file.c index 305daf043eb0..e87f7b2023af 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -1889,9 +1889,9 @@ static int is_file_size_ok(struct inode *src_inode, struct inode *dst_inode, return 0; } -static ssize_t ceph_copy_file_range(struct file *src_file, loff_t src_off, - struct file *dst_file, loff_t dst_off, - size_t len, unsigned int flags) +static ssize_t __ceph_copy_file_range(struct file *src_file, loff_t src_off, + struct file *dst_file, loff_t dst_off, + size_t len, unsigned int flags) { struct inode *src_inode = file_inode(src_file); struct inode *dst_inode = file_inode(dst_file); @@ -2100,6 +2100,21 @@ static ssize_t ceph_copy_file_range(struct file *src_file, loff_t src_off, return ret; } +static ssize_t ceph_copy_file_range(struct file *src_file, loff_t src_off, + struct file *dst_file, loff_t dst_off, + size_t len, unsigned int flags) +{ + ssize_t ret; + + ret = __ceph_copy_file_range(src_file, src_off, dst_file, dst_off, + len, flags); + + if (ret == -EOPNOTSUPP) + ret = generic_copy_file_range(src_file, src_off, dst_file, + dst_off, len, flags); + return ret; +} + const struct file_operations ceph_file_fops = { .open = ceph_open, .release = ceph_release, diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index f5fcd6360056..c65823270313 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -1148,6 +1148,10 @@ static ssize_t cifs_copy_file_range(struct file *src_file, loff_t off, rc = cifs_file_copychunk_range(xid, src_file, off, dst_file, destoff, len, flags); free_xid(xid); + + if (rc == -EOPNOTSUPP) + rc = generic_copy_file_range(src_file, off, dst_file, + destoff, len, flags); return rc; } diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 3959f08279e6..e03901ae729b 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -3097,9 +3097,9 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset, return err; } -static ssize_t fuse_copy_file_range(struct file *file_in, loff_t pos_in, - struct file *file_out, loff_t pos_out, - size_t len, unsigned int flags) +static ssize_t __fuse_copy_file_range(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + size_t len, unsigned int flags) { struct fuse_file *ff_in = file_in->private_data; struct fuse_file *ff_out = file_out->private_data; @@ -3173,6 +3173,21 @@ static ssize_t fuse_copy_file_range(struct file *file_in, loff_t pos_in, return err; } +static ssize_t fuse_copy_file_range(struct file *src_file, loff_t src_off, + struct file *dst_file, loff_t dst_off, + size_t len, unsigned int flags) +{ + ssize_t ret; + + ret = __fuse_copy_file_range(src_file, src_off, dst_file, dst_off, + len, flags); + + if (ret == -EOPNOTSUPP) + ret = generic_copy_file_range(src_file, src_off, dst_file, + dst_off, len, flags); + return ret; +} + static const struct file_operations fuse_file_operations = { .llseek = fuse_file_llseek, .read_iter = fuse_file_read_iter, diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c index cf42a8b939e3..4842f3ab3161 100644 --- a/fs/nfs/nfs4file.c +++ b/fs/nfs/nfs4file.c @@ -129,9 +129,9 @@ nfs4_file_flush(struct file *file, fl_owner_t id) } #ifdef CONFIG_NFS_V4_2 -static ssize_t nfs4_copy_file_range(struct file *file_in, loff_t pos_in, - struct file *file_out, loff_t pos_out, - size_t count, unsigned int flags) +static ssize_t __nfs4_copy_file_range(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + size_t count, unsigned int flags) { if (!nfs_server_capable(file_inode(file_out), NFS_CAP_COPY)) return -EOPNOTSUPP; @@ -140,6 +140,20 @@ static ssize_t nfs4_copy_file_range(struct file *file_in, loff_t pos_in, return nfs42_proc_copy(file_in, pos_in, file_out, pos_out, count); } +static ssize_t nfs4_copy_file_range(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + size_t count, unsigned int flags) +{ + ssize_t ret; + + ret = __nfs4_copy_file_range(file_in, pos_in, file_out, pos_out, count, + flags); + if (ret == -EOPNOTSUPP) + ret = generic_copy_file_range(file_in, pos_in, file_out, + pos_out, count, flags); + return ret; +} + static loff_t nfs4_file_llseek(struct file *filep, loff_t offset, int whence) { loff_t ret; diff --git a/fs/read_write.c b/fs/read_write.c index 676b02fae589..b63dcb4e4fe9 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1595,6 +1595,19 @@ ssize_t generic_copy_file_range(struct file *file_in, loff_t pos_in, } EXPORT_SYMBOL(generic_copy_file_range); +static ssize_t do_copy_file_range(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + size_t len, unsigned int flags) +{ + if (file_out->f_op->copy_file_range) + return file_out->f_op->copy_file_range(file_in, pos_in, + file_out, pos_out, + len, flags); + + return generic_copy_file_range(file_in, pos_in, file_out, pos_out, len, + flags); +} + /* * copy_file_range() differs from regular file read and write in that it * specifically allows return partial success. When it does so is up to @@ -1655,15 +1668,9 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, } } - if (file_out->f_op->copy_file_range) { - ret = file_out->f_op->copy_file_range(file_in, pos_in, file_out, - pos_out, len, flags); - if (ret != -EOPNOTSUPP) - goto done; - } - - ret = generic_copy_file_range(file_in, pos_in, file_out, pos_out, len, - flags); + ret = do_copy_file_range(file_in, pos_in, file_out, pos_out, len, + flags); + WARN_ON_ONCE(ret == -EOPNOTSUPP); done: if (ret > 0) { fsnotify_access(file_in); From patchwork Wed May 29 17:43:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10967401 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8BF62933 for ; Wed, 29 May 2019 17:43:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7DDDE288E5 for ; Wed, 29 May 2019 17:43:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7771C28A5E; Wed, 29 May 2019 17:43:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C382288E5 for ; Wed, 29 May 2019 17:43:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727089AbfE2Rni (ORCPT ); Wed, 29 May 2019 13:43:38 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:33888 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726205AbfE2Rng (ORCPT ); Wed, 29 May 2019 13:43:36 -0400 Received: by mail-wr1-f66.google.com with SMTP id f8so2421462wrt.1; Wed, 29 May 2019 10:43:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zD+G66icCrS83U+p0kj1jVa8Ed5aOLuiZE56AA1YrhI=; b=Z9LHyUj59Y12ZR+Ao4t5/5+xyqVIk8lVXWbZ4hILxnDlXw/qwRjvT0vpNwtyzms1T0 q+dIWdkAKD96I6hJiKbGULkPjl92hP4jGG4S5O4q+UlkLid/slyuTzXCB8NSV6WMipTt S5D5KcbnNdqxOiMi7FsZme7IewipQxtmpw6JPQIYWgVOUaAAceLpWZsBLDLkUMWIfCXm 7ae2W+DPyfUurY0ze8fEKjQUHDgPaHAOky0S2MEAsJjzWTsY+wr3Qf+jW6osRkijiYJh colYvqc+mkTOrZ5F6LrcHdmQ6TTNP0RBzXHLRUNSxgT7M333jr5DZlUL1Nzm6E4hrRW5 taYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zD+G66icCrS83U+p0kj1jVa8Ed5aOLuiZE56AA1YrhI=; b=Jdo8RDqvjjiEurWx2l7FoY/adcvLNNK6fS5fxJMmuAYPmCYyGCXGllYI04L4PZABST ym+C2/sfylxesF/mcDGOGbqRjpQaZwo6GXm7FcQshJpZgTqbhx5vLLT+9QDU8hng49DI tB1cp8SvGZiNakA0vppcy0cdrRC33fSj2BI4w1zgaY543NqtxAZ73ILif3hjnbT3DvEq GO7WjshUnvRIY7UhZt9hGP1ON9BOtP5NfqlpfvneOq1phW1+2N5knIRZtKu3fnn4yR1Z 2gPAker0AQUak7SJcXzr3okqHQgPujTOSkElOHtMvNNJau6WNFcwNKapUOonbhRM2Tf9 4THQ== X-Gm-Message-State: APjAAAVRva5d9T1VwkKcUy7AZ9foA5uLe2Aj011axTf1InUeZBFeCN/u 6+pFKsK0DZ5/2THJ895xs5w= X-Google-Smtp-Source: APXvYqxhYgcBdlCl44oCcOLk+zJm2JWkD4cbQhiZTLoRJrYTK4hwNO5GToNdbW2BBB87VD/hMMGxog== X-Received: by 2002:adf:e945:: with SMTP id m5mr9491208wrn.90.1559151814028; Wed, 29 May 2019 10:43:34 -0700 (PDT) Received: from localhost.localdomain ([5.102.238.208]) by smtp.gmail.com with ESMTPSA id k125sm31702wmb.34.2019.05.29.10.43.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 May 2019 10:43:33 -0700 (PDT) From: Amir Goldstein To: "Darrick J . Wong" Cc: Dave Chinner , Christoph Hellwig , linux-xfs@vger.kernel.org, Olga Kornievskaia , Luis Henriques , Al Viro , linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, ceph-devel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org Subject: [PATCH v3 03/13] vfs: introduce generic_file_rw_checks() Date: Wed, 29 May 2019 20:43:07 +0300 Message-Id: <20190529174318.22424-4-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190529174318.22424-1-amir73il@gmail.com> References: <20190529174318.22424-1-amir73il@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Factor out helper with some checks on in/out file that are common to clone_file_range and copy_file_range. Suggested-by: Darrick J. Wong Signed-off-by: Amir Goldstein Reviewed-by: Darrick J. Wong --- fs/read_write.c | 38 +++++++++++--------------------------- include/linux/fs.h | 1 + mm/filemap.c | 24 ++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 27 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index b63dcb4e4fe9..f1900bdb3127 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1617,17 +1617,18 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, size_t len, unsigned int flags) { - struct inode *inode_in = file_inode(file_in); - struct inode *inode_out = file_inode(file_out); ssize_t ret; if (flags != 0) return -EINVAL; - if (S_ISDIR(inode_in->i_mode) || S_ISDIR(inode_out->i_mode)) - return -EISDIR; - if (!S_ISREG(inode_in->i_mode) || !S_ISREG(inode_out->i_mode)) - return -EINVAL; + /* this could be relaxed once a method supports cross-fs copies */ + if (file_inode(file_in)->i_sb != file_inode(file_out)->i_sb) + return -EXDEV; + + ret = generic_file_rw_checks(file_in, file_out); + if (unlikely(ret)) + return ret; ret = rw_verify_area(READ, file_in, &pos_in, len); if (unlikely(ret)) @@ -1637,15 +1638,6 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, if (unlikely(ret)) return ret; - if (!(file_in->f_mode & FMODE_READ) || - !(file_out->f_mode & FMODE_WRITE) || - (file_out->f_flags & O_APPEND)) - return -EBADF; - - /* this could be relaxed once a method supports cross-fs copies */ - if (inode_in->i_sb != inode_out->i_sb) - return -EXDEV; - if (len == 0) return 0; @@ -2013,29 +2005,21 @@ loff_t do_clone_file_range(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, loff_t len, unsigned int remap_flags) { - struct inode *inode_in = file_inode(file_in); - struct inode *inode_out = file_inode(file_out); loff_t ret; WARN_ON_ONCE(remap_flags & REMAP_FILE_DEDUP); - if (S_ISDIR(inode_in->i_mode) || S_ISDIR(inode_out->i_mode)) - return -EISDIR; - if (!S_ISREG(inode_in->i_mode) || !S_ISREG(inode_out->i_mode)) - return -EINVAL; - /* * FICLONE/FICLONERANGE ioctls enforce that src and dest files are on * the same mount. Practically, they only need to be on the same file * system. */ - if (inode_in->i_sb != inode_out->i_sb) + if (file_inode(file_in)->i_sb != file_inode(file_out)->i_sb) return -EXDEV; - if (!(file_in->f_mode & FMODE_READ) || - !(file_out->f_mode & FMODE_WRITE) || - (file_out->f_flags & O_APPEND)) - return -EBADF; + ret = generic_file_rw_checks(file_in, file_out); + if (ret < 0) + return ret; if (!file_in->f_op->remap_file_range) return -EOPNOTSUPP; diff --git a/include/linux/fs.h b/include/linux/fs.h index ea17858310ff..89b9b73eb581 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3049,6 +3049,7 @@ extern ssize_t generic_write_checks(struct kiocb *, struct iov_iter *); extern int generic_remap_checks(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, loff_t *count, unsigned int remap_flags); +extern int generic_file_rw_checks(struct file *file_in, struct file *file_out); extern ssize_t generic_file_read_iter(struct kiocb *, struct iov_iter *); extern ssize_t __generic_file_write_iter(struct kiocb *, struct iov_iter *); extern ssize_t generic_file_write_iter(struct kiocb *, struct iov_iter *); diff --git a/mm/filemap.c b/mm/filemap.c index df2006ba0cfa..a38619a4a6af 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3041,6 +3041,30 @@ int generic_remap_checks(struct file *file_in, loff_t pos_in, return 0; } + +/* + * Performs common checks before doing a file copy/clone + * from @file_in to @file_out. + */ +int generic_file_rw_checks(struct file *file_in, struct file *file_out) +{ + struct inode *inode_in = file_inode(file_in); + struct inode *inode_out = file_inode(file_out); + + /* Don't copy dirs, pipes, sockets... */ + if (S_ISDIR(inode_in->i_mode) || S_ISDIR(inode_out->i_mode)) + return -EISDIR; + if (!S_ISREG(inode_in->i_mode) || !S_ISREG(inode_out->i_mode)) + return -EINVAL; + + if (!(file_in->f_mode & FMODE_READ) || + !(file_out->f_mode & FMODE_WRITE) || + (file_out->f_flags & O_APPEND)) + return -EBADF; + + return 0; +} + int pagecache_write_begin(struct file *file, struct address_space *mapping, loff_t pos, unsigned len, unsigned flags, struct page **pagep, void **fsdata) From patchwork Wed May 29 17:43:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10967495 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8E84318A6 for ; Wed, 29 May 2019 17:44:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8050A28A52 for ; Wed, 29 May 2019 17:44:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 737E528A62; Wed, 29 May 2019 17:44:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C7C828A52 for ; Wed, 29 May 2019 17:44:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727341AbfE2Rno (ORCPT ); Wed, 29 May 2019 13:43:44 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:53583 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727195AbfE2Rnn (ORCPT ); Wed, 29 May 2019 13:43:43 -0400 Received: by mail-wm1-f67.google.com with SMTP id d17so2249047wmb.3; Wed, 29 May 2019 10:43:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=NeKDiq+5p2NPB+OcuE01UzrlB5njM3yLN2qd6AodpeU=; b=QN4dIaN9QMaFtoyG1MUp3LUKUh3ugT/NLU0caZNTFXyG+VEwCFfSZ7mD8R4ExD6UXl gOYwKkKWru9NBTMqz2dLCYd6divEv4VxRn9L/xfgmYsnWPWYanKR+5T9cqVr77JQ3DVA UCbWv1SoobyBKVlV1UospEjByMAApeveSG6P9pQcvZogWrw1GCLzEYMjEp9ICab6sVwe MleSETzpiVcMoSl5TEaM8Zm1KYTpW4jXrNVb/TouiRehBOhM0cwE4OyzbFIGSVb7DVr6 kFpAfSEkd0ruju3U1cz31YBgfo9fjbsnDy9f+1MmnvzAotmiLbvk8C9MTyzaf3aMauOn ciRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=NeKDiq+5p2NPB+OcuE01UzrlB5njM3yLN2qd6AodpeU=; b=jPUXmQHgtbS4Rq/9GGDNd8yiKDBwCN5vGFMt1tlBDJNOn7PboKaXLl0fqXdFrFCIZO AJHPUVY3N2pY1c0KisD7xylSogObIcX9MZBU481GDB7hNf85YlvGfdD46kQ2eFjb7gro S5UMnbDiLptyg3TU1xGL3kWXER4/UE1uDrCEwskMStmrTHk7QFKCHE6Jy07/6gLacr2f W2TGPCcU74KGHRfrF0P9NgPtbwMgtgYUtOPvoDF4KpYZIdM48IzFWnvyqfR8tjJsmHfW +aE0O46pyvcO97XKAEQiQJ3ViR0LRFSIbrZw2nkf+R68dDqiRpSIh5ygwPXG/LBpwJh/ oPsA== X-Gm-Message-State: APjAAAWIPEMpvO/3y09BEpMSQTnO5xrXlnDGAh1/qMD84Duh0toc4dXR adtmM9BKCcQ5xspwqv1Xdq0= X-Google-Smtp-Source: APXvYqz6bZyxgncHyHvCPAhLhQv5wGfs/oioqGtZDHF7raSCBLoHpEbnJUrWfw3hcdK4BYBLS9qb7w== X-Received: by 2002:a05:600c:23cf:: with SMTP id p15mr7996691wmb.31.1559151815769; Wed, 29 May 2019 10:43:35 -0700 (PDT) Received: from localhost.localdomain ([5.102.238.208]) by smtp.gmail.com with ESMTPSA id k125sm31702wmb.34.2019.05.29.10.43.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 May 2019 10:43:35 -0700 (PDT) From: Amir Goldstein To: "Darrick J . Wong" Cc: Dave Chinner , Christoph Hellwig , linux-xfs@vger.kernel.org, Olga Kornievskaia , Luis Henriques , Al Viro , linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, ceph-devel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org Subject: [PATCH v3 04/13] vfs: remove redundant checks from generic_remap_checks() Date: Wed, 29 May 2019 20:43:08 +0300 Message-Id: <20190529174318.22424-5-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190529174318.22424-1-amir73il@gmail.com> References: <20190529174318.22424-1-amir73il@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The access limit checks on input file range in generic_remap_checks() are redundant because the input file size is guaranteied to be within limits and pos+len are already checked to be within input file size. Beyond the fact that the check cannot fail, if it would have failed, it could return -EFBIG for input file range error. There is no precedent for that. -EFBIG is returned in syscalls that would change file length. With that call removed, we can fold generic_access_check_limits() into generic_write_check_limits(). Signed-off-by: Amir Goldstein Reviewed-by: Darrick J. Wong --- mm/filemap.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index a38619a4a6af..44361928bbb0 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2895,24 +2895,11 @@ EXPORT_SYMBOL(read_cache_page_gfp); * LFS limits. If pos is under the limit it becomes a short access. If it * exceeds the limit we return -EFBIG. */ -static int generic_access_check_limits(struct file *file, loff_t pos, - loff_t *count) -{ - struct inode *inode = file->f_mapping->host; - loff_t max_size = inode->i_sb->s_maxbytes; - - if (!(file->f_flags & O_LARGEFILE)) - max_size = MAX_NON_LFS; - - if (unlikely(pos >= max_size)) - return -EFBIG; - *count = min(*count, max_size - pos); - return 0; -} - static int generic_write_check_limits(struct file *file, loff_t pos, loff_t *count) { + struct inode *inode = file->f_mapping->host; + loff_t max_size = inode->i_sb->s_maxbytes; loff_t limit = rlimit(RLIMIT_FSIZE); if (limit != RLIM_INFINITY) { @@ -2923,7 +2910,15 @@ static int generic_write_check_limits(struct file *file, loff_t pos, *count = min(*count, limit - pos); } - return generic_access_check_limits(file, pos, count); + if (!(file->f_flags & O_LARGEFILE)) + max_size = MAX_NON_LFS; + + if (unlikely(pos >= max_size)) + return -EFBIG; + + *count = min(*count, max_size - pos); + + return 0; } /* @@ -2963,7 +2958,7 @@ EXPORT_SYMBOL(generic_write_checks); /* * Performs necessary checks before doing a clone. * - * Can adjust amount of bytes to clone. + * Can adjust amount of bytes to clone via @req_count argument. * Returns appropriate error code that caller should return or * zero in case the clone should be allowed. */ @@ -3001,10 +2996,6 @@ int generic_remap_checks(struct file *file_in, loff_t pos_in, return -EINVAL; count = min(count, size_in - (uint64_t)pos_in); - ret = generic_access_check_limits(file_in, pos_in, &count); - if (ret) - return ret; - ret = generic_write_check_limits(file_out, pos_out, &count); if (ret) return ret; From patchwork Wed May 29 17:43:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10967515 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E4F6918A6 for ; Wed, 29 May 2019 17:44:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D8B1628A5B for ; Wed, 29 May 2019 17:44:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D67E228A62; Wed, 29 May 2019 17:44:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7470F28922 for ; Wed, 29 May 2019 17:44:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727219AbfE2Rnm (ORCPT ); Wed, 29 May 2019 13:43:42 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:52228 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727096AbfE2Rnk (ORCPT ); Wed, 29 May 2019 13:43:40 -0400 Received: by mail-wm1-f67.google.com with SMTP id y3so2250518wmm.2; Wed, 29 May 2019 10:43:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2/CP2IvvJS5kHF334Ic9jdZBlmRYc6Ue8s+vgRNa/1Q=; b=upnAf8myIrx2pKteVhF2+kpe+Nin2P5mBATst2HHhtqTY7ITAXJxECpcP1rsy1A1qb 4yHOqCcseIcjx00JRyTDaCJrR7tOa22IqD6U1us6DA5jRAfL6cpAFVwFMZA9WGLoJb9M +31KnfTQQZJ18UBBXuhMt3DRWUyfmsUx1m0ps05SPcUvrQqtMmMiv4CcGj4Cn+6U3IOR hOaDgCK9d4KUIBq6jrb35lwb1aZYr8T2+HN1xyvTkD1aAo5onz/HGLDUp9l8ytbcXzr0 ubdvUyAtvEJs0Ky/vhGXKnYfok5g/mHlZfxX/nYLpQTyZfmvSXXW8vubw5XzO4+itBmu IwGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=2/CP2IvvJS5kHF334Ic9jdZBlmRYc6Ue8s+vgRNa/1Q=; b=KnIM3QRLBIFWbH2bHpXnJi+B9nK3n/p76H3RgQoQ51tFFsOyCO6WFODllls9gVqKGf xTLr3Q/mFj8Ugk8MF47H9XZEhjv0RDxTrvt7UlIMZzKaBnVLKBYElDjpaP8NGQoVO0/z RVgy7DqGdnG396ihqKnDZtBU8pFYIcz7YtJKuWWjeKBXgMIz1g6IqLJsrjNYPLDF9Myx gYmO4rrFC2um6hbbJO97vNV5oXx3tpUpmhT+xK1kLobJGoH8axAW2umMVxH3KqRy27bO LGa3paxhN/gYB5TvtvknWuyVZzaFxIGIM9FHS23RLiDo3VBGMqiSz8SKM9xpMBLhOsSw N/qg== X-Gm-Message-State: APjAAAUNrBJeQ9SH/01ptoPQzbluW7MoRbORtD8kwB5PkR/CD7XS2qnh Eex8ArTxa+Xpvl3HEYVi3dRrCcurRU0= X-Google-Smtp-Source: APXvYqyeRXP+ushjMp0sko4DG5SCcZdemIdjPmQZqrRvr76nJTW+ebE4dTcExW9j+EVS8IBrj5eQJw== X-Received: by 2002:a1c:eb0c:: with SMTP id j12mr7503521wmh.55.1559151817888; Wed, 29 May 2019 10:43:37 -0700 (PDT) Received: from localhost.localdomain ([5.102.238.208]) by smtp.gmail.com with ESMTPSA id k125sm31702wmb.34.2019.05.29.10.43.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 May 2019 10:43:37 -0700 (PDT) From: Amir Goldstein To: "Darrick J . Wong" Cc: Dave Chinner , Christoph Hellwig , linux-xfs@vger.kernel.org, Olga Kornievskaia , Luis Henriques , Al Viro , linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, ceph-devel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, Dave Chinner Subject: [PATCH v3 05/13] vfs: add missing checks to copy_file_range Date: Wed, 29 May 2019 20:43:09 +0300 Message-Id: <20190529174318.22424-6-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190529174318.22424-1-amir73il@gmail.com> References: <20190529174318.22424-1-amir73il@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Like the clone and dedupe interfaces we've recently fixed, the copy_file_range() implementation is missing basic sanity, limits and boundary condition tests on the parameters that are passed to it from userspace. Create a new "generic_copy_file_checks()" function modelled on the generic_remap_checks() function to provide this missing functionality. [Amir] Shorten copy length instead of checking pos_in limits because input file size already abides by the limits. Signed-off-by: Dave Chinner Signed-off-by: Amir Goldstein Reviewed-by: Darrick J. Wong --- fs/read_write.c | 3 ++- include/linux/fs.h | 3 +++ mm/filemap.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/fs/read_write.c b/fs/read_write.c index f1900bdb3127..b0fb1176b628 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1626,7 +1626,8 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, if (file_inode(file_in)->i_sb != file_inode(file_out)->i_sb) return -EXDEV; - ret = generic_file_rw_checks(file_in, file_out); + ret = generic_copy_file_checks(file_in, pos_in, file_out, pos_out, &len, + flags); if (unlikely(ret)) return ret; diff --git a/include/linux/fs.h b/include/linux/fs.h index 89b9b73eb581..e4d382c4342a 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3050,6 +3050,9 @@ extern int generic_remap_checks(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, loff_t *count, unsigned int remap_flags); extern int generic_file_rw_checks(struct file *file_in, struct file *file_out); +extern int generic_copy_file_checks(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + size_t *count, unsigned int flags); extern ssize_t generic_file_read_iter(struct kiocb *, struct iov_iter *); extern ssize_t __generic_file_write_iter(struct kiocb *, struct iov_iter *); extern ssize_t generic_file_write_iter(struct kiocb *, struct iov_iter *); diff --git a/mm/filemap.c b/mm/filemap.c index 44361928bbb0..aac71aef4c61 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3056,6 +3056,59 @@ int generic_file_rw_checks(struct file *file_in, struct file *file_out) return 0; } +/* + * Performs necessary checks before doing a file copy + * + * Can adjust amount of bytes to copy via @req_count argument. + * Returns appropriate error code that caller should return or + * zero in case the copy should be allowed. + */ +int generic_copy_file_checks(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + size_t *req_count, unsigned int flags) +{ + struct inode *inode_in = file_inode(file_in); + struct inode *inode_out = file_inode(file_out); + uint64_t count = *req_count; + loff_t size_in; + int ret; + + ret = generic_file_rw_checks(file_in, file_out); + if (ret) + return ret; + + /* Don't touch certain kinds of inodes */ + if (IS_IMMUTABLE(inode_out)) + return -EPERM; + + if (IS_SWAPFILE(inode_in) || IS_SWAPFILE(inode_out)) + return -ETXTBSY; + + /* Ensure offsets don't wrap. */ + if (pos_in + count < pos_in || pos_out + count < pos_out) + return -EOVERFLOW; + + /* Shorten the copy to EOF */ + size_in = i_size_read(inode_in); + if (pos_in >= size_in) + count = 0; + else + count = min(count, size_in - (uint64_t)pos_in); + + ret = generic_write_check_limits(file_out, pos_out, &count); + if (ret) + return ret; + + /* Don't allow overlapped copying within the same file. */ + if (inode_in == inode_out && + pos_out + count > pos_in && + pos_out < pos_in + count) + return -EINVAL; + + *req_count = count; + return 0; +} + int pagecache_write_begin(struct file *file, struct address_space *mapping, loff_t pos, unsigned len, unsigned flags, struct page **pagep, void **fsdata) From patchwork Wed May 29 17:43:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10967503 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 889B1933 for ; Wed, 29 May 2019 17:44:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7CEDD28A5E for ; Wed, 29 May 2019 17:44:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 712A028A5F; Wed, 29 May 2019 17:44:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DFFE2856E for ; Wed, 29 May 2019 17:44:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727312AbfE2Rnm (ORCPT ); Wed, 29 May 2019 13:43:42 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:35474 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726205AbfE2Rnl (ORCPT ); Wed, 29 May 2019 13:43:41 -0400 Received: by mail-wm1-f67.google.com with SMTP id w9so2181935wmi.0; Wed, 29 May 2019 10:43:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=scXNy7Kv0jk0u1cUOdecKgwqwG5sRFulap1lrncxuHo=; b=s+jtsDe6rXzCxWe4+vL2LKW99Wa6fSQ5fJFeqRL0+ypE7CjnvYTV/ENnJOM8O84F8G eyfHIA3Gs9BWZnUk8XBCWOztvFKUdmdjhcw1s3ScNe91pfBhIJsOS1aQlOESy/Pwt5OF EVjvnDjIC28XzmPo+yat+GOs+8DNr7Z14d8QMSGG4b2EhvxSbmF3nxvhufcpUGKZNQI6 z9S9gjH40vjNjVDZKU9XHMl5v0gwr1KE//A9kfqIVjMFaDS5VwLVM0fodQ5ww5jy/pYR W7vJqwP7TbUuchqruP6RapRhdhiAnIR+37GizTbBrR/0gripwtGAuk6jFyKc/qnfAY6k poiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=scXNy7Kv0jk0u1cUOdecKgwqwG5sRFulap1lrncxuHo=; b=krXca3yrL5g1NkBNso3nsqrQzGSv+GqYEf6t4w3hh2XQPRq+BhfGsRJf25O6BWgww3 w0LFC8q1J3DTefPeOuwxX616tNNcu6MAS3y7EemVFYQKn449HpbqavVXkY3+8bIhpOSG /Y4FplDT7vPUFmkjubMxTc3rwe05RcM0H1tMYG2KQc686yaea54jpH0/9epiAYV4KaV5 jvD1tAtWIM05GuZ8sNwUfKcqn28Y3iSt0jz1eH+h5qBtwfB6qBqxgxg09C72DMvBh0QK Z0lhoorjlX1JqrE+AW3XNwu/nDhueWE+Lk5pg0SflntvMXEp81Ru/JEQdzk2XZrzshNh 0UwQ== X-Gm-Message-State: APjAAAVO0K/Q8t0q/5RGMPmlJxy2E5qbk1RAHpP8wwLevTWhVsRLHj/l ABoF6Yl/3YNy8WM5ICQEW1Y= X-Google-Smtp-Source: APXvYqxhAE3qGe17aHRIuRoz8i3iWKXSr8e07GEpkjAf4PZNHDYajF6mhq35eVbjNKcCGa5E96iAoQ== X-Received: by 2002:a1c:9904:: with SMTP id b4mr7585111wme.1.1559151819895; Wed, 29 May 2019 10:43:39 -0700 (PDT) Received: from localhost.localdomain ([5.102.238.208]) by smtp.gmail.com with ESMTPSA id k125sm31702wmb.34.2019.05.29.10.43.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 May 2019 10:43:39 -0700 (PDT) From: Amir Goldstein To: "Darrick J . Wong" Cc: Dave Chinner , Christoph Hellwig , linux-xfs@vger.kernel.org, Olga Kornievskaia , Luis Henriques , Al Viro , linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, ceph-devel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org Subject: [PATCH v3 06/13] vfs: introduce file_modified() helper Date: Wed, 29 May 2019 20:43:10 +0300 Message-Id: <20190529174318.22424-7-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190529174318.22424-1-amir73il@gmail.com> References: <20190529174318.22424-1-amir73il@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The combination of file_remove_privs() and file_update_mtime() is quite common in filesystem ->write_iter() methods. Modelled after the helper file_accessed(), introduce file_modified() and use it from generic_remap_file_range_prep(). Note that the order of calling file_remove_privs() before file_update_mtime() in the helper was matched to the more common order by filesystems and not the current order in generic_remap_file_range_prep(). Signed-off-by: Amir Goldstein --- fs/inode.c | 20 ++++++++++++++++++++ fs/read_write.c | 21 +++------------------ include/linux/fs.h | 2 ++ 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index df6542ec3b88..2885f2f2c7a5 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -1899,6 +1899,26 @@ int file_update_time(struct file *file) } EXPORT_SYMBOL(file_update_time); +/* Caller must hold the file's inode lock */ +int file_modified(struct file *file) +{ + int err; + + /* + * Clear the security bits if the process is not being run by root. + * This keeps people from modifying setuid and setgid binaries. + */ + err = file_remove_privs(file); + if (err) + return err; + + if (likely(file->f_mode & FMODE_NOCMTIME)) + return 0; + + return file_update_time(file); +} +EXPORT_SYMBOL(file_modified); + int inode_needs_sync(struct inode *inode) { if (IS_SYNC(inode)) diff --git a/fs/read_write.c b/fs/read_write.c index b0fb1176b628..cec7e7b1f693 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1980,25 +1980,10 @@ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, return ret; /* If can't alter the file contents, we're done. */ - if (!(remap_flags & REMAP_FILE_DEDUP)) { - /* Update the timestamps, since we can alter file contents. */ - if (!(file_out->f_mode & FMODE_NOCMTIME)) { - ret = file_update_time(file_out); - if (ret) - return ret; - } + if (!(remap_flags & REMAP_FILE_DEDUP)) + ret = file_modified(file_out); - /* - * Clear the security bits if the process is not being run by - * root. This keeps people from modifying setuid and setgid - * binaries. - */ - ret = file_remove_privs(file_out); - if (ret) - return ret; - } - - return 0; + return ret; } EXPORT_SYMBOL(generic_remap_file_range_prep); diff --git a/include/linux/fs.h b/include/linux/fs.h index e4d382c4342a..79ffa2958bd8 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2177,6 +2177,8 @@ static inline void file_accessed(struct file *file) touch_atime(&file->f_path); } +extern int file_modified(struct file *file); + int sync_inode(struct inode *inode, struct writeback_control *wbc); int sync_inode_metadata(struct inode *inode, int wait); From patchwork Wed May 29 17:43:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10967501 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D623176 for ; Wed, 29 May 2019 17:44:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB0DD2856E for ; Wed, 29 May 2019 17:44:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C8DE628A48; Wed, 29 May 2019 17:44:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8288D2856E for ; Wed, 29 May 2019 17:44:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726205AbfE2Rnn (ORCPT ); Wed, 29 May 2019 13:43:43 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:53585 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727233AbfE2Rnn (ORCPT ); Wed, 29 May 2019 13:43:43 -0400 Received: by mail-wm1-f68.google.com with SMTP id d17so2249085wmb.3; Wed, 29 May 2019 10:43:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mWDe89ODCpcP6HYYy/yqf+cljHqldogh+/AgsrEHfwE=; b=cD+1CJrnj5cSe1wCIpAFwua2MN1kN1xNg3hIT6ATRPZEleePpBS6eGUWulB1qlMP1/ Ddr+gyrC56II0jJ0mgCgLIHbYpIvw9Uaoe35riq+AN93RuLHGQu72fjZVk3oqne9Wl+a sFfqjNZWNIrSKacCT5jz5DzGMxohKbXopTtjeRxkeMfIWjQJexxCmL17wfht1kbQ0/kE u1NOszql8jNhqMOcQO8sYBy9Q68Pnu+PhxaKS7z/iWim9WlT01meShp9XkP3LSxieuyg pHfItlQiK/im4jO8Ue5CcjCo4tKicYkzQVAcyZ97HWBzBCNCpfC50cefJIS6Q8wCnxh8 9bOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mWDe89ODCpcP6HYYy/yqf+cljHqldogh+/AgsrEHfwE=; b=aFtoHqoN44phN5OJUAEr2WAo7OkNAP780VnpnjkvMHeYFjTTb+cTVbTuN+P1JL7jKh ADPl5+01G+LAFREY6BCx5to2IX4shbif/lVhD4LErFp09acqMEzndnK+7lOCNTcI/MHc /12TEdkMXmCEgsxrezvy82Csqv7NrVwNL4s8qagbuxjwOSv/30C29S7mh6YaXyc7o3l7 9lPV04LbECoP3neMVcrE80H++955zwVsGri57Rgi8NAg8iyhA32fY6JgAZRKMxPPtl5Z j392EDX4j4jxu4RWQPde1oL/VpKaW8cb35kpEZz7YJWT1Jr1dagrbWep99Rr43dkQDK4 feGQ== X-Gm-Message-State: APjAAAVtaPJkmcaQSEeerfPgN3eKU6EbN8T1pTBWZ7uJQro55q01FjLZ wX23RNxRfkwr0wOkxoDWKC0= X-Google-Smtp-Source: APXvYqwIlp98ADVdrSYvWbdeg9HNHHdS9VwKtmNUodON5E/WEaVY9+Ztcp9OWHWCflaplsQIscHC1A== X-Received: by 2002:a1c:cb49:: with SMTP id b70mr8135774wmg.80.1559151821622; Wed, 29 May 2019 10:43:41 -0700 (PDT) Received: from localhost.localdomain ([5.102.238.208]) by smtp.gmail.com with ESMTPSA id k125sm31702wmb.34.2019.05.29.10.43.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 May 2019 10:43:41 -0700 (PDT) From: Amir Goldstein To: "Darrick J . Wong" Cc: Dave Chinner , Christoph Hellwig , linux-xfs@vger.kernel.org, Olga Kornievskaia , Luis Henriques , Al Viro , linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, ceph-devel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org Subject: [PATCH v3 07/13] xfs: use file_modified() helper Date: Wed, 29 May 2019 20:43:11 +0300 Message-Id: <20190529174318.22424-8-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190529174318.22424-1-amir73il@gmail.com> References: <20190529174318.22424-1-amir73il@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Note that by using the helper, the order of calling file_remove_privs() after file_update_mtime() in xfs_file_aio_write_checks() has changed. Signed-off-by: Amir Goldstein Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_file.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 76748255f843..916a35cae5e9 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -367,20 +367,7 @@ xfs_file_aio_write_checks( * lock above. Eventually we should look into a way to avoid * the pointless lock roundtrip. */ - if (likely(!(file->f_mode & FMODE_NOCMTIME))) { - error = file_update_time(file); - if (error) - return error; - } - - /* - * If we're writing the file then make sure to clear the setuid and - * setgid bits if the process is not being run by root. This keeps - * people from modifying setuid and setgid binaries. - */ - if (!IS_NOSEC(inode)) - return file_remove_privs(file); - return 0; + return file_modified(file); } static int From patchwork Wed May 29 17:43:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10967427 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9C6CC933 for ; Wed, 29 May 2019 17:43:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8FD142000A for ; Wed, 29 May 2019 17:43:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8D4B928A6B; Wed, 29 May 2019 17:43:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4449120CCF for ; Wed, 29 May 2019 17:43:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727381AbfE2Rnp (ORCPT ); Wed, 29 May 2019 13:43:45 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:50753 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727345AbfE2Rnp (ORCPT ); Wed, 29 May 2019 13:43:45 -0400 Received: by mail-wm1-f67.google.com with SMTP id f204so2264471wme.0; Wed, 29 May 2019 10:43:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yYTFJKL40LM++VpLTZTzwXvwxxD1UrCsqPZT6tG+/XE=; b=cSqvCgWy1YUQe0dHZNRcbGIm/QEpVxUs6IT3YXaSyTh4x9WjSNR5boI0WRhPgPAwTC YiOR+sZiQ2g335Wkr7SvCOrlFeo8ICtA+/A4NNSnHdOKdDSWWnXG8PDIkjWDzo450BPH iEcy/YGbb+k+IYl//FLQyIIaCWywEu9FP5bLBCJpDzO704xeoNqoCwoLqoNWeelRTvMx aTlXk/0tm4w7OrQ6tcZpAMrsdO/ONgCDJCNZQWiR5retFl7gsuPPehmDMoOE8i9Zrgzo aP+pBNX7yLNjvozjcUMh3FQX+L0lNchxh8e3MP9zvR6pSYznLHLW6k/NYIqE3gNMgS/B 5bcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=yYTFJKL40LM++VpLTZTzwXvwxxD1UrCsqPZT6tG+/XE=; b=krNgBSOQcjUiqjrVtHXNlvYluzCxCYSaxmalJHYugjo4lQKbRbt4SF75NI9E7hXJSr WA4rxP/7FnEPNjlwI1hPgXJC5jQCQ4/ywIjxXWV2mQ4GuRUK241eJ3usOL2vFJcYcByy 9uTwU2Xi8SjoJFqgtNG38MQLsw/Za5DGSRQEB+IYToul3vyIfSKjQQ7zZyRh5BfGRFYj 3Cg928n+pINQtLeJUHmnUUlZevZJ1Q/57rOWEWNuB2SVcofEQ75sywioYINgiwLaT8Un 6JZ2lysN+GHU3jjoShZU73CBKwgkdSU5pb/Gar+Vh9/4Bi6cXKl7aIe0PN+tF3I9fH/u dywQ== X-Gm-Message-State: APjAAAU7JJpdz3MdGX3JdYKKvWwCWT/OAyL2TOyS7uuJnUbHh0E3TTEl 57OMurvcgWLNf9jBFuE0vXM= X-Google-Smtp-Source: APXvYqwquQoM7yAP2+/AyNykqKSjW4fG5r+voHHnsO1jrH6Riwda2nc9fTFThBKC6BcsinK57kEFVg== X-Received: by 2002:a1c:f60d:: with SMTP id w13mr7438206wmc.40.1559151823589; Wed, 29 May 2019 10:43:43 -0700 (PDT) Received: from localhost.localdomain ([5.102.238.208]) by smtp.gmail.com with ESMTPSA id k125sm31702wmb.34.2019.05.29.10.43.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 May 2019 10:43:42 -0700 (PDT) From: Amir Goldstein To: "Darrick J . Wong" Cc: Dave Chinner , Christoph Hellwig , linux-xfs@vger.kernel.org, Olga Kornievskaia , Luis Henriques , Al Viro , linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, ceph-devel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org Subject: [PATCH v3 08/13] vfs: copy_file_range needs to strip setuid bits and update timestamps Date: Wed, 29 May 2019 20:43:12 +0300 Message-Id: <20190529174318.22424-9-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190529174318.22424-1-amir73il@gmail.com> References: <20190529174318.22424-1-amir73il@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Because generic_copy_file_range doesn't hold the destination inode lock throughout the copy, strip setuid bits before and after copy. The destination inode mtime is updated before and after the copy and the source inode atime is updated after the copy, similar to generic_file_read_iter(). Signed-off-by: Amir Goldstein Reviewed-by: Darrick J. Wong --- fs/read_write.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index cec7e7b1f693..706ea5f276a7 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1590,8 +1590,27 @@ ssize_t generic_copy_file_range(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, size_t len, unsigned int flags) { - return do_splice_direct(file_in, &pos_in, file_out, &pos_out, - len > MAX_RW_COUNT ? MAX_RW_COUNT : len, 0); + struct inode *inode_out = file_inode(file_out); + int ret, err; + + /* Should inode_out lock be held throughout the copy operation? */ + inode_lock(inode_out); + err = file_modified(file_out); + inode_unlock(inode_out); + if (err) + return err; + + ret = do_splice_direct(file_in, &pos_in, file_out, &pos_out, + len > MAX_RW_COUNT ? MAX_RW_COUNT : len, 0); + + file_accessed(file_in); + + /* To be on the safe side, remove privs also after copy */ + inode_lock(inode_out); + err = file_modified(file_out); + inode_unlock(inode_out); + + return err ?: ret; } EXPORT_SYMBOL(generic_copy_file_range); From patchwork Wed May 29 17:43:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10967491 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9C492933 for ; Wed, 29 May 2019 17:44:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E42E2000A for ; Wed, 29 May 2019 17:44:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E63F28A52; Wed, 29 May 2019 17:44:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2BD3020CCF for ; Wed, 29 May 2019 17:44:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727404AbfE2Rnt (ORCPT ); Wed, 29 May 2019 13:43:49 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:36412 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727400AbfE2Rns (ORCPT ); Wed, 29 May 2019 13:43:48 -0400 Received: by mail-wm1-f67.google.com with SMTP id v22so2188603wml.1; Wed, 29 May 2019 10:43:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rlDX58TIMkSnxlZYvBJZ2TZQKYpka5ehiNgustkWnZY=; b=PebP4+cLhsmj4O+1azOWcIfAVONfFzTh1sA9YSTYEBAqybToCfE37RpBbr7J9ptozi RmOGNtC0UuYTmEP3nYBBuEw10G2PIKqbSZRnlYGH3pdBC1WbUqM9effRhKKC7ZCZWxR+ mn9v/TgTQtecIOFKq2sRrcpKuoU5myZ0nXvAQ1jyxpkh+PMs5uvaMTLWgp8sAUHUAo3G l/vLcINnzwiZcdCt1d9y2Ylo03GCaKy0nFJ8d/moT6PxaRTh/ZNXEd6+9NQhxWgzPVTo Cn34hQiE6iWkVGyGyscRfsy7yvxqigDx8JMxip1JXYtHhjMx6rgv0h5iDL+sgsCUQpgy JeHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=rlDX58TIMkSnxlZYvBJZ2TZQKYpka5ehiNgustkWnZY=; b=BZ4v7xrF/WV99P6LtNx/1Lu6DZfHxxREy8hQu+LmP8Avp/QF9iVSjtFeMJZ6qiXrtt EdaMeKEtFyIw+SOFDwFQnyyQe8Yv6LEjNH2ZVubwCK7WNJUM6ITxv20E8p8JzqFHhCuR uY+zddWK0UJ0Hh6bJ2Irqd0MGozS14VKG/3t5AIJa35/v3SMiY+1fY8X2qvD7Frtf1ob DsA9DHdcz2+IOdj8HXIoJsesNftf9rooG1pu7c7t7XLak+U322yzBL5AZnzEqMTYETTu mdUgyi2oIIuSoZJwuSR1omoTol9wXEjxapSh9KG7c/Z5IIH+5by+EPjmjtvmssff/T+T VlqA== X-Gm-Message-State: APjAAAWcNWRrsCp/VUj4Zh8Oc418dIpRv2PqttcRuNSlWa5FBWtHChYt /ZQC1MxAu3YuDflZ91N8vjzgoFIaP5g= X-Google-Smtp-Source: APXvYqyZnP/ym9Cj9u95IdXYn2JeWpOXl96aMvy78ul3u/IC+OGJ1gY7fQFBpkU10Ayxtspk+rk0RA== X-Received: by 2002:a1c:eb0c:: with SMTP id j12mr7503798wmh.55.1559151825614; Wed, 29 May 2019 10:43:45 -0700 (PDT) Received: from localhost.localdomain ([5.102.238.208]) by smtp.gmail.com with ESMTPSA id k125sm31702wmb.34.2019.05.29.10.43.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 May 2019 10:43:45 -0700 (PDT) From: Amir Goldstein To: "Darrick J . Wong" Cc: Dave Chinner , Christoph Hellwig , linux-xfs@vger.kernel.org, Olga Kornievskaia , Luis Henriques , Al Viro , linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, ceph-devel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org Subject: [PATCH v3 09/13] ceph: copy_file_range needs to strip setuid bits and update timestamps Date: Wed, 29 May 2019 20:43:13 +0300 Message-Id: <20190529174318.22424-10-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190529174318.22424-1-amir73il@gmail.com> References: <20190529174318.22424-1-amir73il@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Because ceph doesn't hold destination inode lock throughout the copy, strip setuid bits before and after copy. The destination inode mtime is updated before and after the copy and the source inode atime is updated after the copy, similar to the filesystem ->read_iter() implementation. Signed-off-by: Amir Goldstein --- fs/ceph/file.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/fs/ceph/file.c b/fs/ceph/file.c index e87f7b2023af..8a70708e1aca 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -1947,6 +1947,15 @@ static ssize_t __ceph_copy_file_range(struct file *src_file, loff_t src_off, goto out; } + /* Should dst_inode lock be held throughout the copy operation? */ + inode_lock(dst_inode); + ret = file_modified(dst_file); + inode_unlock(dst_inode); + if (ret < 0) { + dout("failed to modify dst file before copy (%zd)\n", ret); + goto out; + } + /* * We need FILE_WR caps for dst_ci and FILE_RD for src_ci as other * clients may have dirty data in their caches. And OSDs know nothing @@ -2097,6 +2106,14 @@ static ssize_t __ceph_copy_file_range(struct file *src_file, loff_t src_off, out: ceph_free_cap_flush(prealloc_cf); + file_accessed(src_file); + /* To be on the safe side, remove privs also after copy */ + inode_lock(dst_inode); + err = file_modified(dst_file); + inode_unlock(dst_inode); + if (err < 0) + dout("failed to modify dst file after copy (%zd)\n", err); + return ret; } From patchwork Wed May 29 17:43:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10967439 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2B179933 for ; Wed, 29 May 2019 17:43:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C67E2000A for ; Wed, 29 May 2019 17:43:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1058B28A62; Wed, 29 May 2019 17:43:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B57D92000A for ; Wed, 29 May 2019 17:43:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727448AbfE2Rnw (ORCPT ); Wed, 29 May 2019 13:43:52 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:51785 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727345AbfE2Rnu (ORCPT ); Wed, 29 May 2019 13:43:50 -0400 Received: by mail-wm1-f65.google.com with SMTP id f10so2260117wmb.1; Wed, 29 May 2019 10:43:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LuX5OE/4xeK/rXyfFoIQSO2O4Y7R4fvZmK/kzW/AyOc=; b=QHweU0W6vis1g3FWDAwkvTc+uYcEbVGnabnUr7ydLPiaQ3VrO88OCdIzY5BuI3zQoG LlTWKvE2bVVaHzwMESE8R+eWV49mdBnzRpu3tpoknpTd2dNdkmUPS5XIgA5DzCU1Jr0F z53LCTl/JAES+/k0/yaedPqY29A3bBCwhnnhYM8MyWD4c9T0x34U3HEIr4F0olVyCOTv v77+R6+7M3jiLcAW0VAXG0qjm9J3aL63EY7HqcxAbHCk2WTIKfFC0lZ4vG1RkfzwKBCf kDG90wvjrRHn6eUW72BWo6Rd7gCydWt6cPZiQwyLRa6I+X/BHVUsBljW3xIctCi34JQn CAOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LuX5OE/4xeK/rXyfFoIQSO2O4Y7R4fvZmK/kzW/AyOc=; b=Acg6sMW8W6Dews3VO6/A+AyqB38Cd3m7Aq9mgkPyjGsmmpMwva5MSX4LH7+8HT0sn9 kUEF09TADT2M9PQxvGREqMG2YS47tAYLR88Ak1jwnm1CuWH+voSEF2yABOR9l5yC8roL o1Hd+yVh7RKx6c4wXG//CycjccgmlsRb2Zj6rHApbmIpqyEmgCmr/LkqR1lcvnrCbRFN K2mRFBD4X+I4nCBF37mgOE+/9Tw8VL0P6YvqLc6y6BfIc30xx1om31K7/xrkNKPUx+w4 9RiCvcbkrbNQRtYQshJWimskIDYZXpCLvF7yU6k8N04APkewCRfGXD3RbjDTWabZD7bK xMtA== X-Gm-Message-State: APjAAAWncXOTdnFpR8r6Ql7VJL9Rfb4R3FOmcvHqmMJq3qfLYZw4Z5zU zSZ96ZIgRvQ1v2IGEnOBrzI= X-Google-Smtp-Source: APXvYqxMVTsGcUrsWM2pHjICaDWZ1YGun6kQavpkUgEVYAdBg5XpQfH588VNTDt/ZqGP9JxDTC8tTA== X-Received: by 2002:a1c:9904:: with SMTP id b4mr7585387wme.1.1559151827378; Wed, 29 May 2019 10:43:47 -0700 (PDT) Received: from localhost.localdomain ([5.102.238.208]) by smtp.gmail.com with ESMTPSA id k125sm31702wmb.34.2019.05.29.10.43.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 May 2019 10:43:46 -0700 (PDT) From: Amir Goldstein To: "Darrick J . Wong" Cc: Dave Chinner , Christoph Hellwig , linux-xfs@vger.kernel.org, Olga Kornievskaia , Luis Henriques , Al Viro , linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, ceph-devel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org Subject: [PATCH v3 10/13] cifs: copy_file_range needs to strip setuid bits and update timestamps Date: Wed, 29 May 2019 20:43:14 +0300 Message-Id: <20190529174318.22424-11-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190529174318.22424-1-amir73il@gmail.com> References: <20190529174318.22424-1-amir73il@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP cifs has both source and destination inodes locked throughout the copy. Like ->write_iter(), we update mtime and strip setuid bits of destination file before copy and like ->read_iter(), we update atime of source file after copy. Signed-off-by: Amir Goldstein --- fs/cifs/cifsfs.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index c65823270313..ab6c5c24146d 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -1096,6 +1096,10 @@ ssize_t cifs_file_copychunk_range(unsigned int xid, goto out; } + rc = -EOPNOTSUPP; + if (!target_tcon->ses->server->ops->copychunk_range) + goto out; + /* * Note: cifs case is easier than btrfs since server responsible for * checks for proper open modes and file type and if it wants @@ -1107,11 +1111,12 @@ ssize_t cifs_file_copychunk_range(unsigned int xid, /* should we flush first and last page first */ truncate_inode_pages(&target_inode->i_data, 0); - if (target_tcon->ses->server->ops->copychunk_range) + rc = file_modified(dst_file); + if (!rc) rc = target_tcon->ses->server->ops->copychunk_range(xid, smb_file_src, smb_file_target, off, len, destoff); - else - rc = -EOPNOTSUPP; + + file_accessed(src_file); /* force revalidate of size and timestamps of target file now * that target is updated on the server From patchwork Wed May 29 17:43:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10967475 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2FAD2933 for ; Wed, 29 May 2019 17:44:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2429728942 for ; Wed, 29 May 2019 17:44:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 182BD287D3; Wed, 29 May 2019 17:44:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 920CA28942 for ; Wed, 29 May 2019 17:44:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727506AbfE2Rn7 (ORCPT ); Wed, 29 May 2019 13:43:59 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:42154 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727421AbfE2Rnv (ORCPT ); Wed, 29 May 2019 13:43:51 -0400 Received: by mail-wr1-f67.google.com with SMTP id l2so2379570wrb.9; Wed, 29 May 2019 10:43:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=iB8gfO01UWVOvIbXC1SgRvasH8gb3p1b2pcn/FSICGQ=; b=b0k7Uhky+yocLh7DQ5oosoZKI7/cqVQKaU4lK18qqSzkTiwbokIBbcPe+8QkWpRXa8 /SdwMHVqdJZQqTm1Fq1HdJTbttYNaiTx80cqXKZKTcxiAlH7x47tQiZtgM09gOqMUU4c dOG8N4gYpx+jTYmeNj39drvhVoHEmrwIeEvk/HncoD+JQ42uuDcCp/FazXiOnmjbmA0y Qyws70g4mdHlzhfgWhGdgY/dMtF8JmkPZiaOrD7l5uW8qrY61bJjm1qranskdKzNJQKa 7EVtbBYF9DG+lINa//bbPNSWhu3w6ZQMnKrFNN3ZOzT9LC9pbEW5SVAV44T0KHYzwOYb DcMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=iB8gfO01UWVOvIbXC1SgRvasH8gb3p1b2pcn/FSICGQ=; b=kpnlOT/7+5r0Ewo6ThMmk0KjjbrF64+XosP/4yYxy3MBcwI84b3ojsus4EwSTuEwpP u1bnVn7Dl4nqJ7sdB+l304rHwjschwt050RVBblQ//7f7gOts9YezS/VleehbElM8eXL xASgZr/grByxK8LcSJrec+Mcked0v0S+7OB1g4GAPT/BtJRS4t/U/t+cjAbcy8JG/JJE sCqQN5H4uOP5w3BMfWIpSkywjYdmyC7uPUTTjUJLxrh3oWuYVzGvnKcaznLhUc7mkTKp azaA0EdL9HTONDlFnGPiFnuBYUb3/jBPJDDqGWTa7amD7ozMBR/ENlNJzhwZ2bTD+w/l yohQ== X-Gm-Message-State: APjAAAXy8y1Bpvj7ngqIYQ6Y7ynqh8C1p58NCZRHh8QZR8B8ewbe1eFE PSKrGi0A09pA+DWVIglHdoc= X-Google-Smtp-Source: APXvYqwJOJ4izTFnolZmkhfQaBuL6JfpKe4IKnghtgloYRwVTP4nUzDRTpo9aL+/5u/O6Q118FCXnA== X-Received: by 2002:adf:db4c:: with SMTP id f12mr4020367wrj.243.1559151829055; Wed, 29 May 2019 10:43:49 -0700 (PDT) Received: from localhost.localdomain ([5.102.238.208]) by smtp.gmail.com with ESMTPSA id k125sm31702wmb.34.2019.05.29.10.43.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 May 2019 10:43:48 -0700 (PDT) From: Amir Goldstein To: "Darrick J . Wong" Cc: Dave Chinner , Christoph Hellwig , linux-xfs@vger.kernel.org, Olga Kornievskaia , Luis Henriques , Al Viro , linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, ceph-devel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org Subject: [PATCH v3 11/13] fuse: copy_file_range needs to strip setuid bits and update timestamps Date: Wed, 29 May 2019 20:43:15 +0300 Message-Id: <20190529174318.22424-12-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190529174318.22424-1-amir73il@gmail.com> References: <20190529174318.22424-1-amir73il@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Like ->write_iter(), we update mtime and strip setuid of dst file before copy and like ->read_iter(), we update atime of src file after copy. Signed-off-by: Amir Goldstein --- fs/fuse/file.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index e03901ae729b..7f33d68f66d9 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -3128,6 +3128,10 @@ static ssize_t __fuse_copy_file_range(struct file *file_in, loff_t pos_in, inode_lock(inode_out); + err = file_modified(file_out); + if (err) + goto out; + if (fc->writeback_cache) { err = filemap_write_and_wait_range(inode_out->i_mapping, pos_out, pos_out + len); @@ -3169,6 +3173,7 @@ static ssize_t __fuse_copy_file_range(struct file *file_in, loff_t pos_in, clear_bit(FUSE_I_SIZE_UNSTABLE, &fi_out->state); inode_unlock(inode_out); + file_accessed(file_in); return err; } From patchwork Wed May 29 17:43:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10967453 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5D7DF18A6 for ; Wed, 29 May 2019 17:43:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 517CF28451 for ; Wed, 29 May 2019 17:43:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4FBC0286E4; Wed, 29 May 2019 17:43:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E17E22856E for ; Wed, 29 May 2019 17:43:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727468AbfE2Rnx (ORCPT ); Wed, 29 May 2019 13:43:53 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:42156 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726018AbfE2Rnw (ORCPT ); Wed, 29 May 2019 13:43:52 -0400 Received: by mail-wr1-f68.google.com with SMTP id l2so2379619wrb.9; Wed, 29 May 2019 10:43:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=HN28jzdWIDmYfqKHB1OqlcDa2tkQLMvz+g74LeD+kio=; b=JUf3gpx4X+xBASgixo3psABkDGhXiKV7Lv6aCmi3cIY5g3UvcqkbbvIo4LEBHHlOcM 47HvlL4K1Cfr3ZCYRlFlQMk169fxuc4V9OE11x9tSy5YsvifN+2+3lazi2lND22my4/4 vd26PGS+5Js9jWQid+RCNzQaf/Cxq14XwTGKpzF/Q1Bka7r0NBU4GOkAB1YemhBS82Bd Lb9aAjs9AjZ7/j02/iDPiRAipCy9DyKOAKm748nAnJr525j6GQIkn1vJLKJPSxueSVCR /PoGsscocZt9StBbSuN5VS082vCWGMzYH/2Eb9v2UTVF6paGYYjXEs0W0yHzHIGdVPtu C46w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=HN28jzdWIDmYfqKHB1OqlcDa2tkQLMvz+g74LeD+kio=; b=MS3J53CKNFFz2rSBpksU06XDAGDj5zEwBl97iWik1SdEGEpAu2hHiKo+yeEmArIUdH lVEdbH+QoprW0X1IMQcPfUtTLbUfKvZEyepItdQ6QjxR6pUsEu0l0We+CMDP4UeQeOxb kTHBgPvlK9+tKT5LA4QixKCRxlZNGa6TjE4ZXh7uVD+wiALxQLko4Dde1GHWKU7lx/vp WhMoxl6fMWMFPIveljlgAIdfjq2zvi8GpNgM/V0ksTdqUzcixcWRMogRtSZl0/SOYpPI gAf8s+A2QWO4oqNnn/WLPUeXtLXSkF+RtITh+807gT7Pfn16DXb+jUsKAvb1bvl0TlRT 0bsA== X-Gm-Message-State: APjAAAVTvoCspflraceM8mhM/vJyv87EVG6nZE5hambx2Ehn6+94HYzl B60kVO5j7/HCi8OZDQrjpBk= X-Google-Smtp-Source: APXvYqy4vphWl+uJOQFfpvp7RUdNvXC3EMyYKCKKMmpEfRH0EaEwUWjRn9WIuethzwglftoWN3AHHA== X-Received: by 2002:a5d:54cc:: with SMTP id x12mr35442527wrv.303.1559151830843; Wed, 29 May 2019 10:43:50 -0700 (PDT) Received: from localhost.localdomain ([5.102.238.208]) by smtp.gmail.com with ESMTPSA id k125sm31702wmb.34.2019.05.29.10.43.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 May 2019 10:43:50 -0700 (PDT) From: Amir Goldstein To: "Darrick J . Wong" Cc: Dave Chinner , Christoph Hellwig , linux-xfs@vger.kernel.org, Olga Kornievskaia , Luis Henriques , Al Viro , linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, ceph-devel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org Subject: [PATCH v3 12/13] nfs: copy_file_range needs to strip setuid bits and update timestamps Date: Wed, 29 May 2019 20:43:16 +0300 Message-Id: <20190529174318.22424-13-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190529174318.22424-1-amir73il@gmail.com> References: <20190529174318.22424-1-amir73il@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Like ->write_iter(), we update mtime and strip setuid of dst file before copy and like ->read_iter(), we update atime of src file after copy. Signed-off-by: Amir Goldstein --- fs/nfs/nfs42proc.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fs/nfs/nfs42proc.c b/fs/nfs/nfs42proc.c index 5196bfa7894d..c37a8e5116c6 100644 --- a/fs/nfs/nfs42proc.c +++ b/fs/nfs/nfs42proc.c @@ -345,10 +345,13 @@ ssize_t nfs42_proc_copy(struct file *src, loff_t pos_src, do { inode_lock(file_inode(dst)); - err = _nfs42_proc_copy(src, src_lock, - dst, dst_lock, - &args, &res); + err = file_modified(dst); + if (!err) + err = _nfs42_proc_copy(src, src_lock, + dst, dst_lock, + &args, &res); inode_unlock(file_inode(dst)); + file_accessed(src); if (err >= 0) break; From patchwork Wed May 29 17:43:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10967463 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7D44B18A6 for ; Wed, 29 May 2019 17:43:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 718B1288E5 for ; Wed, 29 May 2019 17:43:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6FA1F28915; Wed, 29 May 2019 17:43:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DDF64288E5 for ; Wed, 29 May 2019 17:43:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727484AbfE2Rn4 (ORCPT ); Wed, 29 May 2019 13:43:56 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:42155 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727469AbfE2Rnz (ORCPT ); Wed, 29 May 2019 13:43:55 -0400 Received: by mail-wr1-f65.google.com with SMTP id l2so2379663wrb.9; Wed, 29 May 2019 10:43:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=T2Smjb+P/jamD/M2jOo9Duoj3MRoGI3Hr+9fU0qlJ6w=; b=FU1FhQe1TIQdXbxXVf5dUrBoSLGXOIJMF39wk8OT0iVzWXt6cRkIxk5E/6Mm1SBygS 0Ny+shwFxfXEXz/ET5VAXJp02SE5E09b8AsbMMvPcz2sKlHr0qP+jB7VQ/NI++XxbdAx 5eGO1zStdB4JYZj20CKwnNzYU118nPj5y1MtHy6jhCwjSl5YX4kPUrLmhhxdwDRfkFI9 uzoqhOZ91LZ83r+YNijpFAkr2yB0fK4JEqgWl2ahEHASmD9CBoHoYVhZoHzYAM0Uuhj9 dtWyi+CtS1M65llXJNXqALbsOtznGOyDG3VbWllmR2yNIyccZZpJ+/zJFzLXmgCPenoJ EeBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=T2Smjb+P/jamD/M2jOo9Duoj3MRoGI3Hr+9fU0qlJ6w=; b=AJ/w/B19J7cDlZpmEgO7ce9aKf2W2ClxgBpln/oqtzrDygIKeMQ07NPMJbfGzviu6P Wrksea5oThEp6eehtckpmgF7K65EklHQqRanloWa5hMJ5tdwJJGUrk04rGoZbHgf2iq0 UfZaySOZsKhLN9I+/MZifn+OzS14glzhmEDsY8EF5YjoKBiCYKIBzgvnZ1H1M1vfWp37 sWMOJOyjRCUx5cg9DmAxmmyO3OAadP4hacb7TS4b7Qq+cm6ayfw884QZ0so7s562qBbk vA+zxHJfMPMPx2rOYFibIjkTeO87p+ww/LYU7zykz6nhpQvsBRzb9sa6z7tiDR3ZpYiG bIGA== X-Gm-Message-State: APjAAAUrq4J4VCOclPiGQbDedQ+EoFgRZdADdnXBPrROCAHJa9NHx1QN S8yhVtzF2HqCekA0JPFLcmw= X-Google-Smtp-Source: APXvYqy5Ykid2UHE9Xy5TwnsBq4/hT/qPUHgFp/uKL/KopsjCES3wSKuYyQJelul4J8R3Ch0F2ys6g== X-Received: by 2002:adf:e945:: with SMTP id m5mr9492027wrn.90.1559151832848; Wed, 29 May 2019 10:43:52 -0700 (PDT) Received: from localhost.localdomain ([5.102.238.208]) by smtp.gmail.com with ESMTPSA id k125sm31702wmb.34.2019.05.29.10.43.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 May 2019 10:43:52 -0700 (PDT) From: Amir Goldstein To: "Darrick J . Wong" Cc: Dave Chinner , Christoph Hellwig , linux-xfs@vger.kernel.org, Olga Kornievskaia , Luis Henriques , Al Viro , linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, ceph-devel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, Steve French , Dave Chinner Subject: [PATCH v3 13/13] vfs: allow copy_file_range to copy across devices Date: Wed, 29 May 2019 20:43:17 +0300 Message-Id: <20190529174318.22424-14-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190529174318.22424-1-amir73il@gmail.com> References: <20190529174318.22424-1-amir73il@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We want to enable cross-filesystem copy_file_range functionality where possible, so push the "same superblock only" checks down to the individual filesystem callouts so they can make their own decisions about cross-superblock copy offload and fallack to generic_copy_file_range() for cross-superblock copy. [Amir] We do not call ->remap_file_range() in case the inodes are not on the same sb and do not call ->copy_file_range() in case the inodes are not on the same filesystem type. This changes behavior of the copy_file_range(2) syscall, which will now allow cross filesystem in-kernel copy. CIFS already supports cross-superblock copy, between two shares to the same server. This functionality will now be available via the copy_file_range(2) syscall. Cc: Steve French Signed-off-by: Dave Chinner Signed-off-by: Amir Goldstein Reviewed-by: Darrick J. Wong --- fs/ceph/file.c | 4 +++- fs/cifs/cifsfs.c | 2 +- fs/fuse/file.c | 5 ++++- fs/nfs/nfs4file.c | 5 ++++- fs/read_write.c | 20 ++++++++++++++------ 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/fs/ceph/file.c b/fs/ceph/file.c index 8a70708e1aca..e9614d686301 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -1909,6 +1909,8 @@ static ssize_t __ceph_copy_file_range(struct file *src_file, loff_t src_off, if (src_inode == dst_inode) return -EINVAL; + if (src_inode->i_sb != dst_inode->i_sb) + return -EXDEV; if (ceph_snap(dst_inode) != CEPH_NOSNAP) return -EROFS; @@ -2126,7 +2128,7 @@ static ssize_t ceph_copy_file_range(struct file *src_file, loff_t src_off, ret = __ceph_copy_file_range(src_file, src_off, dst_file, dst_off, len, flags); - if (ret == -EOPNOTSUPP) + if (ret == -EOPNOTSUPP || ret == -EXDEV) ret = generic_copy_file_range(src_file, src_off, dst_file, dst_off, len, flags); return ret; diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index ab6c5c24146d..83956452c108 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -1154,7 +1154,7 @@ static ssize_t cifs_copy_file_range(struct file *src_file, loff_t off, len, flags); free_xid(xid); - if (rc == -EOPNOTSUPP) + if (rc == -EOPNOTSUPP || rc == -EXDEV) rc = generic_copy_file_range(src_file, off, dst_file, destoff, len, flags); return rc; diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 7f33d68f66d9..eab00cd089e8 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -3126,6 +3126,9 @@ static ssize_t __fuse_copy_file_range(struct file *file_in, loff_t pos_in, if (fc->no_copy_file_range) return -EOPNOTSUPP; + if (file_inode(file_in)->i_sb != file_inode(file_out)->i_sb) + return -EXDEV; + inode_lock(inode_out); err = file_modified(file_out); @@ -3187,7 +3190,7 @@ static ssize_t fuse_copy_file_range(struct file *src_file, loff_t src_off, ret = __fuse_copy_file_range(src_file, src_off, dst_file, dst_off, len, flags); - if (ret == -EOPNOTSUPP) + if (ret == -EOPNOTSUPP || ret == -EXDEV) ret = generic_copy_file_range(src_file, src_off, dst_file, dst_off, len, flags); return ret; diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c index 4842f3ab3161..f4157eb1f69d 100644 --- a/fs/nfs/nfs4file.c +++ b/fs/nfs/nfs4file.c @@ -133,6 +133,9 @@ static ssize_t __nfs4_copy_file_range(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, size_t count, unsigned int flags) { + /* Only offload copy if superblock is the same */ + if (file_inode(file_in)->i_sb != file_inode(file_out)->i_sb) + return -EXDEV; if (!nfs_server_capable(file_inode(file_out), NFS_CAP_COPY)) return -EOPNOTSUPP; if (file_inode(file_in) == file_inode(file_out)) @@ -148,7 +151,7 @@ static ssize_t nfs4_copy_file_range(struct file *file_in, loff_t pos_in, ret = __nfs4_copy_file_range(file_in, pos_in, file_out, pos_out, count, flags); - if (ret == -EOPNOTSUPP) + if (ret == -EOPNOTSUPP || ret == -EXDEV) ret = generic_copy_file_range(file_in, pos_in, file_out, pos_out, count, flags); return ret; diff --git a/fs/read_write.c b/fs/read_write.c index 706ea5f276a7..d8930bb735cb 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1618,7 +1618,18 @@ static ssize_t do_copy_file_range(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, size_t len, unsigned int flags) { - if (file_out->f_op->copy_file_range) + /* + * Although we now allow filesystems to handle cross sb copy, passing + * an inode of the wrong filesystem type to filesystem operation can + * often result in an attempt to dereference the wrong concrete inode + * struct, so avoid doing that until we really have a good reason. + * The incentive for passing inode from different sb to filesystem is + * NFS cross server copy and for that use case, enforcing same + * filesystem type is acceptable. + */ + if (file_out->f_op->copy_file_range && + file_inode(file_in)->i_sb->s_type == + file_inode(file_out)->i_sb->s_type) return file_out->f_op->copy_file_range(file_in, pos_in, file_out, pos_out, len, flags); @@ -1641,10 +1652,6 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, if (flags != 0) return -EINVAL; - /* this could be relaxed once a method supports cross-fs copies */ - if (file_inode(file_in)->i_sb != file_inode(file_out)->i_sb) - return -EXDEV; - ret = generic_copy_file_checks(file_in, pos_in, file_out, pos_out, &len, flags); if (unlikely(ret)) @@ -1667,7 +1674,8 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, * Try cloning first, this is supported by more file systems, and * more efficient if both clone and copy are supported (e.g. NFS). */ - if (file_in->f_op->remap_file_range) { + if (file_in->f_op->remap_file_range && + file_inode(file_in)->i_sb == file_inode(file_out)->i_sb) { loff_t cloned; cloned = file_in->f_op->remap_file_range(file_in, pos_in, From patchwork Wed May 29 17:43:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10967487 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7A46C18A6 for ; Wed, 29 May 2019 17:44:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E7FB28910 for ; Wed, 29 May 2019 17:44:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6CEE228A48; Wed, 29 May 2019 17:44:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA55928915 for ; Wed, 29 May 2019 17:44:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727527AbfE2RoD (ORCPT ); Wed, 29 May 2019 13:44:03 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:33367 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727469AbfE2Rn7 (ORCPT ); Wed, 29 May 2019 13:43:59 -0400 Received: by mail-wr1-f68.google.com with SMTP id d9so2423637wrx.0; Wed, 29 May 2019 10:43:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WwUXFPt91WsbqtPlQqDtW6uVrMZ3xNSrz8TFzSKWF9s=; b=kf/RbiJQg7mY7JWj8U88yy+RrZJtDkshcjme8EVPKqvUbPAssOTDRnNP1VNAJ0h5Gc dMWRtByZJr1qKG5Q5uI1w97m56tFxUwmXjOVmyVVC8qlW4dYeec1BKvRZzNLrHr1CNQ0 5gNMS4EgXXIOzDl+0ogkbeD68WZt6N6Pvg71HoUBeKMJNIcHe4rKQP5qL4ef+hvvCGq3 nQgv3BPv+/4x5MP6SgimEh+I2+6CkR6rKuaGOJinoqZJXPyZJwyL7jDdmROGnlQ2YoXg 3KBkdGqgoKoHuXtfwPByykh2zARsr6aaj3dRjfxMGeopSAmzPys3JebTBaKr907nctYO +1Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WwUXFPt91WsbqtPlQqDtW6uVrMZ3xNSrz8TFzSKWF9s=; b=aDtcho74Fc/WehzZZM+QrYOjVhA4gVKRr/vIi/Go5gL5rKISr/qvNOsYK789oyoimF ziiGi3W7L6jwhyZqFMfFEtLO9Lp9mQSY4URj2g4EyjZp8dyjyFYzEgOfd7K38wvDCdzP TsYUTYMpgy9I0U9SnLNVTlEEKGfyupsFWz9tCMW5GaDuZTGT//Ae3XDh5dWG1AV3Xfyg /E/VA2OrPLhKZHTfwoW52KvBjWeWfJeblhyGzDD4M8ZEWczPYwzTC/iGWZFwk2hxzXvg SK4hszL72OENbNqWtFzYYIVa/pe0rq/1oLdE8ifk3e3uoYvjISBN3V05VFjnp52JMadU ddSQ== X-Gm-Message-State: APjAAAWmwgpgah5y4p6/RXRnz1ZwIma3MiyRXhX3AzLoim2pvu7J507B xNjyYtA+yVsh8GBcM9hAPqs2yXnV2aU= X-Google-Smtp-Source: APXvYqyiizi1bOIdpKqtlzXoIQKQkDk0I9v+OMY7YcuXQtTDJ6jKNhalBgGr3FYtY4ncHATZsZrOKg== X-Received: by 2002:adf:e2c7:: with SMTP id d7mr45926208wrj.272.1559151834922; Wed, 29 May 2019 10:43:54 -0700 (PDT) Received: from localhost.localdomain ([5.102.238.208]) by smtp.gmail.com with ESMTPSA id k125sm31702wmb.34.2019.05.29.10.43.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 May 2019 10:43:54 -0700 (PDT) From: Amir Goldstein To: "Darrick J . Wong" Cc: Dave Chinner , Christoph Hellwig , linux-xfs@vger.kernel.org, Olga Kornievskaia , Luis Henriques , Al Viro , linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, ceph-devel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, Dave Chinner Subject: [PATCH v3 14/13] man-pages: copy_file_range updates Date: Wed, 29 May 2019 20:43:18 +0300 Message-Id: <20190529174318.22424-15-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190529174318.22424-1-amir73il@gmail.com> References: <20190529174318.22424-1-amir73il@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Update with all the missing errors the syscall can return, the behaviour the syscall should have w.r.t. to copies within single files, etc. [Amir] Copying beyond EOF returns zero. Signed-off-by: Dave Chinner Signed-off-by: Amir Goldstein --- man2/copy_file_range.2 | 91 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 78 insertions(+), 13 deletions(-) diff --git a/man2/copy_file_range.2 b/man2/copy_file_range.2 index 2438b63c8..9f9b081a7 100644 --- a/man2/copy_file_range.2 +++ b/man2/copy_file_range.2 @@ -42,9 +42,9 @@ without the additional cost of transferring data from the kernel to user space and then back into the kernel. It copies up to .I len -bytes of data from file descriptor +bytes of data from the source file descriptor .I fd_in -to file descriptor +to the target file descriptor .IR fd_out , overwriting any data that exists within the requested range of the target file. .PP @@ -74,6 +74,12 @@ is not changed, but .I off_in is adjusted appropriately. .PP +.I fd_in +and +.I fd_out +can refer to the same file. +If they refer to the same file, then the source and target ranges are not +allowed to overlap. .PP The .I flags @@ -84,6 +90,11 @@ Upon successful completion, .BR copy_file_range () will return the number of bytes copied between files. This could be less than the length originally requested. +If the file offset of +.I fd_in +is at or past the end of file, no bytes are copied, and +.BR copy_file_range () +returns zero. .PP On error, .BR copy_file_range () @@ -93,12 +104,16 @@ is set to indicate the error. .SH ERRORS .TP .B EBADF -One or more file descriptors are not valid; or +One or more file descriptors are not valid. +.TP +.B EBADF .I fd_in is not open for reading; or .I fd_out -is not open for writing; or -the +is not open for writing. +.TP +.B EBADF +The .B O_APPEND flag is set for the open file description (see .BR open (2)) @@ -106,24 +121,52 @@ referred to by the file descriptor .IR fd_out . .TP .B EFBIG -An attempt was made to write a file that exceeds the implementation-defined -maximum file size or the process's file size limit, -or to write at a position past the maximum allowed offset. +An attempt was made to write at a position past the maximum file offset the +kernel supports. +.TP +.B EFBIG +An attempt was made to write a range that exceeds the allowed maximum file size. +The maximum file size differs between filesystem implementations and can be +different from the maximum allowed file offset. +.TP +.B EFBIG +An attempt was made to write beyond the process's file size resource limit. +This may also result in the process receiving a +.I SIGXFSZ +signal. .TP .B EINVAL -Requested range extends beyond the end of the source file; or the +The .I flags argument is not 0. .TP -.B EIO -A low-level I/O error occurred while copying. +.B EINVAL +.I fd_in +and +.I fd_out +refer to the same file and the source and target ranges overlap. +.TP +.B EINVAL +Either +.I fd_in +or +.I fd_out +is not a regular file. .TP .B EISDIR +Either .I fd_in or .I fd_out refers to a directory. .TP +.B EOVERFLOW +The requested source or destination range is too large to represent in the +specified data types. +.TP +.B EIO +A low-level I/O error occurred while copying. +.TP .B ENOMEM Out of memory. .TP @@ -133,13 +176,35 @@ There is not enough space on the target filesystem to complete the copy. .B EXDEV The files referred to by .IR file_in " and " file_out -are not on the same mounted filesystem. +are not on the same mounted filesystem (pre Linux 5.3). +.TP +.B TXTBSY +Either +.I fd_in +or +.I fd_out +refers to an active swap file. +.TP +.B EPERM +.I fd_out +refers to an immutable file. +.TP +.B EACCES +The user does not have write permissions for the destination file. .SH VERSIONS The .BR copy_file_range () system call first appeared in Linux 4.5, but glibc 2.27 provides a user-space emulation when it is not available. .\" https://sourceware.org/git/?p=glibc.git;a=commit;f=posix/unistd.h;h=bad7a0c81f501fbbcc79af9eaa4b8254441c4a1f +.PP +A major rework of the kernel implementation occurred in 5.3. +Areas of the API that weren't clearly defined were clarified and the API bounds +are much more strictly checked than on earlier kernels. +Applications should target the behaviour and requirements of 5.3 kernels. +.PP +First support for cross-filesystem copies was introduced in Linux 5.3. +Older kernels will return -EXDEV when cross-filesystem copies are attempted. .SH CONFORMING TO The .BR copy_file_range () @@ -224,7 +289,7 @@ main(int argc, char **argv) } len \-= ret; - } while (len > 0); + } while (len > 0 && ret > 0); close(fd_in); close(fd_out);