Message ID | 20200912110820.597135-15-keescook@chromium.org (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | selftests/seccomp: Refactor change_syscall() | expand |
On Sat, Sep 12, 2020 at 04:08:19AM -0700, Kees Cook wrote: > As the UAPI headers start to appear in distros, we need to avoid > outdated versions of struct clone_args to be able to test modern > features. Additionally pull in the syscall numbers correctly. > > Signed-off-by: Kees Cook <keescook@chromium.org> > --- Hm, with this patch applied I'm getting: gcc -g -I../../../../usr/include/ clone3_set_tid.c /home/brauner/src/git/linux/linux/tools/testing/selftests/kselftest_harness.h /home/brauner/src/git/linux/linux/tools/testing/selftests/kselftest.h -lcap -o /home/brauner/src/git/linux/linux/tools/testing/selftests/clone3/clone3_set_tid In file included from clone3_set_tid.c:24: clone3_selftests.h:37:8: error: redefinition of ‘struct clone_args’ 37 | struct clone_args { | ^~~~~~~~~~ In file included from clone3_set_tid.c:12: /usr/include/linux/sched.h:92:8: note: originally defined here 92 | struct clone_args { | ^~~~~~~~~~ make: *** [../lib.mk:140: /home/brauner/src/git/linux/linux/tools/testing/selftests/clone3/clone3_set_tid] Error 1 One trick to avoid this could be: #ifndef CLONE_ARGS_SIZE_VER0 #define CLONE_ARGS_SIZE_VER0 64 /* sizeof first published struct */ #endif #ifndef CLONE_ARGS_SIZE_VER1 #define CLONE_ARGS_SIZE_VER1 80 /* sizeof second published struct */ #endif #ifndef CLONE_ARGS_SIZE_VER2 #define CLONE_ARGS_SIZE_VER2 88 /* sizeof third published struct */ #endif struct __clone_args { __aligned_u64 flags; __aligned_u64 pidfd; __aligned_u64 child_tid; __aligned_u64 parent_tid; __aligned_u64 exit_signal; __aligned_u64 stack; __aligned_u64 stack_size; __aligned_u64 tls; __aligned_u64 set_tid; __aligned_u64 set_tid_size; __aligned_u64 cgroup; }; static pid_t sys_clone3(struct __clone_args *args, size_t size) { return syscall(__NR_clone3, args, size); } Christian
On Tue, Sep 15, 2020 at 06:25:28PM +0200, Christian Brauner wrote: > On Sat, Sep 12, 2020 at 04:08:19AM -0700, Kees Cook wrote: > > As the UAPI headers start to appear in distros, we need to avoid > > outdated versions of struct clone_args to be able to test modern > > features. Additionally pull in the syscall numbers correctly. > > > > Signed-off-by: Kees Cook <keescook@chromium.org> > > --- > > Hm, with this patch applied I'm getting: > > gcc -g -I../../../../usr/include/ clone3_set_tid.c /home/brauner/src/git/linux/linux/tools/testing/selftests/kselftest_harness.h /home/brauner/src/git/linux/linux/tools/testing/selftests/kselftest.h -lcap -o /home/brauner/src/git/linux/linux/tools/testing/selftests/clone3/clone3_set_tid > In file included from clone3_set_tid.c:24: > clone3_selftests.h:37:8: error: redefinition of ‘struct clone_args’ > 37 | struct clone_args { > | ^~~~~~~~~~ > In file included from clone3_set_tid.c:12: > /usr/include/linux/sched.h:92:8: note: originally defined here > 92 | struct clone_args { > | ^~~~~~~~~~ > make: *** [../lib.mk:140: /home/brauner/src/git/linux/linux/tools/testing/selftests/clone3/clone3_set_tid] Error 1 Hm, weird. > One trick to avoid this could be: > > #ifndef CLONE_ARGS_SIZE_VER0 > #define CLONE_ARGS_SIZE_VER0 64 /* sizeof first published struct */ > #endif > > #ifndef CLONE_ARGS_SIZE_VER1 > #define CLONE_ARGS_SIZE_VER1 80 /* sizeof second published struct */ > #endif > > #ifndef CLONE_ARGS_SIZE_VER2 > #define CLONE_ARGS_SIZE_VER2 88 /* sizeof third published struct */ > #endif > > struct __clone_args { > __aligned_u64 flags; > __aligned_u64 pidfd; > __aligned_u64 child_tid; > __aligned_u64 parent_tid; > __aligned_u64 exit_signal; > __aligned_u64 stack; > __aligned_u64 stack_size; > __aligned_u64 tls; > __aligned_u64 set_tid; > __aligned_u64 set_tid_size; > __aligned_u64 cgroup; > }; > > static pid_t sys_clone3(struct __clone_args *args, size_t size) > { > return syscall(__NR_clone3, args, size); > } Yeah, that has fewer down sides. I'll rework it.
diff --git a/tools/testing/selftests/clone3/clone3_selftests.h b/tools/testing/selftests/clone3/clone3_selftests.h index 91c1a78ddb39..bc0f34e37ae1 100644 --- a/tools/testing/selftests/clone3/clone3_selftests.h +++ b/tools/testing/selftests/clone3/clone3_selftests.h @@ -4,11 +4,19 @@ #define _CLONE3_SELFTESTS_H #define _GNU_SOURCE + +/* Pull in syscall numbers. */ +#include <unistd.h> +#include <sys/syscall.h> + +/* Avoid old OS versions of "struct clone_args". */ +#define clone_args old_clone_args #include <sched.h> #include <linux/sched.h> +#undef clone_args + #include <linux/types.h> #include <stdint.h> -#include <syscall.h> #include <sys/wait.h> #include "../kselftest.h" @@ -25,6 +33,7 @@ #ifndef __NR_clone3 #define __NR_clone3 -1 +#endif struct clone_args { __aligned_u64 flags; __aligned_u64 pidfd; @@ -34,13 +43,16 @@ struct clone_args { __aligned_u64 stack; __aligned_u64 stack_size; __aligned_u64 tls; +#ifndef CLONE_ARGS_SIZE_VER1 #define CLONE_ARGS_SIZE_VER1 80 +#endif __aligned_u64 set_tid; __aligned_u64 set_tid_size; +#ifndef CLONE_ARGS_SIZE_VER2 #define CLONE_ARGS_SIZE_VER2 88 +#endif __aligned_u64 cgroup; }; -#endif /* __NR_clone3 */ static pid_t sys_clone3(struct clone_args *args, size_t size) {
As the UAPI headers start to appear in distros, we need to avoid outdated versions of struct clone_args to be able to test modern features. Additionally pull in the syscall numbers correctly. Signed-off-by: Kees Cook <keescook@chromium.org> --- I needed to fix this to get MIPS to build the seccomp selftests. --- .../testing/selftests/clone3/clone3_selftests.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)