Skip to content

Commit 9d223fa

Browse files
committed
Internal change.
PiperOrigin-RevId: 927384056
1 parent da03d3a commit 9d223fa

9 files changed

Lines changed: 94 additions & 3 deletions

File tree

examples/seccheck/server.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ std::vector<Callback> dispatchers = {
125125
unpackSyscall<::gvisor::syscall::InotifyRmWatch>,
126126
unpackSyscall<::gvisor::syscall::SocketPair>,
127127
unpackSyscall<::gvisor::syscall::Write>,
128+
unpackSyscall<::gvisor::syscall::Poll>,
128129
};
129130

130131
void unpack(absl::string_view buf) {

pkg/sentry/seccheck/metadata_amd64.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func archInit() {
3939
Name: "fd_path",
4040
},
4141
})
42+
addSyscallPoint(7, "poll", nil)
4243
addSyscallPoint(17, "pread64", []FieldDesc{
4344
{
4445
ID: FieldSyscallPath,
@@ -181,6 +182,7 @@ func archInit() {
181182
Name: "fd_path",
182183
},
183184
})
185+
addSyscallPoint(271, "ppoll", nil)
184186
addSyscallPoint(290, "eventfd2", nil)
185187
addSyscallPoint(292, "dup3", []FieldDesc{
186188
{

pkg/sentry/seccheck/metadata_arm64.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ func archInit() {
122122
Name: "fd_path",
123123
},
124124
})
125+
addSyscallPoint(73, "ppoll", nil)
125126
addSyscallPoint(74, "signalfd4", []FieldDesc{
126127
{
127128
ID: FieldSyscallPath,

pkg/sentry/seccheck/points/common.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,5 +134,6 @@ enum MessageType {
134134
MESSAGE_SYSCALL_INOTIFY_RM_WATCH = 32;
135135
MESSAGE_SYSCALL_SOCKETPAIR = 33;
136136
MESSAGE_SYSCALL_WRITE = 34;
137+
MESSAGE_SYSCALL_POLL = 35;
137138
}
138139
// LINT.ThenChange(../../../../examples/seccheck/server.cc)

pkg/sentry/seccheck/points/syscall.proto

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,3 +311,11 @@ message SocketPair {
311311
int32 socket1 = 7;
312312
int32 socket2 = 8;
313313
}
314+
315+
message Poll {
316+
gvisor.common.ContextData context_data = 1;
317+
Exit exit = 2;
318+
uint64 sysno = 3;
319+
repeated int64 fds = 4;
320+
int64 timeout_ms = 5;
321+
}

pkg/sentry/syscalls/linux/linux64.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ var AMD64 = &kernel.SyscallTable{
4949
4: syscalls.Supported("stat", Stat),
5050
5: syscalls.Supported("fstat", Fstat),
5151
6: syscalls.Supported("lstat", Lstat),
52-
7: syscalls.Supported("poll", Poll),
52+
7: syscalls.SupportedPoint("poll", Poll, PointPoll),
5353
8: syscalls.Supported("lseek", Lseek),
5454
9: syscalls.Supported("mmap", Mmap),
5555
10: syscalls.Supported("mprotect", Mprotect),
@@ -313,7 +313,7 @@ var AMD64 = &kernel.SyscallTable{
313313
268: syscalls.Supported("fchmodat", Fchmodat),
314314
269: syscalls.Supported("faccessat", Faccessat),
315315
270: syscalls.Supported("pselect6", Pselect6),
316-
271: syscalls.Supported("ppoll", Ppoll),
316+
271: syscalls.SupportedPoint("ppoll", Ppoll, PointPpoll),
317317
272: syscalls.PartiallySupported("unshare", Unshare, "Time, cgroup namespaces not supported.", nil),
318318
273: syscalls.Supported("set_robust_list", SetRobustList),
319319
274: syscalls.Supported("get_robust_list", GetRobustList),
@@ -495,7 +495,7 @@ var ARM64 = &kernel.SyscallTable{
495495
70: syscalls.SupportedPoint("pwritev", Pwritev, PointPwritev),
496496
71: syscalls.Supported("sendfile", Sendfile),
497497
72: syscalls.Supported("pselect6", Pselect6),
498-
73: syscalls.Supported("ppoll", Ppoll),
498+
73: syscalls.SupportedPoint("ppoll", Ppoll, PointPpoll),
499499
74: syscalls.SupportedPoint("signalfd4", Signalfd4, PointSignalfd4),
500500
75: syscalls.ErrorWithEvent("vmsplice", linuxerr.ENOSYS, "", []string{"gvisor.dev/issue/138"}), // TODO(b/29354098)
501501
76: syscalls.Supported("splice", Splice),

pkg/sentry/syscalls/linux/points.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,3 +992,52 @@ func PointSocketpair(t *kernel.Task, fields seccheck.FieldSet, cxtData *pb.Conte
992992
p.Exit = newExitMaybe(info)
993993
return p, pb.MessageType_MESSAGE_SYSCALL_SOCKETPAIR
994994
}
995+
996+
// PointPoll converts poll(2) syscall to proto.
997+
func PointPoll(t *kernel.Task, fields seccheck.FieldSet, cxtData *pb.ContextData, info kernel.SyscallInfo) (proto.Message, pb.MessageType) {
998+
p := &pb.Poll{
999+
ContextData: cxtData,
1000+
Sysno: uint64(info.Sysno),
1001+
TimeoutMs: int64(info.Args[2].Int()),
1002+
}
1003+
1004+
addr := info.Args[0].Pointer()
1005+
nfds := uint(info.Args[1].Uint())
1006+
if pfd, err := CopyInPollFDs(t, addr, nfds); err == nil {
1007+
p.Fds = make([]int64, len(pfd))
1008+
for i, fd := range pfd {
1009+
p.Fds[i] = int64(fd.FD)
1010+
}
1011+
}
1012+
1013+
p.Exit = newExitMaybe(info)
1014+
return p, pb.MessageType_MESSAGE_SYSCALL_POLL
1015+
}
1016+
1017+
// PointPpoll converts ppoll(2) syscall to proto.
1018+
func PointPpoll(t *kernel.Task, fields seccheck.FieldSet, cxtData *pb.ContextData, info kernel.SyscallInfo) (proto.Message, pb.MessageType) {
1019+
p := &pb.Poll{
1020+
ContextData: cxtData,
1021+
Sysno: uint64(info.Sysno),
1022+
TimeoutMs: -1,
1023+
}
1024+
1025+
timespecAddr := info.Args[2].Pointer()
1026+
if timeout, err := copyTimespecInToDuration(t, timespecAddr); err == nil {
1027+
if timeout >= 0 {
1028+
p.TimeoutMs = timeout.Milliseconds()
1029+
}
1030+
}
1031+
1032+
addr := info.Args[0].Pointer()
1033+
nfds := uint(info.Args[1].Uint())
1034+
if pfd, err := CopyInPollFDs(t, addr, nfds); err == nil {
1035+
p.Fds = make([]int64, len(pfd))
1036+
for i, fd := range pfd {
1037+
p.Fds[i] = int64(fd.FD)
1038+
}
1039+
}
1040+
1041+
p.Exit = newExitMaybe(info)
1042+
return p, pb.MessageType_MESSAGE_SYSCALL_POLL
1043+
}

test/trace/trace_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ func matchPoints(t *testing.T, msgs []test.Message) map[pb.MessageType]*checkers
133133
pb.MessageType_MESSAGE_SYSCALL_INOTIFY_ADD_WATCH: {checker: checkSyscallInotifyInitAddWatch},
134134
pb.MessageType_MESSAGE_SYSCALL_INOTIFY_RM_WATCH: {checker: checkSyscallInotifyInitRmWatch},
135135
pb.MessageType_MESSAGE_SYSCALL_CLONE: {checker: checkSyscallClone},
136+
pb.MessageType_MESSAGE_SYSCALL_POLL: {checker: checkSyscallPoll},
136137
}
137138
return matchers
138139
}
@@ -881,3 +882,22 @@ func checkSyscallInotifyInitRmWatch(msg test.Message) error {
881882
}
882883
return nil
883884
}
885+
886+
func checkSyscallPoll(msg test.Message) error {
887+
p := pb.Poll{}
888+
if err := proto.Unmarshal(msg.Msg, &p); err != nil {
889+
return err
890+
}
891+
if err := checkContextData(p.ContextData); err != nil {
892+
return err
893+
}
894+
if len(p.Fds) == 0 {
895+
return fmt.Errorf("poll with 0 fds")
896+
}
897+
for _, fd := range p.Fds {
898+
if fd != 0 && fd != 3 {
899+
return fmt.Errorf("unexpected polled fd: want 0 or 3, got %d", fd)
900+
}
901+
}
902+
return nil
903+
}

test/trace/workload/workload.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <bits/types/struct_itimerspec.h>
1616
#include <err.h>
1717
#include <fcntl.h>
18+
#include <poll.h>
1819
#include <sched.h>
1920
#include <stdlib.h>
2021
#include <sys/eventfd.h>
@@ -662,6 +663,13 @@ void runInotifyRmWatch() {
662663
rmdir(pathname);
663664
}
664665

666+
void runPoll() {
667+
struct pollfd pfd;
668+
pfd.fd = 0;
669+
pfd.events = POLLIN;
670+
poll(&pfd, 1, 0);
671+
}
672+
665673
} // namespace testing
666674
} // namespace gvisor
667675

@@ -697,6 +705,7 @@ int main(int argc, char** argv) {
697705
::gvisor::testing::runInotifyInit1();
698706
::gvisor::testing::runInotifyAddWatch();
699707
::gvisor::testing::runInotifyRmWatch();
708+
::gvisor::testing::runPoll();
700709
// signalfd(2), fork(2), and vfork(2) system calls are not supported in arm
701710
// architecture.
702711
#ifdef __x86_64__

0 commit comments

Comments
 (0)