Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit the maximum resolve depth to prevent infinite loops #3896

Merged
merged 13 commits into from
Jul 13, 2023
4 changes: 3 additions & 1 deletion .github/scripts/command/sync_minio.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ test_sync_hard_link(){
./mc cat myminio/myjfs/def | grep abcd || (echo "content should be abcd" && exit 1)
}

skip_test_sync_broken_link(){
test_sync_broken_link(){
prepare_test
(./mc rb myminio/myjfs > /dev/null 2>&1 --force || true) && ./mc mb myminio/myjfs
./juicefs format $META_URL myjfs
Expand All @@ -134,6 +134,8 @@ skip_test_sync_broken_link(){
lsof -i :9005 | awk 'NR!=1 {print $2}' | xargs -r kill -9
MINIO_ROOT_USER=minioadmin MINIO_ROOT_PASSWORD=minioadmin ./juicefs gateway $META_URL localhost:9005 &
./mc alias set juicegw http://localhost:9005 minioadmin minioadmin --api S3v4
./juicefs sync minio://minioadmin:minioadmin@localhost:9005/myjfs/ myjfs/ && exit 1 || true
rm -rf /jfs/hello
./juicefs sync minio://minioadmin:minioadmin@localhost:9005/myjfs/ myjfs/
}

Expand Down
9 changes: 8 additions & 1 deletion pkg/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,10 @@ func (fs *FileSystem) lookup(ctx meta.Context, parent Ino, name string, inode *I
}

func (fs *FileSystem) resolve(ctx meta.Context, p string, followLastSymlink bool) (fi *FileStat, err syscall.Errno) {
return fs.doResolve(ctx, p, followLastSymlink, 0)
}

func (fs *FileSystem) doResolve(ctx meta.Context, p string, followLastSymlink bool, depth int) (fi *FileStat, err syscall.Errno) {
var inode Ino
var attr = &Attr{}

Expand Down Expand Up @@ -736,6 +740,9 @@ func (fs *FileSystem) resolve(ctx meta.Context, p string, followLastSymlink bool
}
fi = AttrToFileInfo(inode, attr)
if (!resolved || followLastSymlink) && fi.IsSymlink() {
if depth > 100 {
return nil, syscall.ELOOP
}
var buf []byte
err = fs.m.ReadLink(ctx, inode, &buf)
if err != 0 {
Expand All @@ -746,7 +753,7 @@ func (fs *FileSystem) resolve(ctx meta.Context, p string, followLastSymlink bool
return &FileStat{name: target}, syscall.ENOTSUP
}
target = path.Join(strings.Join(ss[:i], "/"), target)
fi, err = fs.resolve(ctx, target, followLastSymlink)
fi, err = fs.doResolve(ctx, target, followLastSymlink, depth+1)
if err != 0 {
return
}
Expand Down