mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
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:
committed by
gVisor bot
parent
76d1ecdba3
commit
28472cc03f
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user