Re: [PATCH] selftests/seccomp: fix build on older kernels

From: Tycho Andersen
Date: Fri Aug 30 2019 - 11:31:40 EST


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@xxxxxxxx>
> > > > Fixes: 201766a20e30 ("ptrace: add PTRACE_GET_SYSCALL_INFO request")
> > >
> > > Acked-by: Kees Cook <keescook@xxxxxxxxxxxx>
> > >
> > > 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