From 806e346491503e0292bcee8bf15d74bbf42e2a10 Mon Sep 17 00:00:00 2001 From: Rahat Mahmood Date: Tue, 4 Dec 2018 13:45:11 -0800 Subject: Fix mempolicy_test on bazel. Bazel runs multiple test cases on the same thread. Some of the test cases rely on the test thread starting with the default memory policy, while other tests modify the test thread's memory policy. This obviously breaks when the test framework doesn't run each test case on a new thread. Also fixing an incompatibility where set_mempolicy(2) was prevented from specifying an empty nodemask, which is allowed for some modes. PiperOrigin-RevId: 224038957 Change-Id: Ibf780766f2706ebc9b129dbc8cf1b85c2a275074 --- pkg/sentry/syscalls/linux/sys_mmap.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'pkg/sentry/syscalls/linux') diff --git a/pkg/sentry/syscalls/linux/sys_mmap.go b/pkg/sentry/syscalls/linux/sys_mmap.go index f8d9c43fd..145f7846c 100644 --- a/pkg/sentry/syscalls/linux/sys_mmap.go +++ b/pkg/sentry/syscalls/linux/sys_mmap.go @@ -308,28 +308,31 @@ func SetMempolicy(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kernel. nodemask := args[1].Pointer() maxnode := args[2].Uint() - if maxnode < 1 { + if nodemask != 0 && maxnode < 1 { return 0, nil, syserror.EINVAL } if modeWithFlags&linux.MPOL_MODE_FLAGS == linux.MPOL_MODE_FLAGS { - // Can't specify multiple modes simultaneously. Must also contain a - // valid mode, which we check below. + // Can't specify multiple modes simultaneously. return 0, nil, syserror.EINVAL } mode := modeWithFlags &^ linux.MPOL_MODE_FLAGS if mode < 0 || mode >= linux.MPOL_MAX { + // Must specify a valid mode. return 0, nil, syserror.EINVAL } var nodemaskVal uint32 - if _, err := t.CopyIn(nodemask, &nodemaskVal); err != nil { - return 0, nil, syserror.EFAULT + // Nodemask may be empty for some policy modes. + if nodemask != 0 && maxnode > 0 { + if _, err := t.CopyIn(nodemask, &nodemaskVal); err != nil { + return 0, nil, syserror.EFAULT + } } - // When setting MPOL_INTERLEAVE, nodemask must not be empty. - if mode == linux.MPOL_INTERLEAVE && nodemaskVal == 0 { + if (mode == linux.MPOL_INTERLEAVE || mode == linux.MPOL_BIND) && nodemaskVal == 0 { + // Mode requires a non-empty nodemask, but got an empty nodemask. return 0, nil, syserror.EINVAL } -- cgit v1.2.3