Skip to content

Commit 62b5194

Browse files
committed
btrfs: Allow unprivileged user to delete subvolumes (kernel >= 4.18)
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 <akihiro.suda.cz@hco.ntt.co.jp>
1 parent db2759d commit 62b5194

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

daemon/graphdriver/btrfs/btrfs.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,14 @@ func (d *Driver) Remove(id string) error {
633633
d.updateQuotaStatus()
634634

635635
if err := subvolDelete(d.subvolumesDir(), id, d.quotaEnabled); err != nil {
636-
return err
636+
if d.quotaEnabled {
637+
return err
638+
}
639+
// If quota is not enabled, fallback to rmdir syscall to delete subvolumes.
640+
// This would allow unprivileged user to delete their owned subvolumes
641+
// in kernel >= 4.18 without user_subvol_rm_allowed mount option.
642+
//
643+
// From https://github.com/containers/storage/pull/508/commits/831e32b6bdcb530acc4c1cb9059d3c6dba14208c
637644
}
638645
if err := system.EnsureRemoveAll(dir); err != nil {
639646
return err

0 commit comments

Comments
 (0)