From 4fa85fb6f7a375cec7201e840d65b261cca41584 Mon Sep 17 00:00:00 2001 From: Ayush Ranjan Date: Mon, 30 May 2022 19:42:28 -0700 Subject: [PATCH] Handle Walk failure while attaching gofer client to attach path. The Walk RPC can fail partially if an intermediate path component does not exist or is a symlink. In such a scenario, the RPC itself is successful but lisafs.WalkStatus is not WalkSuccess. It is possible that in such scenarios, 0 inodes are returned. Handle this in the gofer client code. PiperOrigin-RevId: 451945633 --- pkg/sentry/fsimpl/gofer/gofer.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/sentry/fsimpl/gofer/gofer.go b/pkg/sentry/fsimpl/gofer/gofer.go index 55df58017..6717eb308 100644 --- a/pkg/sentry/fsimpl/gofer/gofer.go +++ b/pkg/sentry/fsimpl/gofer/gofer.go @@ -551,8 +551,8 @@ func (fs *filesystem) initClientLisa(ctx context.Context) (lisafs.Inode, error) // Close all intermediate FDs to the attach point. numInodes := len(inodes) - for _, inode := range inodes[:numInodes-1] { - curFD := fs.clientLisa.NewFD(inode.ControlFD) + for i := 0; i < numInodes-1; i++ { + curFD := fs.clientLisa.NewFD(inodes[i].ControlFD) curFD.Close(ctx, false /* flush */) } @@ -560,8 +560,10 @@ func (fs *filesystem) initClientLisa(ctx context.Context) (lisafs.Inode, error) case lisafs.WalkSuccess: return inodes[numInodes-1], nil default: - last := fs.clientLisa.NewFD(inodes[numInodes-1].ControlFD) - last.Close(ctx, false /* flush */) + if numInodes > 0 { + last := fs.clientLisa.NewFD(inodes[numInodes-1].ControlFD) + last.Close(ctx, false /* flush */) + } log.Warningf("initClientLisa failed because walk to attach point %q failed: lisafs.WalkStatus = %v", fs.opts.aname, status) return lisafs.Inode{}, unix.ENOENT }