don't take an unnecessary reference in proc.fdSymlink.Valid()

Reported-by: syzbot+8622a8a08287adc17bc9@syzkaller.appspotmail.com
PiperOrigin-RevId: 510454946
This commit is contained in:
Kevin Krakauer
2023-02-17 09:51:21 -08:00
committed by gVisor bot
parent 76d1ecdba3
commit 28472cc03f
2 changed files with 18 additions and 6 deletions
+7 -6
View File
@@ -43,12 +43,13 @@ func getTaskFD(t *kernel.Task, fd int32) (*vfs.FileDescription, kernel.FDFlags)
}
func taskFDExists(ctx context.Context, fs *filesystem, t *kernel.Task, fd int32) bool {
file, _ := getTaskFD(t, fd)
if file == nil {
return false
}
fs.SafeDecRefFD(ctx, file)
return true
var exists bool
t.WithMuLocked(func(task *kernel.Task) {
if fdt := t.FDTable(); fdt != nil {
exists = fdt.Exists(fd)
}
})
return exists
}
// +stateify savable
+11
View File
@@ -440,6 +440,17 @@ func (f *FDTable) GetFDs(ctx context.Context) []int32 {
return fds
}
// Exists returns whether fd is defined in the table. It is inherently racy.
//
//go:nosplit
func (f *FDTable) Exists(fd int32) bool {
if fd < 0 {
return false
}
file, _, _ := f.get(fd)
return file != nil
}
// Fork returns an independent FDTable, cloning all FDs up to maxFds (non-inclusive).
func (f *FDTable) Fork(ctx context.Context, maxFds int32) *FDTable {
clone := f.k.NewFDTable()