From patchwork Mon Dec 3 08:34:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Chinner X-Patchwork-Id: 10708889 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 0AE1A1923 for ; Mon, 3 Dec 2018 08:40:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F13AE2A967 for ; Mon, 3 Dec 2018 08:40:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E514C2A97B; Mon, 3 Dec 2018 08:40:18 +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=-7.9 required=2.0 tests=BAYES_00,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 8F1332ABB5 for ; Mon, 3 Dec 2018 08:40:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725901AbeLCIkT (ORCPT ); Mon, 3 Dec 2018 03:40:19 -0500 Received: from ipmailnode02.adl6.internode.on.net ([150.101.137.148]:53319 "EHLO ipmailnode02.adl6.internode.on.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725972AbeLCIjh (ORCPT ); Mon, 3 Dec 2018 03:39:37 -0500 Received: from ppp59-167-129-252.static.internode.on.net (HELO dastard) ([59.167.129.252]) by ipmail02.adl6.internode.on.net with ESMTP; 03 Dec 2018 19:04:19 +1030 Received: from discord.disaster.area ([192.168.1.111]) by dastard with esmtp (Exim 4.80) (envelope-from ) id 1gTjgJ-0003PY-4o; Mon, 03 Dec 2018 19:34:19 +1100 Received: from dave by discord.disaster.area with local (Exim 4.91) (envelope-from ) id 1gTjgJ-00006G-3l; Mon, 03 Dec 2018 19:34:19 +1100 From: Dave Chinner To: linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Cc: olga.kornievskaia@gmail.com, linux-nfs@vger.kernel.org, linux-unionfs@vger.kernel.org, ceph-devel@vger.kernel.org, linux-cifs@vger.kernel.org Subject: [PATCH 08/11] vfs: push EXDEV check down into ->remap_file_range Date: Mon, 3 Dec 2018 19:34:13 +1100 Message-Id: <20181203083416.28978-9-david@fromorbit.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181203083416.28978-1-david@fromorbit.com> References: <20181203083416.28978-1-david@fromorbit.com> MIME-Version: 1.0 Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Dave Chinner before we can enable cross-device copies into copy_file_range(), we have to ensure that ->remap_file_range() implemenations will correctly reject attempts to do cross filesystem clones. Currently these checks are done above calls to ->remap_file_range(), but we need to drive them inwards so that we get EXDEV protection for all callers of ->remap_file_range(). Signed-off-by: Dave Chinner --- fs/read_write.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index 3288db1d5f21..174cf92eea1d 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1909,6 +1909,19 @@ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, bool same_inode = (inode_in == inode_out); int ret; + /* + * 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. We check this here rather than at the ioctl layers because + * this is effectively a limitation of the fielsystem implementations, + * not so much the API itself. Further, ->remap_file_range() can be + * called from syscalls that don't have cross device copy restrictions + * (such as copy_file_range()) and so we need to catch them before we + * do any damage. + */ + if (inode_in->i_sb != inode_out->i_sb) + return -EXDEV; + /* Don't touch certain kinds of inodes */ if (IS_IMMUTABLE(inode_out)) return -EPERM; @@ -2013,14 +2026,6 @@ loff_t do_clone_file_range(struct file *file_in, loff_t pos_in, 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) - return -EXDEV; - if (!(file_in->f_mode & FMODE_READ) || !(file_out->f_mode & FMODE_WRITE) || (file_out->f_flags & O_APPEND))