Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5836943pxb; Tue, 16 Feb 2021 08:44:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJxkzIWEMSbLjsGIlLMSUj+s/6G/x4SdD0sv7b9IWB6XIj1D7aOCwa2dIk3ybkq2X6Q00npP X-Received: by 2002:aa7:d358:: with SMTP id m24mr21488404edr.118.1613493896317; Tue, 16 Feb 2021 08:44:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613493896; cv=none; d=google.com; s=arc-20160816; b=xEQOKt1S1QGT2pdMNuwz/iFf0HrhWTDqGbAAXBQ7nIi9RDIT1kmDvrS/+zZnkya9e8 um4HQR1Tf7bAHOwgT6gti0x0Jwh9rKElwYgycNZGYEcnYpYVZ1aESxL9P7JcyGRedI2v 3wOkeDQVdOR2duf0nDfiAH7PPimI9i4CO5dTZ0e6HxH2nulbzJ2QheoHgt6brHFVFBOR MQRo4flFeRN7U3dSFlZg6ppHT3ahyLMIF9r76EIMnpHf+Jl4XlKxORRZcEevZLucr48B l2gKA+MNfut14v8WmmBy0IRaulOcwrMpOZUhwRwse/f84x5o2FEfbEh9BAOBlsCiIHEO 2i1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:in-reply-to:date :references:subject:cc:to:from; bh=HCW2lvkPig8rZLPb7d+qaKLb9D59dsPkU/GFV0ib/10=; b=ahncI6oQBqa2gQW8V7p68i5/wpzFChIHejo3Ck+PakMx1ay4pV7qqt3SQaMy17ML0t dbbKuMQAlZeGeG50YXdWKALrDsurSmIDOH7a7SDEFnw781TNAvXbwycnTXvubDgca/dc UZ1w4OPLRe6CwG2kjbn5QFi0nrH2XG8hmtT+pRzRJy5qeuJ79anQe/aVDdE6UFPnXhFh A6zO9FEJT3RYvy7kQ1kgEv14wwfH88K3K7a/ogBIIeO5nwcHB6EcBEtws+ZQ5hCMuKHb nIoIwXXa7OJ8YEUWJWPy1QXHG1Z2X9yAsyQ4XNslbQOIDk8EVPW8ah/cxuTborS5m9K3 VcgQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id eb13si18395061edb.8.2021.02.16.08.44.32; Tue, 16 Feb 2021 08:44:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230467AbhBPQmP (ORCPT + 99 others); Tue, 16 Feb 2021 11:42:15 -0500 Received: from mx2.suse.de ([195.135.220.15]:50348 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230077AbhBPQmN (ORCPT ); Tue, 16 Feb 2021 11:42:13 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 4BE4FAF5B; Tue, 16 Feb 2021 16:41:31 +0000 (UTC) Received: from localhost (brahms [local]) by brahms (OpenSMTPD) with ESMTPA id f662a3f7; Tue, 16 Feb 2021 16:42:32 +0000 (UTC) From: Luis Henriques To: Amir Goldstein Cc: Trond Myklebust , "samba-technical@lists.samba.org" , "drinkcat@chromium.org" , "iant@google.com" , "linux-cifs@vger.kernel.org" , "darrick.wong@oracle.com" , "linux-kernel@vger.kernel.org" , "jlayton@kernel.org" , "anna.schumaker@netapp.com" , "llozano@chromium.org" , "linux-nfs@vger.kernel.org" , "miklos@szeredi.hu" , "viro@zeniv.linux.org.uk" , "dchinner@redhat.com" , "linux-fsdevel@vger.kernel.org" , "gregkh@linuxfoundation.org" , "sfrench@samba.org" , "ceph-devel@vger.kernel.org" Subject: Re: [PATCH v2] vfs: prevent copy_file_range to copy across devices References: <20210215154317.8590-1-lhenriques@suse.de> <73ab4951f48d69f0183548c7a82f7ae37e286d1c.camel@hammerspace.com> <92d27397479984b95883197d90318ee76995b42e.camel@hammerspace.com> <87r1lgjm7l.fsf@suse.de> Date: Tue, 16 Feb 2021 16:42:32 +0000 In-Reply-To: (Amir Goldstein's message of "Tue, 16 Feb 2021 15:51:56 +0200") Message-ID: <87blckj75z.fsf@suse.de> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Amir Goldstein writes: >> Ugh. And I guess overlayfs may have a similar problem. > > Not exactly. > Generally speaking, overlayfs should call vfs_copy_file_range() > with the flags it got from layer above, so if called from nfsd it > will allow cross fs copy and when called from syscall it won't. > > There are some corner cases where overlayfs could benefit from > COPY_FILE_SPLICE (e.g. copy from lower file to upper file), but > let's leave those for now. Just leave overlayfs code as is. Got it, thanks for clarifying. >> > This is easy to solve with a flag COPY_FILE_SPLICE (or something) that >> > is internal to kernel users. >> > >> > FWIW, you may want to look at the loop in ovl_copy_up_data() >> > for improvements to nfsd_copy_file_range(). >> > >> > We can move the check out to copy_file_range syscall: >> > >> > if (flags != 0) >> > return -EINVAL; >> > >> > Leave the fallback from all filesystems and check for the >> > COPY_FILE_SPLICE flag inside generic_copy_file_range(). >> >> Ok, the diff bellow is just to make sure I understood your suggestion. >> >> The patch will also need to: >> >> - change nfs and overlayfs calls to vfs_copy_file_range() so that they >> use the new flag. >> >> - check flags in generic_copy_file_checks() to make sure only valid flags >> are used (COPY_FILE_SPLICE at the moment). >> >> Also, where should this flag be defined? include/uapi/linux/fs.h? > > Grep for REMAP_FILE_ > Same header file, same Documentation rst file. > >> >> Cheers, >> -- >> Luis >> >> diff --git a/fs/read_write.c b/fs/read_write.c >> index 75f764b43418..341d315d2a96 100644 >> --- a/fs/read_write.c >> +++ b/fs/read_write.c >> @@ -1383,6 +1383,13 @@ 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) >> { >> + if (!(flags & COPY_FILE_SPLICE)) { >> + if (!file_out->f_op->copy_file_range) >> + return -EOPNOTSUPP; >> + else if (file_out->f_op->copy_file_range != >> + file_in->f_op->copy_file_range) >> + return -EXDEV; >> + } > > That looks strange, because you are duplicating the logic in > do_copy_file_range(). Maybe better: > > if (WARN_ON_ONCE(flags & ~COPY_FILE_SPLICE)) > return -EINVAL; > if (flags & COPY_FILE_SPLICE) > return do_splice_direct(file_in, &pos_in, file_out, &pos_out, > len > MAX_RW_COUNT ? MAX_RW_COUNT : len, 0); My initial reasoning for duplicating the logic in do_copy_file_range() was to allow the generic_copy_file_range() callers to be left unmodified and allow the filesystems to default to this implementation. With this change, I guess that the calls to generic_copy_file_range() from the different filesystems can be dropped, as in my initial patch, as they will always get -EINVAL. The other option would be to set the COPY_FILE_SPLICE flag in those calls, but that would get us back to the problem we're trying to solve. > if (!file_out->f_op->copy_file_range) > return -EOPNOTSUPP; > return -EXDEV; > >> } >> @@ -1474,9 +1481,6 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, >> { >> ssize_t ret; >> >> - if (flags != 0) >> - return -EINVAL; >> - > > This needs to move to the beginning of SYSCALL_DEFINE6(copy_file_range,... Yep, I didn't included that change in my diff as I wasn't sure if you'd like to have the flag visible in userspace. Anyway, thanks for your patience! Cheers, -- Luis