Skip to content

btrfs: Allow unprivileged user to delete subvolumes (kernel >= 4.18)#42203

Merged
thaJeztah merged 1 commit intomoby:masterfrom
AkihiroSuda:btrfs-allow-unprivileged
Apr 5, 2021
Merged

btrfs: Allow unprivileged user to delete subvolumes (kernel >= 4.18)#42203
thaJeztah merged 1 commit intomoby:masterfrom
AkihiroSuda:btrfs-allow-unprivileged

Conversation

@AkihiroSuda
Copy link
Copy Markdown
Member

- What I did

Fix #41762 ([rootless] driver "btrfs" failed to remove root filesystem: Failed to destroy btrfs snapshot /home/<USER>/.local/share/docker/btrfs/subvolumes for <ID>: operation not permitted)

- How I did it

Cherry-pick "drivers: btrfs: Allow unprivileged user to delete subvolumes" from containers/storage
containers/storage@831e32b

In btrfs, subvolume can be deleted by IOC_SNAP_DESTROY ioctl but there
is one catch: unprivileged IOC_SNAP_DESTROY call is restricted by default.

This is because IOC_SNAP_DESTROY only performs permission checks on
the top directory(subvolume) and unprivileged user might delete dirs/files
which cannot be deleted otherwise. This restriction can be relaxed if
user_subvol_rm_allowed mount option is used.

Although the above ioctl had been the only way to delete a subvolume,
btrfs now allows deletion of subvolume just like regular directory
(i.e. rmdir sycall) since kernel 4.18.

So if we fail to cleanup subvolume in subvolDelete(), just fallback to
system.EnsureRmoveall() to try to cleanup subvolumes again.
(Note: quota needs privilege, so if quota is enabled we do not fallback)

This fix will allow non-privileged container works with btrfs backend.

- How to verify it

$ dockerd-rootless.sh --data-root /mnt/btrfs/varlibdocker
$ docker --context=rootless run --rm hello-world

- Description for the changelog

btrfs: Allow unprivileged user to delete subvolumes (kernel >= 4.18)

- A picture of a cute animal (not mandatory but encouraged)
🐧

Fix issue 41762

Cherry-pick "drivers: btrfs: Allow unprivileged user to delete subvolumes" from containers/storage
containers/storage@831e32b

> In btrfs, subvolume can be deleted by IOC_SNAP_DESTROY ioctl but there
> is one catch: unprivileged IOC_SNAP_DESTROY call is restricted by default.
>
> This is because IOC_SNAP_DESTROY only performs permission checks on
> the top directory(subvolume) and unprivileged user might delete dirs/files
> which cannot be deleted otherwise. This restriction can be relaxed if
> user_subvol_rm_allowed mount option is used.
>
> Although the above ioctl had been the only way to delete a subvolume,
> btrfs now allows deletion of subvolume just like regular directory
> (i.e. rmdir sycall) since kernel 4.18.
>
> So if we fail to cleanup subvolume in subvolDelete(), just fallback to
> system.EnsureRmoveall() to try to cleanup subvolumes again.
> (Note: quota needs privilege, so if quota is enabled we do not fallback)
>
> This fix will allow non-privileged container works with btrfs backend.

Signed-off-by: Akihiro Suda <[email protected]>
@AkihiroSuda AkihiroSuda force-pushed the btrfs-allow-unprivileged branch from ee9886c to 62b5194 Compare March 26, 2021 05:31
@AkihiroSuda
Copy link
Copy Markdown
Member Author

@thaJeztah PTAL 🙏

Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

3 participants