diff options
author | gVisor bot <gvisor-bot@google.com> | 2020-04-04 01:39:59 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-04-04 01:39:59 +0000 |
commit | 078753e0fe85dbcc047aaa5607a2bbc209491672 (patch) | |
tree | 14790716c79a7318214f1dc9293b6158a47851c3 /pkg/sentry | |
parent | 818a047ab6deabe5a75a5452cdb950cc0e22d722 (diff) | |
parent | fc99a7ebf0c24b6f7b3cfd6351436373ed54548b (diff) |
Merge release-20200323.0-69-gfc99a7e (automated)
Diffstat (limited to 'pkg/sentry')
-rwxr-xr-x | pkg/sentry/fs/dirent_list.go | 13 | ||||
-rwxr-xr-x | pkg/sentry/fs/event_list.go | 13 | ||||
-rwxr-xr-x | pkg/sentry/fsimpl/kernfs/slot_list.go | 13 | ||||
-rwxr-xr-x | pkg/sentry/kernel/epoll/epoll_list.go | 13 | ||||
-rwxr-xr-x | pkg/sentry/kernel/futex/waiter_list.go | 13 | ||||
-rw-r--r-- | pkg/sentry/kernel/kernel.go | 22 | ||||
-rwxr-xr-x | pkg/sentry/kernel/pending_signals_list.go | 13 | ||||
-rwxr-xr-x | pkg/sentry/kernel/process_group_list.go | 13 | ||||
-rwxr-xr-x | pkg/sentry/kernel/semaphore/waiter_list.go | 13 | ||||
-rwxr-xr-x | pkg/sentry/kernel/session_list.go | 13 | ||||
-rwxr-xr-x | pkg/sentry/kernel/socket_list.go | 13 | ||||
-rwxr-xr-x | pkg/sentry/kernel/task_list.go | 13 | ||||
-rwxr-xr-x | pkg/sentry/mm/io_list.go | 13 | ||||
-rwxr-xr-x | pkg/sentry/socket/unix/transport/transport_message_list.go | 13 | ||||
-rwxr-xr-x | pkg/sentry/vfs/epoll_interest_list.go | 13 |
15 files changed, 156 insertions, 48 deletions
diff --git a/pkg/sentry/fs/dirent_list.go b/pkg/sentry/fs/dirent_list.go index acdce100c..ecbbd7883 100755 --- a/pkg/sentry/fs/dirent_list.go +++ b/pkg/sentry/fs/dirent_list.go @@ -52,12 +52,21 @@ func (l *direntList) Back() *Dirent { return l.tail } +// Len returns the number of elements in the list. +// +// NOTE: This is an O(n) operation. +func (l *direntList) Len() (count int) { + for e := l.Front(); e != nil; e = e.Next() { + count++ + } + return count +} + // PushFront inserts the element e at the front of list l. func (l *direntList) PushFront(e *Dirent) { linker := direntElementMapper{}.linkerFor(e) linker.SetNext(l.head) linker.SetPrev(nil) - if l.head != nil { direntElementMapper{}.linkerFor(l.head).SetPrev(e) } else { @@ -72,7 +81,6 @@ func (l *direntList) PushBack(e *Dirent) { linker := direntElementMapper{}.linkerFor(e) linker.SetNext(nil) linker.SetPrev(l.tail) - if l.tail != nil { direntElementMapper{}.linkerFor(l.tail).SetNext(e) } else { @@ -93,7 +101,6 @@ func (l *direntList) PushBackList(m *direntList) { l.tail = m.tail } - m.head = nil m.tail = nil } diff --git a/pkg/sentry/fs/event_list.go b/pkg/sentry/fs/event_list.go index 0274f41a2..167fdf906 100755 --- a/pkg/sentry/fs/event_list.go +++ b/pkg/sentry/fs/event_list.go @@ -52,12 +52,21 @@ func (l *eventList) Back() *Event { return l.tail } +// Len returns the number of elements in the list. +// +// NOTE: This is an O(n) operation. +func (l *eventList) Len() (count int) { + for e := l.Front(); e != nil; e = e.Next() { + count++ + } + return count +} + // PushFront inserts the element e at the front of list l. func (l *eventList) PushFront(e *Event) { linker := eventElementMapper{}.linkerFor(e) linker.SetNext(l.head) linker.SetPrev(nil) - if l.head != nil { eventElementMapper{}.linkerFor(l.head).SetPrev(e) } else { @@ -72,7 +81,6 @@ func (l *eventList) PushBack(e *Event) { linker := eventElementMapper{}.linkerFor(e) linker.SetNext(nil) linker.SetPrev(l.tail) - if l.tail != nil { eventElementMapper{}.linkerFor(l.tail).SetNext(e) } else { @@ -93,7 +101,6 @@ func (l *eventList) PushBackList(m *eventList) { l.tail = m.tail } - m.head = nil m.tail = nil } diff --git a/pkg/sentry/fsimpl/kernfs/slot_list.go b/pkg/sentry/fsimpl/kernfs/slot_list.go index 5c8020e11..09c30bca7 100755 --- a/pkg/sentry/fsimpl/kernfs/slot_list.go +++ b/pkg/sentry/fsimpl/kernfs/slot_list.go @@ -52,12 +52,21 @@ func (l *slotList) Back() *slot { return l.tail } +// Len returns the number of elements in the list. +// +// NOTE: This is an O(n) operation. +func (l *slotList) Len() (count int) { + for e := l.Front(); e != nil; e = e.Next() { + count++ + } + return count +} + // PushFront inserts the element e at the front of list l. func (l *slotList) PushFront(e *slot) { linker := slotElementMapper{}.linkerFor(e) linker.SetNext(l.head) linker.SetPrev(nil) - if l.head != nil { slotElementMapper{}.linkerFor(l.head).SetPrev(e) } else { @@ -72,7 +81,6 @@ func (l *slotList) PushBack(e *slot) { linker := slotElementMapper{}.linkerFor(e) linker.SetNext(nil) linker.SetPrev(l.tail) - if l.tail != nil { slotElementMapper{}.linkerFor(l.tail).SetNext(e) } else { @@ -93,7 +101,6 @@ func (l *slotList) PushBackList(m *slotList) { l.tail = m.tail } - m.head = nil m.tail = nil } diff --git a/pkg/sentry/kernel/epoll/epoll_list.go b/pkg/sentry/kernel/epoll/epoll_list.go index 37f757fa8..a018f7b5c 100755 --- a/pkg/sentry/kernel/epoll/epoll_list.go +++ b/pkg/sentry/kernel/epoll/epoll_list.go @@ -52,12 +52,21 @@ func (l *pollEntryList) Back() *pollEntry { return l.tail } +// Len returns the number of elements in the list. +// +// NOTE: This is an O(n) operation. +func (l *pollEntryList) Len() (count int) { + for e := l.Front(); e != nil; e = e.Next() { + count++ + } + return count +} + // PushFront inserts the element e at the front of list l. func (l *pollEntryList) PushFront(e *pollEntry) { linker := pollEntryElementMapper{}.linkerFor(e) linker.SetNext(l.head) linker.SetPrev(nil) - if l.head != nil { pollEntryElementMapper{}.linkerFor(l.head).SetPrev(e) } else { @@ -72,7 +81,6 @@ func (l *pollEntryList) PushBack(e *pollEntry) { linker := pollEntryElementMapper{}.linkerFor(e) linker.SetNext(nil) linker.SetPrev(l.tail) - if l.tail != nil { pollEntryElementMapper{}.linkerFor(l.tail).SetNext(e) } else { @@ -93,7 +101,6 @@ func (l *pollEntryList) PushBackList(m *pollEntryList) { l.tail = m.tail } - m.head = nil m.tail = nil } diff --git a/pkg/sentry/kernel/futex/waiter_list.go b/pkg/sentry/kernel/futex/waiter_list.go index 204eededf..1b7a92b62 100755 --- a/pkg/sentry/kernel/futex/waiter_list.go +++ b/pkg/sentry/kernel/futex/waiter_list.go @@ -52,12 +52,21 @@ func (l *waiterList) Back() *Waiter { return l.tail } +// Len returns the number of elements in the list. +// +// NOTE: This is an O(n) operation. +func (l *waiterList) Len() (count int) { + for e := l.Front(); e != nil; e = e.Next() { + count++ + } + return count +} + // PushFront inserts the element e at the front of list l. func (l *waiterList) PushFront(e *Waiter) { linker := waiterElementMapper{}.linkerFor(e) linker.SetNext(l.head) linker.SetPrev(nil) - if l.head != nil { waiterElementMapper{}.linkerFor(l.head).SetPrev(e) } else { @@ -72,7 +81,6 @@ func (l *waiterList) PushBack(e *Waiter) { linker := waiterElementMapper{}.linkerFor(e) linker.SetNext(nil) linker.SetPrev(l.tail) - if l.tail != nil { waiterElementMapper{}.linkerFor(l.tail).SetNext(e) } else { @@ -93,7 +101,6 @@ func (l *waiterList) PushBackList(m *waiterList) { l.tail = m.tail } - m.head = nil m.tail = nil } diff --git a/pkg/sentry/kernel/kernel.go b/pkg/sentry/kernel/kernel.go index 0a448b57c..2e6f42b92 100644 --- a/pkg/sentry/kernel/kernel.go +++ b/pkg/sentry/kernel/kernel.go @@ -564,15 +564,25 @@ func (ts *TaskSet) unregisterEpollWaiters() { ts.mu.RLock() defer ts.mu.RUnlock() + + // Tasks that belong to the same process could potentially point to the + // same FDTable. So we retain a map of processed ones to avoid + // processing the same FDTable multiple times. + processed := make(map[*FDTable]struct{}) for t := range ts.Root.tids { // We can skip locking Task.mu here since the kernel is paused. - if t.fdTable != nil { - t.fdTable.forEach(func(_ int32, file *fs.File, _ *vfs.FileDescription, _ FDFlags) { - if e, ok := file.FileOperations.(*epoll.EventPoll); ok { - e.UnregisterEpollWaiters() - } - }) + if t.fdTable == nil { + continue + } + if _, ok := processed[t.fdTable]; ok { + continue } + t.fdTable.forEach(func(_ int32, file *fs.File, _ *vfs.FileDescription, _ FDFlags) { + if e, ok := file.FileOperations.(*epoll.EventPoll); ok { + e.UnregisterEpollWaiters() + } + }) + processed[t.fdTable] = struct{}{} } } diff --git a/pkg/sentry/kernel/pending_signals_list.go b/pkg/sentry/kernel/pending_signals_list.go index 8eb40ac2c..2685c631a 100755 --- a/pkg/sentry/kernel/pending_signals_list.go +++ b/pkg/sentry/kernel/pending_signals_list.go @@ -52,12 +52,21 @@ func (l *pendingSignalList) Back() *pendingSignal { return l.tail } +// Len returns the number of elements in the list. +// +// NOTE: This is an O(n) operation. +func (l *pendingSignalList) Len() (count int) { + for e := l.Front(); e != nil; e = e.Next() { + count++ + } + return count +} + // PushFront inserts the element e at the front of list l. func (l *pendingSignalList) PushFront(e *pendingSignal) { linker := pendingSignalElementMapper{}.linkerFor(e) linker.SetNext(l.head) linker.SetPrev(nil) - if l.head != nil { pendingSignalElementMapper{}.linkerFor(l.head).SetPrev(e) } else { @@ -72,7 +81,6 @@ func (l *pendingSignalList) PushBack(e *pendingSignal) { linker := pendingSignalElementMapper{}.linkerFor(e) linker.SetNext(nil) linker.SetPrev(l.tail) - if l.tail != nil { pendingSignalElementMapper{}.linkerFor(l.tail).SetNext(e) } else { @@ -93,7 +101,6 @@ func (l *pendingSignalList) PushBackList(m *pendingSignalList) { l.tail = m.tail } - m.head = nil m.tail = nil } diff --git a/pkg/sentry/kernel/process_group_list.go b/pkg/sentry/kernel/process_group_list.go index 40c1a13a4..3c5ea8aa7 100755 --- a/pkg/sentry/kernel/process_group_list.go +++ b/pkg/sentry/kernel/process_group_list.go @@ -52,12 +52,21 @@ func (l *processGroupList) Back() *ProcessGroup { return l.tail } +// Len returns the number of elements in the list. +// +// NOTE: This is an O(n) operation. +func (l *processGroupList) Len() (count int) { + for e := l.Front(); e != nil; e = e.Next() { + count++ + } + return count +} + // PushFront inserts the element e at the front of list l. func (l *processGroupList) PushFront(e *ProcessGroup) { linker := processGroupElementMapper{}.linkerFor(e) linker.SetNext(l.head) linker.SetPrev(nil) - if l.head != nil { processGroupElementMapper{}.linkerFor(l.head).SetPrev(e) } else { @@ -72,7 +81,6 @@ func (l *processGroupList) PushBack(e *ProcessGroup) { linker := processGroupElementMapper{}.linkerFor(e) linker.SetNext(nil) linker.SetPrev(l.tail) - if l.tail != nil { processGroupElementMapper{}.linkerFor(l.tail).SetNext(e) } else { @@ -93,7 +101,6 @@ func (l *processGroupList) PushBackList(m *processGroupList) { l.tail = m.tail } - m.head = nil m.tail = nil } diff --git a/pkg/sentry/kernel/semaphore/waiter_list.go b/pkg/sentry/kernel/semaphore/waiter_list.go index 27120afe3..4bfe5ff95 100755 --- a/pkg/sentry/kernel/semaphore/waiter_list.go +++ b/pkg/sentry/kernel/semaphore/waiter_list.go @@ -52,12 +52,21 @@ func (l *waiterList) Back() *waiter { return l.tail } +// Len returns the number of elements in the list. +// +// NOTE: This is an O(n) operation. +func (l *waiterList) Len() (count int) { + for e := l.Front(); e != nil; e = e.Next() { + count++ + } + return count +} + // PushFront inserts the element e at the front of list l. func (l *waiterList) PushFront(e *waiter) { linker := waiterElementMapper{}.linkerFor(e) linker.SetNext(l.head) linker.SetPrev(nil) - if l.head != nil { waiterElementMapper{}.linkerFor(l.head).SetPrev(e) } else { @@ -72,7 +81,6 @@ func (l *waiterList) PushBack(e *waiter) { linker := waiterElementMapper{}.linkerFor(e) linker.SetNext(nil) linker.SetPrev(l.tail) - if l.tail != nil { waiterElementMapper{}.linkerFor(l.tail).SetNext(e) } else { @@ -93,7 +101,6 @@ func (l *waiterList) PushBackList(m *waiterList) { l.tail = m.tail } - m.head = nil m.tail = nil } diff --git a/pkg/sentry/kernel/session_list.go b/pkg/sentry/kernel/session_list.go index 8174f413d..768482ab6 100755 --- a/pkg/sentry/kernel/session_list.go +++ b/pkg/sentry/kernel/session_list.go @@ -52,12 +52,21 @@ func (l *sessionList) Back() *Session { return l.tail } +// Len returns the number of elements in the list. +// +// NOTE: This is an O(n) operation. +func (l *sessionList) Len() (count int) { + for e := l.Front(); e != nil; e = e.Next() { + count++ + } + return count +} + // PushFront inserts the element e at the front of list l. func (l *sessionList) PushFront(e *Session) { linker := sessionElementMapper{}.linkerFor(e) linker.SetNext(l.head) linker.SetPrev(nil) - if l.head != nil { sessionElementMapper{}.linkerFor(l.head).SetPrev(e) } else { @@ -72,7 +81,6 @@ func (l *sessionList) PushBack(e *Session) { linker := sessionElementMapper{}.linkerFor(e) linker.SetNext(nil) linker.SetPrev(l.tail) - if l.tail != nil { sessionElementMapper{}.linkerFor(l.tail).SetNext(e) } else { @@ -93,7 +101,6 @@ func (l *sessionList) PushBackList(m *sessionList) { l.tail = m.tail } - m.head = nil m.tail = nil } diff --git a/pkg/sentry/kernel/socket_list.go b/pkg/sentry/kernel/socket_list.go index ac93e2365..294aa99fe 100755 --- a/pkg/sentry/kernel/socket_list.go +++ b/pkg/sentry/kernel/socket_list.go @@ -52,12 +52,21 @@ func (l *socketList) Back() *SocketEntry { return l.tail } +// Len returns the number of elements in the list. +// +// NOTE: This is an O(n) operation. +func (l *socketList) Len() (count int) { + for e := l.Front(); e != nil; e = e.Next() { + count++ + } + return count +} + // PushFront inserts the element e at the front of list l. func (l *socketList) PushFront(e *SocketEntry) { linker := socketElementMapper{}.linkerFor(e) linker.SetNext(l.head) linker.SetPrev(nil) - if l.head != nil { socketElementMapper{}.linkerFor(l.head).SetPrev(e) } else { @@ -72,7 +81,6 @@ func (l *socketList) PushBack(e *SocketEntry) { linker := socketElementMapper{}.linkerFor(e) linker.SetNext(nil) linker.SetPrev(l.tail) - if l.tail != nil { socketElementMapper{}.linkerFor(l.tail).SetNext(e) } else { @@ -93,7 +101,6 @@ func (l *socketList) PushBackList(m *socketList) { l.tail = m.tail } - m.head = nil m.tail = nil } diff --git a/pkg/sentry/kernel/task_list.go b/pkg/sentry/kernel/task_list.go index 4dfcdbf2c..e7a3a3d20 100755 --- a/pkg/sentry/kernel/task_list.go +++ b/pkg/sentry/kernel/task_list.go @@ -52,12 +52,21 @@ func (l *taskList) Back() *Task { return l.tail } +// Len returns the number of elements in the list. +// +// NOTE: This is an O(n) operation. +func (l *taskList) Len() (count int) { + for e := l.Front(); e != nil; e = e.Next() { + count++ + } + return count +} + // PushFront inserts the element e at the front of list l. func (l *taskList) PushFront(e *Task) { linker := taskElementMapper{}.linkerFor(e) linker.SetNext(l.head) linker.SetPrev(nil) - if l.head != nil { taskElementMapper{}.linkerFor(l.head).SetPrev(e) } else { @@ -72,7 +81,6 @@ func (l *taskList) PushBack(e *Task) { linker := taskElementMapper{}.linkerFor(e) linker.SetNext(nil) linker.SetPrev(l.tail) - if l.tail != nil { taskElementMapper{}.linkerFor(l.tail).SetNext(e) } else { @@ -93,7 +101,6 @@ func (l *taskList) PushBackList(m *taskList) { l.tail = m.tail } - m.head = nil m.tail = nil } diff --git a/pkg/sentry/mm/io_list.go b/pkg/sentry/mm/io_list.go index 287e4305c..ae0f19fc5 100755 --- a/pkg/sentry/mm/io_list.go +++ b/pkg/sentry/mm/io_list.go @@ -52,12 +52,21 @@ func (l *ioList) Back() *ioResult { return l.tail } +// Len returns the number of elements in the list. +// +// NOTE: This is an O(n) operation. +func (l *ioList) Len() (count int) { + for e := l.Front(); e != nil; e = e.Next() { + count++ + } + return count +} + // PushFront inserts the element e at the front of list l. func (l *ioList) PushFront(e *ioResult) { linker := ioElementMapper{}.linkerFor(e) linker.SetNext(l.head) linker.SetPrev(nil) - if l.head != nil { ioElementMapper{}.linkerFor(l.head).SetPrev(e) } else { @@ -72,7 +81,6 @@ func (l *ioList) PushBack(e *ioResult) { linker := ioElementMapper{}.linkerFor(e) linker.SetNext(nil) linker.SetPrev(l.tail) - if l.tail != nil { ioElementMapper{}.linkerFor(l.tail).SetNext(e) } else { @@ -93,7 +101,6 @@ func (l *ioList) PushBackList(m *ioList) { l.tail = m.tail } - m.head = nil m.tail = nil } diff --git a/pkg/sentry/socket/unix/transport/transport_message_list.go b/pkg/sentry/socket/unix/transport/transport_message_list.go index 9edc731b4..568cd5871 100755 --- a/pkg/sentry/socket/unix/transport/transport_message_list.go +++ b/pkg/sentry/socket/unix/transport/transport_message_list.go @@ -52,12 +52,21 @@ func (l *messageList) Back() *message { return l.tail } +// Len returns the number of elements in the list. +// +// NOTE: This is an O(n) operation. +func (l *messageList) Len() (count int) { + for e := l.Front(); e != nil; e = e.Next() { + count++ + } + return count +} + // PushFront inserts the element e at the front of list l. func (l *messageList) PushFront(e *message) { linker := messageElementMapper{}.linkerFor(e) linker.SetNext(l.head) linker.SetPrev(nil) - if l.head != nil { messageElementMapper{}.linkerFor(l.head).SetPrev(e) } else { @@ -72,7 +81,6 @@ func (l *messageList) PushBack(e *message) { linker := messageElementMapper{}.linkerFor(e) linker.SetNext(nil) linker.SetPrev(l.tail) - if l.tail != nil { messageElementMapper{}.linkerFor(l.tail).SetNext(e) } else { @@ -93,7 +101,6 @@ func (l *messageList) PushBackList(m *messageList) { l.tail = m.tail } - m.head = nil m.tail = nil } diff --git a/pkg/sentry/vfs/epoll_interest_list.go b/pkg/sentry/vfs/epoll_interest_list.go index 1bd41f400..67104a9c6 100755 --- a/pkg/sentry/vfs/epoll_interest_list.go +++ b/pkg/sentry/vfs/epoll_interest_list.go @@ -52,12 +52,21 @@ func (l *epollInterestList) Back() *epollInterest { return l.tail } +// Len returns the number of elements in the list. +// +// NOTE: This is an O(n) operation. +func (l *epollInterestList) Len() (count int) { + for e := l.Front(); e != nil; e = e.Next() { + count++ + } + return count +} + // PushFront inserts the element e at the front of list l. func (l *epollInterestList) PushFront(e *epollInterest) { linker := epollInterestElementMapper{}.linkerFor(e) linker.SetNext(l.head) linker.SetPrev(nil) - if l.head != nil { epollInterestElementMapper{}.linkerFor(l.head).SetPrev(e) } else { @@ -72,7 +81,6 @@ func (l *epollInterestList) PushBack(e *epollInterest) { linker := epollInterestElementMapper{}.linkerFor(e) linker.SetNext(nil) linker.SetPrev(l.tail) - if l.tail != nil { epollInterestElementMapper{}.linkerFor(l.tail).SetNext(e) } else { @@ -93,7 +101,6 @@ func (l *epollInterestList) PushBackList(m *epollInterestList) { l.tail = m.tail } - m.head = nil m.tail = nil } |