diff options
author | Fabricio Voznika <fvoznika@google.com> | 2019-03-01 10:55:22 -0800 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2019-03-01 10:57:02 -0800 |
commit | 3dbd4a16f8ae4da967f69fd93870462d1b3554f5 (patch) | |
tree | 8e504070388bf0ac098384b52f7d722362570d79 /pkg/sentry/syscalls/linux | |
parent | 7693b7469f7464a88c1eb62f9479b73d5cee3921 (diff) |
Add semctl(GETPID) syscall
Also added unimplemented notification for semctl(2)
commands.
PiperOrigin-RevId: 236340672
Change-Id: I0795e3bd2e6d41d7936fabb731884df426a42478
Diffstat (limited to 'pkg/sentry/syscalls/linux')
-rw-r--r-- | pkg/sentry/syscalls/linux/sys_sem.go | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/pkg/sentry/syscalls/linux/sys_sem.go b/pkg/sentry/syscalls/linux/sys_sem.go index 6775725ca..86f850ef1 100644 --- a/pkg/sentry/syscalls/linux/sys_sem.go +++ b/pkg/sentry/syscalls/linux/sys_sem.go @@ -71,8 +71,9 @@ func Semop(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kernel.Syscall } creds := auth.CredentialsFromContext(t) + pid := t.Kernel().GlobalInit().PIDNamespace().IDOfThreadGroup(t.ThreadGroup()) for { - ch, num, err := set.ExecuteOps(t, ops, creds) + ch, num, err := set.ExecuteOps(t, ops, creds, int32(pid)) if ch == nil || err != nil { // We're done (either on success or a failure). return 0, nil, err @@ -123,6 +124,21 @@ func Semctl(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kernel.Syscal perms := fs.FilePermsFromMode(linux.FileMode(s.SemPerm.Mode & 0777)) return 0, nil, ipcSet(t, id, auth.UID(s.SemPerm.UID), auth.GID(s.SemPerm.GID), perms) + case linux.GETPID: + v, err := getPID(t, id, num) + return uintptr(v), nil, err + + case linux.IPC_INFO, + linux.SEM_INFO, + linux.IPC_STAT, + linux.SEM_STAT, + linux.SEM_STAT_ANY, + linux.GETNCNT, + linux.GETZCNT: + + t.Kernel().EmitUnimplementedEvent(t) + fallthrough + default: return 0, nil, syserror.EINVAL } @@ -161,7 +177,8 @@ func setVal(t *kernel.Task, id int32, num int32, val int16) error { return syserror.EINVAL } creds := auth.CredentialsFromContext(t) - return set.SetVal(t, num, val, creds) + pid := t.Kernel().GlobalInit().PIDNamespace().IDOfThreadGroup(t.ThreadGroup()) + return set.SetVal(t, num, val, creds, int32(pid)) } func setValAll(t *kernel.Task, id int32, array usermem.Addr) error { @@ -175,7 +192,8 @@ func setValAll(t *kernel.Task, id int32, array usermem.Addr) error { return err } creds := auth.CredentialsFromContext(t) - return set.SetValAll(t, vals, creds) + pid := t.Kernel().GlobalInit().PIDNamespace().IDOfThreadGroup(t.ThreadGroup()) + return set.SetValAll(t, vals, creds, int32(pid)) } func getVal(t *kernel.Task, id int32, num int32) (int16, error) { @@ -202,3 +220,22 @@ func getValAll(t *kernel.Task, id int32, array usermem.Addr) error { _, err = t.CopyOut(array, vals) return err } + +func getPID(t *kernel.Task, id int32, num int32) (int32, error) { + r := t.IPCNamespace().SemaphoreRegistry() + set := r.FindByID(id) + if set == nil { + return 0, syserror.EINVAL + } + creds := auth.CredentialsFromContext(t) + gpid, err := set.GetPID(num, creds) + if err != nil { + return 0, err + } + // Convert pid from init namespace to the caller's namespace. + tg := t.PIDNamespace().ThreadGroupWithID(kernel.ThreadID(gpid)) + if tg == nil { + return 0, nil + } + return int32(tg.ID()), nil +} |