diff mbox series

[bpf-next,v3,2/4] libfs: support RENAME_EXCHANGE in simple_rename()

Message ID 20211028094724.59043-3-lmb@cloudflare.com (mailing list archive)
State Accepted
Commit 3871cb8cf741dcd8ebaec4f960be9479da2f176b
Delegated to: BPF
Headers show
Series Support RENAME_EXCHANGE on bpffs | expand

Checks

Context Check Description
netdev/cover_letter success Series has a cover letter
netdev/fixes_present success Fixes tag not required for -next series
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for bpf-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 5 maintainers not CCed: john.fastabend@gmail.com yhs@fb.com songliubraving@fb.com kafai@fb.com kpsingh@kernel.org
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 1 this patch: 1
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success No Fixes tag
netdev/checkpatch warning WARNING: line length of 88 exceeds 80 columns
netdev/build_allmodconfig_warn success Errors and warnings before: 1 this patch: 1
netdev/header_inline success No static functions without inline keyword in header files
bpf/vmtest-bpf-next fail VM_Test
bpf/vmtest-bpf-next-PR fail PR summary

Commit Message

Lorenz Bauer Oct. 28, 2021, 9:47 a.m. UTC
Allow atomic exchange via RENAME_EXCHANGE when using simple_rename.
This affects binderfs, ramfs, hubetlbfs and bpffs.

Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
---
 fs/libfs.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Miklos Szeredi Nov. 2, 2021, 9:25 a.m. UTC | #1
On Thu, 28 Oct 2021 at 11:48, Lorenz Bauer <lmb@cloudflare.com> wrote:
>
> Allow atomic exchange via RENAME_EXCHANGE when using simple_rename.
> This affects binderfs, ramfs, hubetlbfs and bpffs.

Ramfs and hugetlbfs are generic enough; those seem safe.

Binderfs: I have no idea what this does; binderfs_rename() should
probably error out on RENAME_EXCHANGE for now, or an explicit ack from
the maintainers.

Bpffs is your baby...

Thanks,
Miklos
Daniel Borkmann Nov. 2, 2021, 10:11 a.m. UTC | #2
On 11/2/21 10:25 AM, Miklos Szeredi wrote:
> On Thu, 28 Oct 2021 at 11:48, Lorenz Bauer <lmb@cloudflare.com> wrote:
>>
>> Allow atomic exchange via RENAME_EXCHANGE when using simple_rename.
>> This affects binderfs, ramfs, hubetlbfs and bpffs.
> 
> Ramfs and hugetlbfs are generic enough; those seem safe.
> 
> Binderfs: I have no idea what this does; binderfs_rename() should
> probably error out on RENAME_EXCHANGE for now, or an explicit ack from
> the maintainers.

Thanks for the review, Miklos! Adding Christian to Cc wrt binderfs ... full context
for all patches: https://lore.kernel.org/bpf/20211028094724.59043-1-lmb@cloudflare.com/

> Bpffs is your baby...
> 
> Thanks,
> Miklos
>
Christian Brauner Nov. 2, 2021, 11:36 a.m. UTC | #3
On Tue, Nov 02, 2021 at 11:11:02AM +0100, Daniel Borkmann wrote:
> On 11/2/21 10:25 AM, Miklos Szeredi wrote:
> > On Thu, 28 Oct 2021 at 11:48, Lorenz Bauer <lmb@cloudflare.com> wrote:
> > > 
> > > Allow atomic exchange via RENAME_EXCHANGE when using simple_rename.
> > > This affects binderfs, ramfs, hubetlbfs and bpffs.
> > 
> > Ramfs and hugetlbfs are generic enough; those seem safe.
> > 
> > Binderfs: I have no idea what this does; binderfs_rename() should

Fwiw, allows dynamic creation and removal of Android binder ipc
devices. Each mount is a separate instance and it's mountable inside
unprivileged containers. Since Android 12 default how binder devices are
managed. Also makes it possibe to run Android in unprivileged
containers.

> > probably error out on RENAME_EXCHANGE for now, or an explicit ack from
> > the maintainers.
> 
> Thanks for the review, Miklos! Adding Christian to Cc wrt binderfs ... full context
> for all patches: https://lore.kernel.org/bpf/20211028094724.59043-1-lmb@cloudflare.com/

Yep, I saw that. Seems good.

> probably error out on RENAME_EXCHANGE for now, or an explicit ack from
> the maintainers.

I don't think there is any issue in allowing binderfs to support this.
Binderfs files are always device nodes. Allowing them to be atomically
renamed shouldn't be a problem. So:

Acked-by: Christian Brauner <christian.brauner@ubuntu.com>

Christian
diff mbox series

Patch

diff --git a/fs/libfs.c b/fs/libfs.c
index 1cf144dc9ed2..ba7438ab9371 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -479,9 +479,12 @@  int simple_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
 	struct inode *inode = d_inode(old_dentry);
 	int they_are_dirs = d_is_dir(old_dentry);
 
-	if (flags & ~RENAME_NOREPLACE)
+	if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE))
 		return -EINVAL;
 
+	if (flags & RENAME_EXCHANGE)
+		return simple_rename_exchange(old_dir, old_dentry, new_dir, new_dentry);
+
 	if (!simple_empty(new_dentry))
 		return -ENOTEMPTY;