diff mbox series

selftests/seccomp: fix build on older kernels

Message ID 20190826144302.7745-1-tycho@tycho.ws (mailing list archive)
State Mainlined
Commit 88282297fff00796e81f5e67734a6afdfb31fbc4
Headers show
Series selftests/seccomp: fix build on older kernels | expand

Commit Message

Tycho Andersen Aug. 26, 2019, 2:43 p.m. UTC
The seccomp selftest goes to some length to build against older kernel
headers, viz. all the #ifdefs at the beginning of the file. 201766a20e30
("ptrace: add PTRACE_GET_SYSCALL_INFO request") introduces some additional
macros, but doesn't do the #ifdef dance. Let's add that dance here to
avoid:

gcc -Wl,-no-as-needed -Wall  seccomp_bpf.c -lpthread -o seccomp_bpf
In file included from seccomp_bpf.c:51:
seccomp_bpf.c: In function ‘tracer_ptrace’:
seccomp_bpf.c:1787:20: error: ‘PTRACE_EVENTMSG_SYSCALL_ENTRY’ undeclared (first use in this function); did you mean ‘PTRACE_EVENT_CLONE’?
  EXPECT_EQ(entry ? PTRACE_EVENTMSG_SYSCALL_ENTRY
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../kselftest_harness.h:608:13: note: in definition of macro ‘__EXPECT’
  __typeof__(_expected) __exp = (_expected); \
             ^~~~~~~~~
seccomp_bpf.c:1787:2: note: in expansion of macro ‘EXPECT_EQ’
  EXPECT_EQ(entry ? PTRACE_EVENTMSG_SYSCALL_ENTRY
  ^~~~~~~~~
seccomp_bpf.c:1787:20: note: each undeclared identifier is reported only once for each function it appears in
  EXPECT_EQ(entry ? PTRACE_EVENTMSG_SYSCALL_ENTRY
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../kselftest_harness.h:608:13: note: in definition of macro ‘__EXPECT’
  __typeof__(_expected) __exp = (_expected); \
             ^~~~~~~~~
seccomp_bpf.c:1787:2: note: in expansion of macro ‘EXPECT_EQ’
  EXPECT_EQ(entry ? PTRACE_EVENTMSG_SYSCALL_ENTRY
  ^~~~~~~~~
seccomp_bpf.c:1788:6: error: ‘PTRACE_EVENTMSG_SYSCALL_EXIT’ undeclared (first use in this function); did you mean ‘PTRACE_EVENT_EXIT’?
    : PTRACE_EVENTMSG_SYSCALL_EXIT, msg);
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
../kselftest_harness.h:608:13: note: in definition of macro ‘__EXPECT’
  __typeof__(_expected) __exp = (_expected); \
             ^~~~~~~~~
seccomp_bpf.c:1787:2: note: in expansion of macro ‘EXPECT_EQ’
  EXPECT_EQ(entry ? PTRACE_EVENTMSG_SYSCALL_ENTRY
  ^~~~~~~~~
make: *** [Makefile:12: seccomp_bpf] Error 1

Signed-off-by: Tycho Andersen <tycho@tycho.ws>
Fixes: 201766a20e30 ("ptrace: add PTRACE_GET_SYSCALL_INFO request")
---
 tools/testing/selftests/seccomp/seccomp_bpf.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Kees Cook Aug. 29, 2019, 5:06 p.m. UTC | #1
On Mon, Aug 26, 2019 at 08:43:02AM -0600, Tycho Andersen wrote:
> The seccomp selftest goes to some length to build against older kernel
> headers, viz. all the #ifdefs at the beginning of the file. 201766a20e30
> ("ptrace: add PTRACE_GET_SYSCALL_INFO request") introduces some additional
> macros, but doesn't do the #ifdef dance. Let's add that dance here to
> avoid:
> 
> gcc -Wl,-no-as-needed -Wall  seccomp_bpf.c -lpthread -o seccomp_bpf
> In file included from seccomp_bpf.c:51:
> seccomp_bpf.c: In function ‘tracer_ptrace’:
> seccomp_bpf.c:1787:20: error: ‘PTRACE_EVENTMSG_SYSCALL_ENTRY’ undeclared (first use in this function); did you mean ‘PTRACE_EVENT_CLONE’?
>   EXPECT_EQ(entry ? PTRACE_EVENTMSG_SYSCALL_ENTRY
>                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../kselftest_harness.h:608:13: note: in definition of macro ‘__EXPECT’
>   __typeof__(_expected) __exp = (_expected); \
>              ^~~~~~~~~
> seccomp_bpf.c:1787:2: note: in expansion of macro ‘EXPECT_EQ’
>   EXPECT_EQ(entry ? PTRACE_EVENTMSG_SYSCALL_ENTRY
>   ^~~~~~~~~
> seccomp_bpf.c:1787:20: note: each undeclared identifier is reported only once for each function it appears in
>   EXPECT_EQ(entry ? PTRACE_EVENTMSG_SYSCALL_ENTRY
>                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../kselftest_harness.h:608:13: note: in definition of macro ‘__EXPECT’
>   __typeof__(_expected) __exp = (_expected); \
>              ^~~~~~~~~
> seccomp_bpf.c:1787:2: note: in expansion of macro ‘EXPECT_EQ’
>   EXPECT_EQ(entry ? PTRACE_EVENTMSG_SYSCALL_ENTRY
>   ^~~~~~~~~
> seccomp_bpf.c:1788:6: error: ‘PTRACE_EVENTMSG_SYSCALL_EXIT’ undeclared (first use in this function); did you mean ‘PTRACE_EVENT_EXIT’?
>     : PTRACE_EVENTMSG_SYSCALL_EXIT, msg);
>       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../kselftest_harness.h:608:13: note: in definition of macro ‘__EXPECT’
>   __typeof__(_expected) __exp = (_expected); \
>              ^~~~~~~~~
> seccomp_bpf.c:1787:2: note: in expansion of macro ‘EXPECT_EQ’
>   EXPECT_EQ(entry ? PTRACE_EVENTMSG_SYSCALL_ENTRY
>   ^~~~~~~~~
> make: *** [Makefile:12: seccomp_bpf] Error 1
> 
> Signed-off-by: Tycho Andersen <tycho@tycho.ws>
> Fixes: 201766a20e30 ("ptrace: add PTRACE_GET_SYSCALL_INFO request")

Acked-by: Kees Cook <keescook@chromium.org>

Alakesh Haloi also sent a fix[1] for this. I prefer Tycho's solution
(one #ifndef and a Fixes line). Shuah, can you please apply this?

Thanks!

-Kees

[1] https://lore.kernel.org/lkml/20190822215823.GA11292@ip-172-31-44-144.us-west-2.compute.internal

> ---
>  tools/testing/selftests/seccomp/seccomp_bpf.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c
> index 6ef7f16c4cf5..7f8b5c8982e3 100644
> --- a/tools/testing/selftests/seccomp/seccomp_bpf.c
> +++ b/tools/testing/selftests/seccomp/seccomp_bpf.c
> @@ -199,6 +199,11 @@ struct seccomp_notif_sizes {
>  };
>  #endif
>  
> +#ifndef PTRACE_EVENTMSG_SYSCALL_ENTRY
> +#define PTRACE_EVENTMSG_SYSCALL_ENTRY	1
> +#define PTRACE_EVENTMSG_SYSCALL_EXIT	2
> +#endif
> +
>  #ifndef seccomp
>  int seccomp(unsigned int op, unsigned int flags, void *args)
>  {
> -- 
> 2.20.1
>
shuah Aug. 30, 2019, 12:45 a.m. UTC | #2
On 8/29/19 11:06 AM, Kees Cook wrote:
> On Mon, Aug 26, 2019 at 08:43:02AM -0600, Tycho Andersen wrote:
>> The seccomp selftest goes to some length to build against older kernel
>> headers, viz. all the #ifdefs at the beginning of the file. 201766a20e30
>> ("ptrace: add PTRACE_GET_SYSCALL_INFO request") introduces some additional
>> macros, but doesn't do the #ifdef dance. Let's add that dance here to
>> avoid:
>>
>> gcc -Wl,-no-as-needed -Wall  seccomp_bpf.c -lpthread -o seccomp_bpf
>> In file included from seccomp_bpf.c:51:
>> seccomp_bpf.c: In function ‘tracer_ptrace’:
>> seccomp_bpf.c:1787:20: error: ‘PTRACE_EVENTMSG_SYSCALL_ENTRY’ undeclared (first use in this function); did you mean ‘PTRACE_EVENT_CLONE’?
>>    EXPECT_EQ(entry ? PTRACE_EVENTMSG_SYSCALL_ENTRY
>>                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> ../kselftest_harness.h:608:13: note: in definition of macro ‘__EXPECT’
>>    __typeof__(_expected) __exp = (_expected); \
>>               ^~~~~~~~~
>> seccomp_bpf.c:1787:2: note: in expansion of macro ‘EXPECT_EQ’
>>    EXPECT_EQ(entry ? PTRACE_EVENTMSG_SYSCALL_ENTRY
>>    ^~~~~~~~~
>> seccomp_bpf.c:1787:20: note: each undeclared identifier is reported only once for each function it appears in
>>    EXPECT_EQ(entry ? PTRACE_EVENTMSG_SYSCALL_ENTRY
>>                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> ../kselftest_harness.h:608:13: note: in definition of macro ‘__EXPECT’
>>    __typeof__(_expected) __exp = (_expected); \
>>               ^~~~~~~~~
>> seccomp_bpf.c:1787:2: note: in expansion of macro ‘EXPECT_EQ’
>>    EXPECT_EQ(entry ? PTRACE_EVENTMSG_SYSCALL_ENTRY
>>    ^~~~~~~~~
>> seccomp_bpf.c:1788:6: error: ‘PTRACE_EVENTMSG_SYSCALL_EXIT’ undeclared (first use in this function); did you mean ‘PTRACE_EVENT_EXIT’?
>>      : PTRACE_EVENTMSG_SYSCALL_EXIT, msg);
>>        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> ../kselftest_harness.h:608:13: note: in definition of macro ‘__EXPECT’
>>    __typeof__(_expected) __exp = (_expected); \
>>               ^~~~~~~~~
>> seccomp_bpf.c:1787:2: note: in expansion of macro ‘EXPECT_EQ’
>>    EXPECT_EQ(entry ? PTRACE_EVENTMSG_SYSCALL_ENTRY
>>    ^~~~~~~~~
>> make: *** [Makefile:12: seccomp_bpf] Error 1
>>
>> Signed-off-by: Tycho Andersen <tycho@tycho.ws>
>> Fixes: 201766a20e30 ("ptrace: add PTRACE_GET_SYSCALL_INFO request")
> 
> Acked-by: Kees Cook <keescook@chromium.org>
> 
> Alakesh Haloi also sent a fix[1] for this. I prefer Tycho's solution
> (one #ifndef and a Fixes line). Shuah, can you please apply this?
> 

Kees,

Yes I will pick this up.

thanks,
-- Shuah
shuah Aug. 30, 2019, 3:19 p.m. UTC | #3
On 8/29/19 6:45 PM, shuah wrote:
> On 8/29/19 11:06 AM, Kees Cook wrote:
>> On Mon, Aug 26, 2019 at 08:43:02AM -0600, Tycho Andersen wrote:
>>> The seccomp selftest goes to some length to build against older kernel
>>> headers, viz. all the #ifdefs at the beginning of the file. 201766a20e30
>>> ("ptrace: add PTRACE_GET_SYSCALL_INFO request") introduces some 
>>> additional
>>> macros, but doesn't do the #ifdef dance. Let's add that dance here to
>>> avoid:
>>>
>>> gcc -Wl,-no-as-needed -Wall  seccomp_bpf.c -lpthread -o seccomp_bpf
>>> In file included from seccomp_bpf.c:51:
>>> seccomp_bpf.c: In function ‘tracer_ptrace’:
>>> seccomp_bpf.c:1787:20: error: ‘PTRACE_EVENTMSG_SYSCALL_ENTRY’ 
>>> undeclared (first use in this function); did you mean 
>>> ‘PTRACE_EVENT_CLONE’?
>>>    EXPECT_EQ(entry ? PTRACE_EVENTMSG_SYSCALL_ENTRY
>>>                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>> ../kselftest_harness.h:608:13: note: in definition of macro ‘__EXPECT’
>>>    __typeof__(_expected) __exp = (_expected); \
>>>               ^~~~~~~~~
>>> seccomp_bpf.c:1787:2: note: in expansion of macro ‘EXPECT_EQ’
>>>    EXPECT_EQ(entry ? PTRACE_EVENTMSG_SYSCALL_ENTRY
>>>    ^~~~~~~~~
>>> seccomp_bpf.c:1787:20: note: each undeclared identifier is reported 
>>> only once for each function it appears in
>>>    EXPECT_EQ(entry ? PTRACE_EVENTMSG_SYSCALL_ENTRY
>>>                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>> ../kselftest_harness.h:608:13: note: in definition of macro ‘__EXPECT’
>>>    __typeof__(_expected) __exp = (_expected); \
>>>               ^~~~~~~~~
>>> seccomp_bpf.c:1787:2: note: in expansion of macro ‘EXPECT_EQ’
>>>    EXPECT_EQ(entry ? PTRACE_EVENTMSG_SYSCALL_ENTRY
>>>    ^~~~~~~~~
>>> seccomp_bpf.c:1788:6: error: ‘PTRACE_EVENTMSG_SYSCALL_EXIT’ 
>>> undeclared (first use in this function); did you mean 
>>> ‘PTRACE_EVENT_EXIT’?
>>>      : PTRACE_EVENTMSG_SYSCALL_EXIT, msg);
>>>        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>> ../kselftest_harness.h:608:13: note: in definition of macro ‘__EXPECT’
>>>    __typeof__(_expected) __exp = (_expected); \
>>>               ^~~~~~~~~
>>> seccomp_bpf.c:1787:2: note: in expansion of macro ‘EXPECT_EQ’
>>>    EXPECT_EQ(entry ? PTRACE_EVENTMSG_SYSCALL_ENTRY
>>>    ^~~~~~~~~
>>> make: *** [Makefile:12: seccomp_bpf] Error 1
>>>
>>> Signed-off-by: Tycho Andersen <tycho@tycho.ws>
>>> Fixes: 201766a20e30 ("ptrace: add PTRACE_GET_SYSCALL_INFO request")
>>
>> Acked-by: Kees Cook <keescook@chromium.org>
>>
>> Alakesh Haloi also sent a fix[1] for this. I prefer Tycho's solution
>> (one #ifndef and a Fixes line). Shuah, can you please apply this?
>>
> 
> Kees,
> 
> Yes I will pick this up.
> 
> thanks,
> -- Shuah
> 

Applied after fixing the following checkpatch error in the commit log:

ERROR: Please use git commit description style 'commit <12+ chars of 
sha1> ("<title line>")' - ie: 'commit 201766a20e30 ("ptrace: add 
PTRACE_GET_SYSCALL_INFO request")'
#82:

Now reads as follows:

Commit 201766a20e30 ("ptrace: add PTRACE_GET_SYSCALL_INFO request")
     introduces some additional macros, but doesn't do the #ifdef dance.
     Let's add that dance here to avoid:

thanks,
-- Shuah
Tycho Andersen Aug. 30, 2019, 3:31 p.m. UTC | #4
On Fri, Aug 30, 2019 at 09:19:00AM -0600, shuah wrote:
> On 8/29/19 6:45 PM, shuah wrote:
> > On 8/29/19 11:06 AM, Kees Cook wrote:
> > > On Mon, Aug 26, 2019 at 08:43:02AM -0600, Tycho Andersen wrote:
> > > > The seccomp selftest goes to some length to build against older kernel
> > > > headers, viz. all the #ifdefs at the beginning of the file. 201766a20e30
> > > > ("ptrace: add PTRACE_GET_SYSCALL_INFO request") introduces some
> > > > additional
> > > > macros, but doesn't do the #ifdef dance. Let's add that dance here to
> > > > avoid:
> > > > 
> > > > gcc -Wl,-no-as-needed -Wall  seccomp_bpf.c -lpthread -o seccomp_bpf
> > > > In file included from seccomp_bpf.c:51:
> > > > seccomp_bpf.c: In function ‘tracer_ptrace’:
> > > > seccomp_bpf.c:1787:20: error: ‘PTRACE_EVENTMSG_SYSCALL_ENTRY’
> > > > undeclared (first use in this function); did you mean
> > > > ‘PTRACE_EVENT_CLONE’?
> > > >    EXPECT_EQ(entry ? PTRACE_EVENTMSG_SYSCALL_ENTRY
> > > >                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > > > ../kselftest_harness.h:608:13: note: in definition of macro ‘__EXPECT’
> > > >    __typeof__(_expected) __exp = (_expected); \
> > > >               ^~~~~~~~~
> > > > seccomp_bpf.c:1787:2: note: in expansion of macro ‘EXPECT_EQ’
> > > >    EXPECT_EQ(entry ? PTRACE_EVENTMSG_SYSCALL_ENTRY
> > > >    ^~~~~~~~~
> > > > seccomp_bpf.c:1787:20: note: each undeclared identifier is
> > > > reported only once for each function it appears in
> > > >    EXPECT_EQ(entry ? PTRACE_EVENTMSG_SYSCALL_ENTRY
> > > >                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > > > ../kselftest_harness.h:608:13: note: in definition of macro ‘__EXPECT’
> > > >    __typeof__(_expected) __exp = (_expected); \
> > > >               ^~~~~~~~~
> > > > seccomp_bpf.c:1787:2: note: in expansion of macro ‘EXPECT_EQ’
> > > >    EXPECT_EQ(entry ? PTRACE_EVENTMSG_SYSCALL_ENTRY
> > > >    ^~~~~~~~~
> > > > seccomp_bpf.c:1788:6: error: ‘PTRACE_EVENTMSG_SYSCALL_EXIT’
> > > > undeclared (first use in this function); did you mean
> > > > ‘PTRACE_EVENT_EXIT’?
> > > >      : PTRACE_EVENTMSG_SYSCALL_EXIT, msg);
> > > >        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > > > ../kselftest_harness.h:608:13: note: in definition of macro ‘__EXPECT’
> > > >    __typeof__(_expected) __exp = (_expected); \
> > > >               ^~~~~~~~~
> > > > seccomp_bpf.c:1787:2: note: in expansion of macro ‘EXPECT_EQ’
> > > >    EXPECT_EQ(entry ? PTRACE_EVENTMSG_SYSCALL_ENTRY
> > > >    ^~~~~~~~~
> > > > make: *** [Makefile:12: seccomp_bpf] Error 1
> > > > 
> > > > Signed-off-by: Tycho Andersen <tycho@tycho.ws>
> > > > Fixes: 201766a20e30 ("ptrace: add PTRACE_GET_SYSCALL_INFO request")
> > > 
> > > Acked-by: Kees Cook <keescook@chromium.org>
> > > 
> > > Alakesh Haloi also sent a fix[1] for this. I prefer Tycho's solution
> > > (one #ifndef and a Fixes line). Shuah, can you please apply this?
> > > 
> > 
> > Kees,
> > 
> > Yes I will pick this up.
> > 
> > thanks,
> > -- Shuah
> > 
> 
> Applied after fixing the following checkpatch error in the commit log:
> 
> ERROR: Please use git commit description style 'commit <12+ chars of sha1>
> ("<title line>")' - ie: 'commit 201766a20e30 ("ptrace: add
> PTRACE_GET_SYSCALL_INFO request")'
> #82:
> 
> Now reads as follows:
> 
> Commit 201766a20e30 ("ptrace: add PTRACE_GET_SYSCALL_INFO request")
>     introduces some additional macros, but doesn't do the #ifdef dance.
>     Let's add that dance here to avoid:

Ah, good to know. Thanks!

Tycho
diff mbox series

Patch

diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c
index 6ef7f16c4cf5..7f8b5c8982e3 100644
--- a/tools/testing/selftests/seccomp/seccomp_bpf.c
+++ b/tools/testing/selftests/seccomp/seccomp_bpf.c
@@ -199,6 +199,11 @@  struct seccomp_notif_sizes {
 };
 #endif
 
+#ifndef PTRACE_EVENTMSG_SYSCALL_ENTRY
+#define PTRACE_EVENTMSG_SYSCALL_ENTRY	1
+#define PTRACE_EVENTMSG_SYSCALL_EXIT	2
+#endif
+
 #ifndef seccomp
 int seccomp(unsigned int op, unsigned int flags, void *args)
 {