mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Replace TaskFromContext(ctx).Kernel() with KernelFromContext(ctx)
Panic seen at some code path like control.ExecAsync where ctx does not have a Task. Reported-by: syzbot+55ce727161cf94a7b7d6@syzkaller.appspotmail.com PiperOrigin-RevId: 355960596
This commit is contained in:
@@ -80,8 +80,7 @@ func newVFS2Socket(t *kernel.Task, family int, stype linux.SockType, protocol in
|
||||
|
||||
// Release implements vfs.FileDescriptionImpl.Release.
|
||||
func (s *socketVFS2) Release(ctx context.Context) {
|
||||
t := kernel.TaskFromContext(ctx)
|
||||
t.Kernel().DeleteSocketVFS2(&s.vfsfd)
|
||||
kernel.KernelFromContext(ctx).DeleteSocketVFS2(&s.vfsfd)
|
||||
s.socketOpsCommon.Release(ctx)
|
||||
}
|
||||
|
||||
|
||||
@@ -79,8 +79,7 @@ func NewVFS2(t *kernel.Task, family int, skType linux.SockType, protocol int, qu
|
||||
|
||||
// Release implements vfs.FileDescriptionImpl.Release.
|
||||
func (s *SocketVFS2) Release(ctx context.Context) {
|
||||
t := kernel.TaskFromContext(ctx)
|
||||
t.Kernel().DeleteSocketVFS2(&s.vfsfd)
|
||||
kernel.KernelFromContext(ctx).DeleteSocketVFS2(&s.vfsfd)
|
||||
s.socketOpsCommon.Release(ctx)
|
||||
}
|
||||
|
||||
|
||||
@@ -95,8 +95,7 @@ func NewFileDescription(ep transport.Endpoint, stype linux.SockType, flags uint3
|
||||
// DecRef implements RefCounter.DecRef.
|
||||
func (s *SocketVFS2) DecRef(ctx context.Context) {
|
||||
s.socketVFS2Refs.DecRef(func() {
|
||||
t := kernel.TaskFromContext(ctx)
|
||||
t.Kernel().DeleteSocketVFS2(&s.vfsfd)
|
||||
kernel.KernelFromContext(ctx).DeleteSocketVFS2(&s.vfsfd)
|
||||
s.ep.Close(ctx)
|
||||
if s.abstractNamespace != nil {
|
||||
s.abstractNamespace.Remove(s.abstractName, s)
|
||||
|
||||
@@ -777,6 +777,28 @@ func TestExec(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Test for exec failure with an non-existent file.
|
||||
t.Run("nonexist", func(t *testing.T) {
|
||||
// b/179114837 found by Syzkaller that causes nil pointer panic when
|
||||
// trying to dec-ref an unix socket FD.
|
||||
fds, err := syscall.Socketpair(syscall.AF_UNIX, syscall.SOCK_STREAM, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer syscall.Close(fds[0])
|
||||
|
||||
_, err = cont.executeSync(&control.ExecArgs{
|
||||
Argv: []string{"/nonexist"},
|
||||
FilePayload: urpc.FilePayload{
|
||||
Files: []*os.File{os.NewFile(uintptr(fds[1]), "sock")},
|
||||
},
|
||||
})
|
||||
want := "failed to load /nonexist"
|
||||
if err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("executeSync: want err containing %q; got err = %q", want, err)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user