diff options
author | Michael Pratt <mpratt@google.com> | 2019-04-18 15:22:47 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2019-04-18 15:24:07 -0700 |
commit | c931c8e0829914718a729e20d7db0c2bf4e73f0b (patch) | |
tree | b1de685150e312d7d4fb0ba51077e2e47569560c /pkg/sentry/syscalls/linux | |
parent | ce64d9ebf03b1efac3e8c2b9ddafb02aafed9f33 (diff) |
Format struct pollfd in poll(2)/ppoll(2)
I0410 15:40:38.854295 3776 x:0] [ 1] poll_test E poll(0x2b00bfb5c020 [{FD: 0x3 anon_inode:[eventfd], Events: POLLOUT, REvents: ...}], 0x1, 0x1)
I0410 15:40:38.854348 3776 x:0] [ 1] poll_test X poll(0x2b00bfb5c020 [{FD: 0x3 anon_inode:[eventfd], Events: POLLOUT|POLLERR|POLLHUP, REvents: POLLOUT}], 0x1, 0x1) = 0x1 (10.765?s)
PiperOrigin-RevId: 244269879
Change-Id: If07ba54a486fdeaaedfc0123769b78d1da862307
Diffstat (limited to 'pkg/sentry/syscalls/linux')
-rw-r--r-- | pkg/sentry/syscalls/linux/sys_poll.go | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/pkg/sentry/syscalls/linux/sys_poll.go b/pkg/sentry/syscalls/linux/sys_poll.go index 23fcb907f..17b6768e5 100644 --- a/pkg/sentry/syscalls/linux/sys_poll.go +++ b/pkg/sentry/syscalls/linux/sys_poll.go @@ -155,18 +155,28 @@ func pollBlock(t *kernel.Task, pfd []linux.PollFD, timeout time.Duration) (time. return timeout, n, nil } -func doPoll(t *kernel.Task, pfdAddr usermem.Addr, nfds uint, timeout time.Duration) (time.Duration, uintptr, error) { +// CopyInPollFDs copies an array of struct pollfd unless nfds exceeds the max. +func CopyInPollFDs(t *kernel.Task, addr usermem.Addr, nfds uint) ([]linux.PollFD, error) { if uint64(nfds) > t.ThreadGroup().Limits().GetCapped(limits.NumberOfFiles, fileCap) { - return timeout, 0, syserror.EINVAL + return nil, syserror.EINVAL } pfd := make([]linux.PollFD, nfds) if nfds > 0 { - if _, err := t.CopyIn(pfdAddr, &pfd); err != nil { - return timeout, 0, err + if _, err := t.CopyIn(addr, &pfd); err != nil { + return nil, err } } + return pfd, nil +} + +func doPoll(t *kernel.Task, addr usermem.Addr, nfds uint, timeout time.Duration) (time.Duration, uintptr, error) { + pfd, err := CopyInPollFDs(t, addr, nfds) + if err != nil { + return timeout, 0, err + } + // Compatibility warning: Linux adds POLLHUP and POLLERR just before // polling, in fs/select.c:do_pollfd(). Since pfd is copied out after // polling, changing event masks here is an application-visible difference. @@ -180,7 +190,7 @@ func doPoll(t *kernel.Task, pfdAddr usermem.Addr, nfds uint, timeout time.Durati // The poll entries are copied out regardless of whether // any are set or not. This aligns with the Linux behavior. if nfds > 0 && err == nil { - if _, err := t.CopyOut(pfdAddr, pfd); err != nil { + if _, err := t.CopyOut(addr, pfd); err != nil { return remainingTimeout, 0, err } } |