selftests/seccomp: Fix seccomp failure by adding missing headers
Shuah Khan
maintainerQuoted 22 lines · Sherry Yang
seccomp_bpffailed on tests 47 global.user_notification_filter_empty and 48 global.user_notification_filter_empty_threaded when it's tested on updated kernel but with old kernel headers. Because old kernel headers don't have definition of macro__NR_clone3which is required for these two tests. Since under selftests/, we can install headers once for all tests (the defaultINSTALL_HDR_PATHis usr/include), fix it by adding usr/include to the list of directories to be searched. Use "-isystem" to indicate it's a system directory as the real kernel headers directories are.Signed-off-by Sherry Yang <[email protected]>Tested-by Sherry Yang <[email protected]>--- tools/testing/selftests/seccomp/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/testing/selftests/seccomp/Makefile +0
-0
tools/testing/selftests/seccomp/Makefile line 5
Quoted 6 lines
tools/testing/selftests/seccomp/Makefile +1
-1@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -CFLAGS += -Wl,-no-as-needed -Wall +CFLAGS += -Wl,-no-as-needed -Wall -isystem ../../../../usr/include/ LDFLAGS += -lpthread TEST_GEN_PROGS := seccomp_bpf seccomp_benchmark
Looks good to me. Adding Kees Cook for his review of this change.
thanks,
-- Shuah
Quoted 17 lines · Shuah Khan
Quoted 16 lines · Sherry Yang
seccomp_bpffailed on tests 47 global.user_notification_filter_empty and 48 global.user_notification_filter_empty_threaded when it's tested on updated kernel but with old kernel headers. Because old kernel headers don't have definition of macro__NR_clone3which is required for these two tests. Since under selftests/, we can install headers once for all tests (the defaultINSTALL_HDR_PATHis usr/include), fix it by adding usr/include to the list of directories to be searched. Use "-isystem" to indicate it's a system directory as the real kernel headers directories are.Signed-off-by Sherry Yang <[email protected]>Tested-by Sherry Yang <[email protected]>--- tools/testing/selftests/seccomp/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 8 lines
tools/testing/selftests/seccomp/Makefile line 2
Quoted 8 lines
tools/testing/selftests/seccomp/Makefile +1
-1@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -CFLAGS += -Wl,-no-as-needed -Wall +CFLAGS += -Wl,-no-as-needed -Wall -isystem ../../../../usr/include/
This didn't look right to me. That's outside the build tree, yes?
I thought missing headers had been globally solved already for the selftests? Going looking, though, I think I'm thinking of the KBUILD_OUTPIT work. Hm.
I thought there was a proper "updated kernel headers" dependency that should be used for this?
-Kees
Quoted 9 lines
tools/testing/selftests/seccomp/Makefile line 5
Quoted 4 lines
tools/testing/selftests/seccomp/Makefile +0
-0LDFLAGS += -lpthread TEST_GEN_PROGS := seccomp_bpf seccomp_benchmarkLooks good to me. Adding Kees Cook for his review of this change.
thanks,
-- Shuah
Signature · 1 line
Kees Cook
Quoted 1 line
This didn't look right to me. That's outside the build tree, yes?
It’s inside the build tree. “../../../../usr/include“ may look a little confusing, it’s actually linux/usr/include (linux/ is top directory of the repo we git clone), i.e. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/usr/include?h=v5.17-rc2
The file tools/testing/sefltests/Makefile can install kernel headers in default path “usr/include”. “../../../../usr/include“ is also used in other Makefile of selftests, like https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/testing/selftests/clone3/Makefile?h=v5.17-rc2
Quoted 1 line
I thought there was a proper "updated kernel headers" dependency that should be used for this?
Updating kernel headers could be one solution. Adding “../../../../usr/include“ in the header file search path could build the tests inside the sandbox.
Sherry
Quoted 4 lines · Sherry Yang
Quoted 1 line
This didn't look right to me. That's outside the build tree, yes?
It’s inside the build tree. “../../../../usr/include“ may look a little confusing, it’s actually linux/usr/include (linux/ is top directory of the repo we git clone), i.e. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/usr/include?h=v5.17-rc2
The filetools/testing/sefltests/Makefilecan install kernel headers in default path “usr/include”. “../../../../usr/include“ is also used in otherMakefileof selftests, like https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/testing/selftests/clone3/Makefile?h=v5.17-rc2
Ah-ha, thanks. Following the other example, should it just be -I instead of -isystem?
Quoted 2 lines
Quoted 1 line
I thought there was a proper "updated kernel headers" dependency that should be used for this?
Updating kernel headers could be one solution. Adding “../../../../usr/include“ in the header file search path could build the tests inside the sandbox.
Yeah, this probably needs separate attention. For this patch, if -I is sufficient, let's do that.
Thanks!
Signature · 1 line
Kees Cook
Quoted 11 lines · Kees Cook
Quoted 4 lines · Sherry Yang
Quoted 1 line
This didn't look right to me. That's outside the build tree, yes?
It’s inside the build tree. “../../../../usr/include“ may look a little confusing, it’s actually linux/usr/include (linux/ is top directory of the repo we git clone), i.e. https://urldefense.com/v3/__https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/usr/include?h=v5.17-rc2__;!!ACWV5N9M2RV99hQ!cP8-SXVNX-k1LuWYjfUYvCYlrOJsInLi9l7hNsqLoXiFULd7xqRS9HRF9WnTno3nBg$
The filetools/testing/sefltests/Makefilecan install kernel headers in default path “usr/include”. “../../../../usr/include“ is also used in otherMakefileof selftests, like https://urldefense.com/v3/__https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/testing/selftests/clone3/Makefile?h=v5.17-rc2__;!!ACWV5N9M2RV99hQ!cP8-SXVNX-k1LuWYjfUYvCYlrOJsInLi9l7hNsqLoXiFULd7xqRS9HRF9WmhyH6mcQ$Ah-ha, thanks. Following the other example, should it just be -I instead of -isystem?
In this case, “-I” works but gcc gives warnings, shown below
———Warning Begin———
gcc -Wl,-no-as-needed -Wall -I../../../../usr/include/ -lpthread seccomp_bpf.c -o /home/opc/linux/tools/testing/selftests/seccomp/seccomp_bpf In file included from seccomp_bpf.c:29:../../../../usr/include/linux/ptrace.h:50: warning: "PTRACE_GETREGSET" redefined
#define PTRACE_GETREGSET 0x4204
In file included from seccomp_bpf.c:26:/usr/include/sys/ptrace.h:153: note: this is the location of the previous definition
#define PTRACE_GETREGSET PTRACE_GETREGSET
In file included from seccomp_bpf.c:29:../../../../usr/include/linux/ptrace.h:51: warning: "PTRACE_SETREGSET" redefined
#define PTRACE_SETREGSET 0x4205
In file included from seccomp_bpf.c:26:/usr/include/sys/ptrace.h:157: note: this is the location of the previous definition
#define PTRACE_SETREGSET PTRACE_SETREGSET
In file included from seccomp_bpf.c:29:../../../../usr/include/linux/ptrace.h:53: warning: "PTRACE_SEIZE" redefined
#define PTRACE_SEIZE 0x4206
In file included from seccomp_bpf.c:26:/usr/include/sys/ptrace.h:162: note: this is the location of the previous definition
#define PTRACE_SEIZE PTRACE_SEIZE
In file included from seccomp_bpf.c:29:../../../../usr/include/linux/ptrace.h:54: warning: "PTRACE_INTERRUPT" redefined
#define PTRACE_INTERRUPT 0x4207
In file included from seccomp_bpf.c:26:/usr/include/sys/ptrace.h:166: note: this is the location of the previous definition
#define PTRACE_INTERRUPT PTRACE_INTERRUPT
In file included from seccomp_bpf.c:29:../../../../usr/include/linux/ptrace.h:55: warning: "PTRACE_LISTEN" redefined
#define PTRACE_LISTEN 0x4208
In file included from seccomp_bpf.c:26:/usr/include/sys/ptrace.h:170: note: this is the location of the previous definition
#define PTRACE_LISTEN PTRACE_LISTEN
In file included from seccomp_bpf.c:29:../../../../usr/include/linux/ptrace.h:57: warning: "PTRACE_PEEKSIGINFO" redefined
#define PTRACE_PEEKSIGINFO 0x4209
In file included from seccomp_bpf.c:26:/usr/include/sys/ptrace.h:174: note: this is the location of the previous definition
#define PTRACE_PEEKSIGINFO PTRACE_PEEKSIGINFO
In file included from seccomp_bpf.c:29:../../../../usr/include/linux/ptrace.h:65: warning: "PTRACE_GETSIGMASK" redefined
#define PTRACE_GETSIGMASK 0x420a
In file included from seccomp_bpf.c:26:/usr/include/sys/ptrace.h:178: note: this is the location of the previous definition
#define PTRACE_GETSIGMASK PTRACE_GETSIGMASK
In file included from seccomp_bpf.c:29:../../../../usr/include/linux/ptrace.h:66: warning: "PTRACE_SETSIGMASK" redefined
#define PTRACE_SETSIGMASK 0x420b
In file included from seccomp_bpf.c:26:/usr/include/sys/ptrace.h:182: note: this is the location of the previous definition
#define PTRACE_SETSIGMASK PTRACE_SETSIGMASK
In file included from seccomp_bpf.c:29:../../../../usr/include/linux/ptrace.h:68: warning: "PTRACE_SECCOMP_GET_FILTER" redefined
#define PTRACE_SECCOMP_GET_FILTER 0x420c
In file included from seccomp_bpf.c:26:/usr/include/sys/ptrace.h:186: note: this is the location of the previous definition
#define PTRACE_SECCOMP_GET_FILTER PTRACE_SECCOMP_GET_FILTER
In file included from seccomp_bpf.c:29:../../../../usr/include/linux/ptrace.h:69: warning: "PTRACE_SECCOMP_GET_METADATA" redefined
#define PTRACE_SECCOMP_GET_METADATA 0x420d
In file included from seccomp_bpf.c:26:/usr/include/sys/ptrace.h:190: note: this is the location of the previous definition
#define PTRACE_SECCOMP_GET_METADATA PTRACE_SECCOMP_GET_METADATA
———Warning End———
So there is redefinition problem between glibc and kernel headers. I tried updating kernel headers, the ptrace.h installed in /usr/include/linux/ptrace.h is the same as we installed in the sandbox ../../../../usr/include/linux/ptrace.h, however, gcc doesn’t throw these warnings if we compile seccomp_bpf.c using /usr/include/linux/ptrace.h. This is because system headers will automatically suppress these warnings (refer to https://gcc.gnu.org/onlinedocs/cpp/System-Headers.html). In my opinion, it’s fair to use “-isystem”, since they're actually generated kernel headers.
Sherry
Shuah Khan
maintainerQuoted 24 lines · Sherry Yang
Quoted 11 lines · Kees Cook
Quoted 4 lines · Sherry Yang
Quoted 1 line
This didn't look right to me. That's outside the build tree, yes?
It’s inside the build tree. “../../../../usr/include“ may look a little confusing, it’s actually linux/usr/include (linux/ is top directory of the repo we git clone), i.e. https://urldefense.com/v3/__https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/usr/include?h=v5.17-rc2__;!!ACWV5N9M2RV99hQ!cP8-SXVNX-k1LuWYjfUYvCYlrOJsInLi9l7hNsqLoXiFULd7xqRS9HRF9WnTno3nBg$
The filetools/testing/sefltests/Makefilecan install kernel headers in default path “usr/include”. “../../../../usr/include“ is also used in otherMakefileof selftests, like https://urldefense.com/v3/__https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/testing/selftests/clone3/Makefile?h=v5.17-rc2__;!!ACWV5N9M2RV99hQ!cP8-SXVNX-k1LuWYjfUYvCYlrOJsInLi9l7hNsqLoXiFULd7xqRS9HRF9WmhyH6mcQ$Ah-ha, thanks. Following the other example, should it just be -I instead of -isystem?
In this case, “-I” works but gcc gives warnings, shown below
———Warning Begin———
gcc -Wl,-no-as-needed -Wall -I../../../../usr/include/ -lpthreadseccomp_bpf.c-o/home/opc/linux/tools/testing/selftests/seccomp/seccomp_bpfIn file included from seccomp_bpf.c:29:../../../../usr/include/linux/ptrace.h:50: warning: "PTRACE_GETREGSET" redefined
#definePTRACE_GETREGSET0x4204In file included from seccomp_bpf.c:26:
/usr/include/sys/ptrace.h:153: note: this is the location of the previous definition
#definePTRACE_GETREGSETPTRACE_GETREGSET
Quoted 5 lines
———Warning End———
So there is redefinition problem between glibc and kernel headers. I tried updating kernel headers, the
ptrace.hinstalled in/usr/include/linux/ptrace.his the same as we installed in the sandbox../../../../usr/include/linux/ptrace.h, however, gcc doesn’t throw these warnings if we compileseccomp_bpf.cusing/usr/include/linux/ptrace.h. This is because system headers will automatically suppress these warnings (refer to https://gcc.gnu.org/onlinedocs/cpp/System-Headers.html). In my opinion, it’s fair to use “-isystem”, since they're actually generated kernel headers.Sherry
Sounds like -i works - I will queue this up for Linux 5.17-rc5.
thanks,
-- Shuah
Quoted 1 line
Sounds like -i works - I will queue this up for Linux 5.17-rc5.
Yeah, -I works, but just with some compiler warnings.
If this is acceptable, do I need to send V2 patch with -I?
Sherry
Shuah Khan
maintainerQuoted 2 lines · Sherry Yang
Yeah, -I works, but just with some compiler warnings.
warnings aren't good. Kees, hope you are okay with this.
Quoted 4 lines
If warnings are acceptable, do I need to send V2 patch with -I?
Sherry
No top posting please. No need to fix it to -I - please send v2 I can't find your patch on lore - not sure why.
Please cc linux-kselftest and [email protected]
Also run scripts/get_maintainer.pl for a complete list of recipients for this patch.
thanks,
-- Shuah
Quoted 7 lines
No top posting please. No need to fix it to -I - please send v2 I can't find your patch on lore - not sure why.
Please cc linux-kselftest and [email protected]
Also run
scripts/get_maintainer.plfor a complete list of recipients for this patch.
Just sent v2, it’s on lore now: https://lore.kernel.org/all/[email protected]/T/#u
Sherry