Fix usages of mountinfo.PrefixFilter
				
					
				
			It says: The prefix path **must be absolute, have all symlinks resolved, and cleaned**. But those requirements are violated in lots of places. What happens when it is given a non-canonicalized path is that `mountinfo.GetMounts` will not find mounts. The trivial case is: ``` $ mkdir a && ln -s a b && mkdir b/c b/d && mount --bind b/c b/d && cat /proc/mounts | grep -- '[ab]/d' /dev/sdd3 /home/user/a/d ext4 rw,noatime,discard 0 0 ``` We asked to bind-mount b/c to b/d, but ended up with mount in a/d. So, mount table always contains canonicalized mount points, and it is an error to look for non-canonicalized paths in it. Signed-off-by: Marat Radchenko <marat@slonopotamus.org>
This commit is contained in:
		@@ -20,18 +20,15 @@ package mount
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
 | 
			
		||||
	"github.com/moby/sys/mountinfo"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// Lookup returns the mount info corresponds to the path.
 | 
			
		||||
func Lookup(dir string) (Info, error) {
 | 
			
		||||
	dir = filepath.Clean(dir)
 | 
			
		||||
 | 
			
		||||
	resolvedDir, err := filepath.EvalSymlinks(dir)
 | 
			
		||||
	resolvedDir, err := CanonicalizePath(dir)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return Info{}, fmt.Errorf("failed to resolve symlink for %q: %w", dir, err)
 | 
			
		||||
		return Info{}, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	m, err := mountinfo.GetMounts(mountinfo.ParentsFilter(resolvedDir))
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user