rmlint icon indicating copy to clipboard operation
rmlint copied to clipboard

Permission denied for bind mounts inside XFS filesystems

Open sbraz opened this issue 2 years ago • 1 comments

Hi, I recently noticed that there are permission errors for mount points outside of the folders on which I run rmlint. It only seems to happen inside XFS filesystems.

I believe the problem happens somewhere around here: https://github.com/sahib/rmlint/blob/427791ca7c9ffa66b2c666b6b01874c5e165fae6/lib/utilities.c#L618

To reproduce:

# Inside an XFS filesystem
cd /mnt/xfs
mkdir source target
chmod 700 source
mount --bind source target

# In a different folder
cd /tmp/empty
rmlint

This will output: /mnt/xfs/target: Permission denied. Strace shows openat(AT_FDCWD, "/mnt/xfs/target", O_RDONLY) = -1 EACCES (Permission denied).

Does rmlint really need to enumerate each mount point? The error is also present when -x is used.

sbraz avatar Sep 06 '21 11:09 sbraz

This ugly line is to blame for that error message: https://github.com/sahib/rmlint/blob/854af40f87b366837ad3851243c06fbfb634b153/lib/utilities.c#L591 Redirecting stderr to null would be the quick fix. rm_mounts_can_reflink is useful to avoid attempting reflinks on filesystems that obviously can't make them, especially when an rmlint run includes more than one fs type. Enumerating them eagerly is the easiest way to do that, but the way it works now isn't perfect. For instance, since Linux 5.5 you can do server-side copy on NFS filesystems, which means cp --reflink will create a reflink if the backing filesystem supports it. The only reason rmlint --dedupe does not work on NFS yet is that it expects FS_IOC_FIEMAP to be available.

cebtenzzre avatar Aug 12 '22 02:08 cebtenzzre