Skip to content

Commit 5f84a10

Browse files
fdmananabrauner
authored andcommitted
btrfs: use may_delete_dentry() in btrfs_ioctl_snap_destroy()
There is no longer the need to use btrfs_may_delete(), which was a copy of the VFS private function may_delete(), since now that functionality is exported by the VFS as a function named may_delete_dentry(). In fact our local copy of may_delete() lacks an update that happened to that function which is point number 7 in that function's comment: "7. If the victim has an unknown uid or gid we can't change the inode." which corresponds to this code: /* Inode writeback is not safe when the uid or gid are invalid. */ if (!vfsuid_valid(i_uid_into_vfsuid(idmap, inode)) || !vfsgid_valid(i_gid_into_vfsgid(idmap, inode))) return -EOVERFLOW; As long as we keep a separate copy, duplicating code, we are also prone to updates to the VFS being missed in our local copy. So change btrfs_ioctl_snap_destroy() to use the VFS function and remove btrfs_may_delete(). Signed-off-by: Filipe Manana <fdmanana@suse.com> Link: https://patch.msgid.link/46b13dc5c957deb72a7f085916757a20878a8e73.1768307858.git.fdmanana@suse.com Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 26aab3a commit 5f84a10

1 file changed

Lines changed: 1 addition & 57 deletions

File tree

fs/btrfs/ioctl.c

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -815,62 +815,6 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir,
815815
return ret;
816816
}
817817

818-
/* copy of may_delete in fs/namei.c()
819-
* Check whether we can remove a link victim from directory dir, check
820-
* whether the type of victim is right.
821-
* 1. We can't do it if dir is read-only (done in permission())
822-
* 2. We should have write and exec permissions on dir
823-
* 3. We can't remove anything from append-only dir
824-
* 4. We can't do anything with immutable dir (done in permission())
825-
* 5. If the sticky bit on dir is set we should either
826-
* a. be owner of dir, or
827-
* b. be owner of victim, or
828-
* c. have CAP_FOWNER capability
829-
* 6. If the victim is append-only or immutable we can't do anything with
830-
* links pointing to it.
831-
* 7. If we were asked to remove a directory and victim isn't one - ENOTDIR.
832-
* 8. If we were asked to remove a non-directory and victim isn't one - EISDIR.
833-
* 9. We can't remove a root or mountpoint.
834-
* 10. We don't allow removal of NFS sillyrenamed files; it's handled by
835-
* nfs_async_unlink().
836-
*/
837-
838-
static int btrfs_may_delete(struct mnt_idmap *idmap,
839-
struct inode *dir, struct dentry *victim, int isdir)
840-
{
841-
int ret;
842-
843-
if (d_really_is_negative(victim))
844-
return -ENOENT;
845-
846-
/* The @victim is not inside @dir. */
847-
if (d_inode(victim->d_parent) != dir)
848-
return -EINVAL;
849-
audit_inode_child(dir, victim, AUDIT_TYPE_CHILD_DELETE);
850-
851-
ret = inode_permission(idmap, dir, MAY_WRITE | MAY_EXEC);
852-
if (ret)
853-
return ret;
854-
if (IS_APPEND(dir))
855-
return -EPERM;
856-
if (check_sticky(idmap, dir, d_inode(victim)) ||
857-
IS_APPEND(d_inode(victim)) || IS_IMMUTABLE(d_inode(victim)) ||
858-
IS_SWAPFILE(d_inode(victim)))
859-
return -EPERM;
860-
if (isdir) {
861-
if (!d_is_dir(victim))
862-
return -ENOTDIR;
863-
if (IS_ROOT(victim))
864-
return -EBUSY;
865-
} else if (d_is_dir(victim))
866-
return -EISDIR;
867-
if (IS_DEADDIR(dir))
868-
return -ENOENT;
869-
if (victim->d_flags & DCACHE_NFSFS_RENAMED)
870-
return -EBUSY;
871-
return 0;
872-
}
873-
874818
/* copy of may_create in fs/namei.c() */
875819
static inline int btrfs_may_create(struct mnt_idmap *idmap,
876820
struct inode *dir, const struct dentry *child)
@@ -2420,7 +2364,7 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
24202364
}
24212365

24222366
/* check if subvolume may be deleted by a user */
2423-
ret = btrfs_may_delete(idmap, dir, dentry, 1);
2367+
ret = may_delete_dentry(idmap, dir, dentry, true);
24242368
if (ret)
24252369
goto out_end_removing;
24262370

0 commit comments

Comments
 (0)