* [PATCH] Fix build on older kernels without BPF.
@ 2016-07-12 18:43 Vinson Lee
2016-07-12 19:02 ` Dave Jones
0 siblings, 1 reply; 8+ messages in thread
From: Vinson Lee @ 2016-07-12 18:43 UTC (permalink / raw)
To: trinity
Signed-off-by: Vinson Lee <vlee@freedesktop.org>
---
configure | 1 +
syscalls/bpf.c | 14 ++++++++++++++
2 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/configure b/configure
index 8d95929..ca37e4e 100755
--- a/configure
+++ b/configure
@@ -239,6 +239,7 @@ check_header execinfo.h USE_BACKTRACE
check_header netatalk/at.h USE_APPLETALK
check_header netrom/netrom.h USE_NETROM
check_header netrose/rose.h USE_ROSE
+check_header linux/bpf.h USE_BPF
rm -f "$TMP" "$TMP.log" "$TMP.c"
diff --git a/syscalls/bpf.c b/syscalls/bpf.c
index b2f57d3..4788082 100644
--- a/syscalls/bpf.c
+++ b/syscalls/bpf.c
@@ -1,13 +1,16 @@
/*
* SYSCALL_DEFINE3(bpf, int, cmd, union bpf_attr __user *, uattr, unsigned int, size)
*/
+#ifdef USE_BPF
#include <linux/bpf.h>
+#endif
#include <linux/filter.h>
#include "arch.h"
#include "net.h"
#include "random.h"
#include "sanitise.h"
+#ifdef USE_BPF
static unsigned long bpf_prog_types[] = {
BPF_PROG_TYPE_UNSPEC,
BPF_PROG_TYPE_SOCKET_FILTER,
@@ -15,9 +18,11 @@ static unsigned long bpf_prog_types[] = {
BPF_PROG_TYPE_SCHED_CLS,
BPF_PROG_TYPE_SCHED_ACT,
};
+#endif
static const char license[] = "GPLv2";
+#ifdef USE_BPF
static void bpf_prog_load(struct syscallrecord *rec)
{
unsigned long *insns = NULL, len = 0;
@@ -49,18 +54,22 @@ static void bpf_prog_load(struct syscallrecord *rec)
rec->a2 = (unsigned long) attr;
rec->a3 = sizeof(attr);
}
+#endif
static void sanitise_bpf(struct syscallrecord *rec)
{
switch (rec->a1) {
+#ifdef USE_BPF
case BPF_PROG_LOAD:
bpf_prog_load(rec);
break;
+#endif
default:
break;
}
}
+#ifdef USE_BPF
static void post_bpf(struct syscallrecord *rec)
{
union bpf_attr *attr;
@@ -84,10 +93,15 @@ static void post_bpf(struct syscallrecord *rec)
break;
}
}
+#else
+static void post_bpf(__unused__ struct syscallrecord *rec) { }
+#endif
static unsigned long bpf_flags[] = {
+#ifdef USE_BPF
BPF_MAP_CREATE, BPF_MAP_LOOKUP_ELEM, BPF_MAP_UPDATE_ELEM, BPF_MAP_DELETE_ELEM,
BPF_MAP_GET_NEXT_KEY, BPF_PROG_LOAD,
+#endif
};
struct syscallentry syscall_bpf = {
--
1.7.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] Fix build on older kernels without BPF.
2016-07-12 18:43 [PATCH] Fix build on older kernels without BPF Vinson Lee
@ 2016-07-12 19:02 ` Dave Jones
2016-07-12 21:33 ` [PATCH v2] " Vinson Lee
0 siblings, 1 reply; 8+ messages in thread
From: Dave Jones @ 2016-07-12 19:02 UTC (permalink / raw)
To: Vinson Lee; +Cc: trinity
On Tue, Jul 12, 2016 at 06:43:06PM +0000, Vinson Lee wrote:
> diff --git a/syscalls/bpf.c b/syscalls/bpf.c
> index b2f57d3..4788082 100644
> --- a/syscalls/bpf.c
> +++ b/syscalls/bpf.c
> @@ -1,13 +1,16 @@
> /*
> * SYSCALL_DEFINE3(bpf, int, cmd, union bpf_attr __user *, uattr, unsigned int, size)
> */
> +#ifdef USE_BPF
> #include <linux/bpf.h>
> +#endif
> #include <linux/filter.h>
> #include "arch.h"
> #include "net.h"
> #include "random.h"
> #include "sanitise.h"
>
> +#ifdef USE_BPF
> static unsigned long bpf_prog_types[] = {
> BPF_PROG_TYPE_UNSPEC,
> BPF_PROG_TYPE_SOCKET_FILTER,
> @@ -15,9 +18,11 @@ static unsigned long bpf_prog_types[] = {
> BPF_PROG_TYPE_SCHED_CLS,
> BPF_PROG_TYPE_SCHED_ACT,
> };
> +#endif
>
> static const char license[] = "GPLv2";
>
> +#ifdef USE_BPF
> static void bpf_prog_load(struct syscallrecord *rec)
> {
> unsigned long *insns = NULL, len = 0;
> @@ -49,18 +54,22 @@ static void bpf_prog_load(struct syscallrecord *rec)
> rec->a2 = (unsigned long) attr;
> rec->a3 = sizeof(attr);
> }
> +#endif
>
> static void sanitise_bpf(struct syscallrecord *rec)
> {
> switch (rec->a1) {
> +#ifdef USE_BPF
> case BPF_PROG_LOAD:
> bpf_prog_load(rec);
> break;
> +#endif
> default:
> break;
> }
> }
>
> +#ifdef USE_BPF
> static void post_bpf(struct syscallrecord *rec)
> {
> union bpf_attr *attr;
> @@ -84,10 +93,15 @@ static void post_bpf(struct syscallrecord *rec)
> break;
> }
> }
> +#else
> +static void post_bpf(__unused__ struct syscallrecord *rec) { }
> +#endif
>
> static unsigned long bpf_flags[] = {
> +#ifdef USE_BPF
> BPF_MAP_CREATE, BPF_MAP_LOOKUP_ELEM, BPF_MAP_UPDATE_ELEM, BPF_MAP_DELETE_ELEM,
> BPF_MAP_GET_NEXT_KEY, BPF_PROG_LOAD,
> +#endif
> };
This might be cleaner to wrap the whole of syscalls/bpf.c in one ifdef, and then
add additional ones to include/syscalls-*.h to look like
#ifdef USE_BPF
{ .entry = &syscall_bpf },
#else
{ .entry = NULL },
#endif
I can't remember if the tables code handles a NULL .entry in the middle though.
Might need some tweaking.
Dave
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2] Fix build on older kernels without BPF.
2016-07-12 19:02 ` Dave Jones
@ 2016-07-12 21:33 ` Vinson Lee
2016-07-21 20:10 ` Dave Jones
0 siblings, 1 reply; 8+ messages in thread
From: Vinson Lee @ 2016-07-12 21:33 UTC (permalink / raw)
To: trinity
Suggested-by: Dave Jones <davej@codemonkey.org.uk>
Signed-off-by: Vinson Lee <vlee@freedesktop.org>
---
configure | 1 +
include/syscalls-aarch64.h | 2 ++
include/syscalls-arm.h | 2 ++
include/syscalls-i386.h | 2 ++
include/syscalls-ia64.h | 2 ++
include/syscalls-mips.h | 2 ++
include/syscalls-parisc.h | 2 ++
include/syscalls-s390.h | 2 ++
include/syscalls-s390x.h | 2 ++
include/syscalls-sparc.h | 2 ++
include/syscalls-x86_64.h | 2 ++
syscalls/bpf.c | 2 ++
12 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/configure b/configure
index 8d95929..fe3985f 100755
--- a/configure
+++ b/configure
@@ -239,6 +239,7 @@ check_header execinfo.h USE_BACKTRACE
check_header netatalk/at.h USE_APPLETALK
check_header netrom/netrom.h USE_NETROM
check_header netrose/rose.h USE_ROSE
+check_header linux/bfp.h USE_BPF
rm -f "$TMP" "$TMP.log" "$TMP.c"
diff --git a/include/syscalls-aarch64.h b/include/syscalls-aarch64.h
index 09acf41..ee18c64 100644
--- a/include/syscalls-aarch64.h
+++ b/include/syscalls-aarch64.h
@@ -290,6 +290,8 @@ struct syscalltable syscalls_aarch64[] = {
/* 277 */ { .entry = &syscall_seccomp },
/* 278 */ { .entry = &syscall_getrandom },
/* 279 */ { .entry = &syscall_memfd_create },
+#ifdef USE_BPF
/* 280 */ { .entry = &syscall_bpf },
+#endif
/* 281 */ { .entry = &syscall_execveat },
};
diff --git a/include/syscalls-arm.h b/include/syscalls-arm.h
index 7ecc435..2c59316 100644
--- a/include/syscalls-arm.h
+++ b/include/syscalls-arm.h
@@ -396,7 +396,9 @@ struct syscalltable syscalls_arm[] = {
{ .entry = &syscall_seccomp },
{ .entry = &syscall_getrandom },
/* 385 */ { .entry = &syscall_memfd_create },
+#ifdef USE_BPF
{ .entry = &syscall_bpf },
+#endif
{ .entry = &syscall_execveat },
{ .entry = &syscall_userfaultfd },
{ .entry = &syscall_membarrier },
diff --git a/include/syscalls-i386.h b/include/syscalls-i386.h
index 147b1eb..078efa3 100644
--- a/include/syscalls-i386.h
+++ b/include/syscalls-i386.h
@@ -364,7 +364,9 @@ struct syscalltable syscalls_i386[] = {
{ .entry = &syscall_seccomp },
{ .entry = &syscall_getrandom },
{ .entry = &syscall_memfd_create },
+#ifdef USE_BPF
{ .entry = &syscall_bpf },
+#endif
{ .entry = &syscall_execveat },
{ .entry = &syscall_socket },
{ .entry = &syscall_socketpair },
diff --git a/include/syscalls-ia64.h b/include/syscalls-ia64.h
index 28eacce..172c64f 100644
--- a/include/syscalls-ia64.h
+++ b/include/syscalls-ia64.h
@@ -324,7 +324,9 @@ struct syscalltable syscalls_ia64[] = {
{ .entry = &syscall_renameat2 },
{ .entry = &syscall_getrandom },
{ .entry = &syscall_memfd_create },
+#ifdef USE_BPF
{ .entry = &syscall_bpf },
+#endif
{ .entry = &syscall_userfaultfd },
{ .entry = &syscall_membarrier },
{ .entry = &syscall_kcmp },
diff --git a/include/syscalls-mips.h b/include/syscalls-mips.h
index 273ba25..1f1748b 100644
--- a/include/syscalls-mips.h
+++ b/include/syscalls-mips.h
@@ -371,5 +371,7 @@ struct syscalltable syscalls_mips[] = {
{ .entry = &syscall_seccomp },
{ .entry = &syscall_getrandom },
{ .entry = &syscall_memfd_create },
+#ifdef USE_BPF
{ .entry = &syscall_bpf }, /* 4355 */
+#endif
};
diff --git a/include/syscalls-parisc.h b/include/syscalls-parisc.h
index 8d164e5..1b830f8 100644
--- a/include/syscalls-parisc.h
+++ b/include/syscalls-parisc.h
@@ -348,6 +348,8 @@ struct syscalltable syscalls_parisc[] = {
{ .entry = &syscall_seccomp },
{ .entry = &syscall_getrandom },
{ .entry = &syscall_memfd_create },
+#ifdef USE_BPF
{ .entry = &syscall_bpf },
+#endif
{ .entry = &syscall_execveat },
};
diff --git a/include/syscalls-s390.h b/include/syscalls-s390.h
index dd9c93a..24d981e 100644
--- a/include/syscalls-s390.h
+++ b/include/syscalls-s390.h
@@ -358,7 +358,9 @@ struct syscalltable syscalls_s390[] = {
{ .entry = &syscall_seccomp },
{ .entry = &syscall_getrandom },
{ .entry = &syscall_memfd_create },
+#ifdef USE_BPF
{ .entry = &syscall_bpf },
+#endif
{ .entry = &syscall_ni_syscall }, // TODO: syscall_s390_pci_mmio_write
{ .entry = &syscall_ni_syscall }, // TODO: syscall_s390_pci_mmio_read
{ .entry = &syscall_execveat },
diff --git a/include/syscalls-s390x.h b/include/syscalls-s390x.h
index 6ddeb85..75c10f8 100644
--- a/include/syscalls-s390x.h
+++ b/include/syscalls-s390x.h
@@ -358,7 +358,9 @@ struct syscalltable syscalls_s390x[] = {
{ .entry = &syscall_seccomp },
{ .entry = &syscall_getrandom },
{ .entry = &syscall_memfd_create },
+#ifdef USE_BPF
{ .entry = &syscall_bpf },
+#endif
{ .entry = &syscall_ni_syscall }, // TODO: syscall_s390_pci_mmio_write
{ .entry = &syscall_ni_syscall }, // TODO: syscall_s390_pci_mmio_read
{ .entry = &syscall_execveat },
diff --git a/include/syscalls-sparc.h b/include/syscalls-sparc.h
index 5cedd89..77cfe2a 100644
--- a/include/syscalls-sparc.h
+++ b/include/syscalls-sparc.h
@@ -356,6 +356,8 @@ struct syscalltable syscalls_sparc[] = {
{ .entry = &syscall_seccomp },
{ .entry = &syscall_getrandom },
{ .entry = &syscall_memfd_create },
+#ifdef USE_BPF
{ .entry = &syscall_bpf },
+#endif
{ .entry = &syscall_execveat },
};
diff --git a/include/syscalls-x86_64.h b/include/syscalls-x86_64.h
index c75f4de..07a67ca 100644
--- a/include/syscalls-x86_64.h
+++ b/include/syscalls-x86_64.h
@@ -328,7 +328,9 @@ struct syscalltable syscalls_x86_64[] = {
{ .entry = &syscall_seccomp },
{ .entry = &syscall_memfd_create },
{ .entry = &syscall_kexec_file_load },
+#ifdef USE_BPF
{ .entry = &syscall_bpf },
+#endif
{ .entry = &syscall_execveat },
{ .entry = &syscall_userfaultfd },
{ .entry = &syscall_membarrier },
diff --git a/syscalls/bpf.c b/syscalls/bpf.c
index b2f57d3..476a277 100644
--- a/syscalls/bpf.c
+++ b/syscalls/bpf.c
@@ -1,6 +1,7 @@
/*
* SYSCALL_DEFINE3(bpf, int, cmd, union bpf_attr __user *, uattr, unsigned int, size)
*/
+#ifdef USE_BPF
#include <linux/bpf.h>
#include <linux/filter.h>
#include "arch.h"
@@ -102,3 +103,4 @@ struct syscallentry syscall_bpf = {
.sanitise = sanitise_bpf,
.post = post_bpf,
};
+#endif
--
1.7.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2] Fix build on older kernels without BPF.
2016-07-12 21:33 ` [PATCH v2] " Vinson Lee
@ 2016-07-21 20:10 ` Dave Jones
2016-07-26 0:24 ` Vinson Lee
0 siblings, 1 reply; 8+ messages in thread
From: Dave Jones @ 2016-07-21 20:10 UTC (permalink / raw)
To: Vinson Lee; +Cc: trinity
On Tue, Jul 12, 2016 at 09:33:56PM +0000, Vinson Lee wrote:
> Suggested-by: Dave Jones <davej@codemonkey.org.uk>
> Signed-off-by: Vinson Lee <vlee@freedesktop.org>
Close, but..
> diff --git a/include/syscalls-aarch64.h b/include/syscalls-aarch64.h
> index 09acf41..ee18c64 100644
> --- a/include/syscalls-aarch64.h
> +++ b/include/syscalls-aarch64.h
> @@ -290,6 +290,8 @@ struct syscalltable syscalls_aarch64[] = {
> /* 277 */ { .entry = &syscall_seccomp },
> /* 278 */ { .entry = &syscall_getrandom },
> /* 279 */ { .entry = &syscall_memfd_create },
> +#ifdef USE_BPF
> /* 280 */ { .entry = &syscall_bpf },
> +#endif
> /* 281 */ { .entry = &syscall_execveat },
> };
You need an
#else
NULL,
for each of these, otherwise the next syscall will be in the wrong slot.
Dave
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] Fix build on older kernels without BPF.
2016-07-21 20:10 ` Dave Jones
@ 2016-07-26 0:24 ` Vinson Lee
2016-07-26 0:59 ` Dave Jones
0 siblings, 1 reply; 8+ messages in thread
From: Vinson Lee @ 2016-07-26 0:24 UTC (permalink / raw)
To: Dave Jones; +Cc: trinity
On Thu, Jul 21, 2016 at 1:10 PM, Dave Jones <davej@codemonkey.org.uk> wrote:
> On Tue, Jul 12, 2016 at 09:33:56PM +0000, Vinson Lee wrote:
> > Suggested-by: Dave Jones <davej@codemonkey.org.uk>
> > Signed-off-by: Vinson Lee <vlee@freedesktop.org>
>
> Close, but..
>
> > diff --git a/include/syscalls-aarch64.h b/include/syscalls-aarch64.h
> > index 09acf41..ee18c64 100644
> > --- a/include/syscalls-aarch64.h
> > +++ b/include/syscalls-aarch64.h
> > @@ -290,6 +290,8 @@ struct syscalltable syscalls_aarch64[] = {
> > /* 277 */ { .entry = &syscall_seccomp },
> > /* 278 */ { .entry = &syscall_getrandom },
> > /* 279 */ { .entry = &syscall_memfd_create },
> > +#ifdef USE_BPF
> > /* 280 */ { .entry = &syscall_bpf },
> > +#endif
> > /* 281 */ { .entry = &syscall_execveat },
> > };
>
> You need an
>
> #else
> NULL,
>
> for each of these, otherwise the next syscall will be in the wrong slot.
>
> Dave
I tried making that change but trinity would crash in
copy_syscall_table with memcpy with a NULL from[n].entry.
Program received signal SIGSEGV, Segmentation fault.
0x000000000041300e in copy_syscall_table (from=0x63d840, nr=329) at
/usr/include/bits/string3.h:52
52 return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest));
(gdb) bt
#0 0x000000000041300e in copy_syscall_table (from=0x63d840, nr=329)
at /usr/include/bits/string3.h:52
#1 0x00000000004130f3 in select_syscall_tables () at tables.c:491
#2 0x0000000000413e95 in main (argc=1, argv=0x7fffffffe438) at trinity.c:115
tables.c
470 static struct syscalltable * copy_syscall_table(struct
syscalltable *from, unsigned int nr)
471 {
472 unsigned int n;
473 struct syscallentry *copy;
474
475 copy = alloc_shared(nr * sizeof(struct syscallentry));
476 if (copy == NULL)
477 exit(EXIT_FAILURE);
478
479 for (n = 0; n < nr; n++) {
480 memcpy(copy + n , from[n].entry, sizeof(struct
syscallentry));
481 copy[n].number = n;
482 copy[n].active_number = 0;
483 from[n].entry = ©[n];
484 }
485 return from;
486 }
Vinson
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] Fix build on older kernels without BPF.
2016-07-26 0:24 ` Vinson Lee
@ 2016-07-26 0:59 ` Dave Jones
2016-08-04 20:36 ` Dave Jones
0 siblings, 1 reply; 8+ messages in thread
From: Dave Jones @ 2016-07-26 0:59 UTC (permalink / raw)
To: Vinson Lee; +Cc: trinity
On Mon, Jul 25, 2016 at 05:24:43PM -0700, Vinson Lee wrote:
> > for each of these, otherwise the next syscall will be in the wrong slot.
>
> I tried making that change but trinity would crash in
> copy_syscall_table with memcpy with a NULL from[n].entry.
>
> Program received signal SIGSEGV, Segmentation fault.
> 0x000000000041300e in copy_syscall_table (from=0x63d840, nr=329) at
> /usr/include/bits/string3.h:52
> 52 return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest));
> (gdb) bt
> #0 0x000000000041300e in copy_syscall_table (from=0x63d840, nr=329)
> at /usr/include/bits/string3.h:52
> #1 0x00000000004130f3 in select_syscall_tables () at tables.c:491
> #2 0x0000000000413e95 in main (argc=1, argv=0x7fffffffe438) at trinity.c:115
>
> tables.c
> 470 static struct syscalltable * copy_syscall_table(struct
> syscalltable *from, unsigned int nr)
> 471 {
> 472 unsigned int n;
> 473 struct syscallentry *copy;
> 474
> 475 copy = alloc_shared(nr * sizeof(struct syscallentry));
> 476 if (copy == NULL)
> 477 exit(EXIT_FAILURE);
> 478
> 479 for (n = 0; n < nr; n++) {
> 480 memcpy(copy + n , from[n].entry, sizeof(struct
> syscallentry));
> 481 copy[n].number = n;
> 482 copy[n].active_number = 0;
> 483 from[n].entry = ©[n];
> 484 }
> 485 return from;
> 486 }
stick a
if (from[n] == NULL)
continue
before the memcpy. Does that dtrt ?
We might segv somewhere else after patching this up. It's been so long since
I touched this stuff I don't fully recall how it works. I'll poke at it
some tomorrow.
Dave
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] Fix build on older kernels without BPF.
2016-07-26 0:59 ` Dave Jones
@ 2016-08-04 20:36 ` Dave Jones
2016-08-05 18:44 ` Dave Jones
0 siblings, 1 reply; 8+ messages in thread
From: Dave Jones @ 2016-08-04 20:36 UTC (permalink / raw)
To: Vinson Lee; +Cc: trinity
On Mon, Jul 25, 2016 at 08:59:29PM -0400, Dave Jones wrote:
> > tables.c
> > 470 static struct syscalltable * copy_syscall_table(struct
> > syscalltable *from, unsigned int nr)
> > 471 {
> > 472 unsigned int n;
> > 473 struct syscallentry *copy;
> > 474
> > 475 copy = alloc_shared(nr * sizeof(struct syscallentry));
> > 476 if (copy == NULL)
> > 477 exit(EXIT_FAILURE);
> > 478
> > 479 for (n = 0; n < nr; n++) {
> > 480 memcpy(copy + n , from[n].entry, sizeof(struct
> > syscallentry));
> > 481 copy[n].number = n;
> > 482 copy[n].active_number = 0;
> > 483 from[n].entry = ©[n];
> > 484 }
> > 485 return from;
> > 486 }
>
>
> stick a
> if (from[n] == NULL)
> continue
>
> before the memcpy. Does that dtrt ?
>
> We might segv somewhere else after patching this up. It's been so long since
> I touched this stuff I don't fully recall how it works. I'll poke at it
> some tomorrow.
Just getting around to this. It's a bit more involved than I hoped.
Spraying a bunch of null checks around like this seems to be the thing to do..
Let me know how this works out for you.
Dave
diff --git a/configure b/configure
index 8d959298f129..93cf19c5861c 100755
--- a/configure
+++ b/configure
@@ -239,6 +239,7 @@ check_header execinfo.h USE_BACKTRACE
check_header netatalk/at.h USE_APPLETALK
check_header netrom/netrom.h USE_NETROM
check_header netrose/rose.h USE_ROSE
+check_header linux/bfp.h USE_BPFF
rm -f "$TMP" "$TMP.log" "$TMP.c"
diff --git a/include/syscalls-aarch64.h b/include/syscalls-aarch64.h
index 09acf418a12e..fda0814128bc 100644
--- a/include/syscalls-aarch64.h
+++ b/include/syscalls-aarch64.h
@@ -290,6 +290,10 @@ struct syscalltable syscalls_aarch64[] = {
/* 277 */ { .entry = &syscall_seccomp },
/* 278 */ { .entry = &syscall_getrandom },
/* 279 */ { .entry = &syscall_memfd_create },
+#ifdef USE_BPF
/* 280 */ { .entry = &syscall_bpf },
+#else
+ { .entry = NULL },
+#endif
/* 281 */ { .entry = &syscall_execveat },
};
diff --git a/include/syscalls-arm.h b/include/syscalls-arm.h
index 7ecc4353a835..0f40e57e5501 100644
--- a/include/syscalls-arm.h
+++ b/include/syscalls-arm.h
@@ -396,7 +396,11 @@ struct syscalltable syscalls_arm[] = {
{ .entry = &syscall_seccomp },
{ .entry = &syscall_getrandom },
/* 385 */ { .entry = &syscall_memfd_create },
+#ifdef USE_BPF
{ .entry = &syscall_bpf },
+#else
+ { .entry = NULL },
+#endif
{ .entry = &syscall_execveat },
{ .entry = &syscall_userfaultfd },
{ .entry = &syscall_membarrier },
diff --git a/include/syscalls-i386.h b/include/syscalls-i386.h
index 147b1eb12607..316836406674 100644
--- a/include/syscalls-i386.h
+++ b/include/syscalls-i386.h
@@ -364,7 +364,11 @@ struct syscalltable syscalls_i386[] = {
{ .entry = &syscall_seccomp },
{ .entry = &syscall_getrandom },
{ .entry = &syscall_memfd_create },
+#ifdef USE_BPF
{ .entry = &syscall_bpf },
+#else
+ { .entry = NULL },
+#endif
{ .entry = &syscall_execveat },
{ .entry = &syscall_socket },
{ .entry = &syscall_socketpair },
diff --git a/include/syscalls-ia64.h b/include/syscalls-ia64.h
index 28eacce0ac3d..5efcb7d42f88 100644
--- a/include/syscalls-ia64.h
+++ b/include/syscalls-ia64.h
@@ -324,7 +324,11 @@ struct syscalltable syscalls_ia64[] = {
{ .entry = &syscall_renameat2 },
{ .entry = &syscall_getrandom },
{ .entry = &syscall_memfd_create },
+#ifdef USE_BPF
{ .entry = &syscall_bpf },
+#else
+ { .entry = NULL },
+#endif
{ .entry = &syscall_userfaultfd },
{ .entry = &syscall_membarrier },
{ .entry = &syscall_kcmp },
diff --git a/include/syscalls-mips.h b/include/syscalls-mips.h
index 273ba257db1c..26130f323f4a 100644
--- a/include/syscalls-mips.h
+++ b/include/syscalls-mips.h
@@ -371,5 +371,9 @@ struct syscalltable syscalls_mips[] = {
{ .entry = &syscall_seccomp },
{ .entry = &syscall_getrandom },
{ .entry = &syscall_memfd_create },
+#ifdef USE_BPF
{ .entry = &syscall_bpf }, /* 4355 */
+#else
+ { .entry = NULL },
+#endif
};
diff --git a/include/syscalls-parisc.h b/include/syscalls-parisc.h
index 8d164e501b12..2ac2d5f9513e 100644
--- a/include/syscalls-parisc.h
+++ b/include/syscalls-parisc.h
@@ -348,6 +348,10 @@ struct syscalltable syscalls_parisc[] = {
{ .entry = &syscall_seccomp },
{ .entry = &syscall_getrandom },
{ .entry = &syscall_memfd_create },
+#ifdef USE_BPF
{ .entry = &syscall_bpf },
+#else
+ { .entry = NULL },
+#endif
{ .entry = &syscall_execveat },
};
diff --git a/include/syscalls-s390.h b/include/syscalls-s390.h
index dd9c93aeae04..9916e6c6e772 100644
--- a/include/syscalls-s390.h
+++ b/include/syscalls-s390.h
@@ -358,7 +358,11 @@ struct syscalltable syscalls_s390[] = {
{ .entry = &syscall_seccomp },
{ .entry = &syscall_getrandom },
{ .entry = &syscall_memfd_create },
+#ifdef USE_BPF
{ .entry = &syscall_bpf },
+#else
+ { .entry = NULL },
+#endif
{ .entry = &syscall_ni_syscall }, // TODO: syscall_s390_pci_mmio_write
{ .entry = &syscall_ni_syscall }, // TODO: syscall_s390_pci_mmio_read
{ .entry = &syscall_execveat },
diff --git a/include/syscalls-s390x.h b/include/syscalls-s390x.h
index 6ddeb85ea39d..6dbaffb37397 100644
--- a/include/syscalls-s390x.h
+++ b/include/syscalls-s390x.h
@@ -358,7 +358,11 @@ struct syscalltable syscalls_s390x[] = {
{ .entry = &syscall_seccomp },
{ .entry = &syscall_getrandom },
{ .entry = &syscall_memfd_create },
+#ifdef USE_BPF
{ .entry = &syscall_bpf },
+#else
+ { .entry = NULL },
+#endif
{ .entry = &syscall_ni_syscall }, // TODO: syscall_s390_pci_mmio_write
{ .entry = &syscall_ni_syscall }, // TODO: syscall_s390_pci_mmio_read
{ .entry = &syscall_execveat },
diff --git a/include/syscalls-sparc.h b/include/syscalls-sparc.h
index 5cedd89b4fee..dbdd4e8d4620 100644
--- a/include/syscalls-sparc.h
+++ b/include/syscalls-sparc.h
@@ -356,6 +356,10 @@ struct syscalltable syscalls_sparc[] = {
{ .entry = &syscall_seccomp },
{ .entry = &syscall_getrandom },
{ .entry = &syscall_memfd_create },
+#ifdef USE_BPF
{ .entry = &syscall_bpf },
+#else
+ { .entry = NULL },
+#endif
{ .entry = &syscall_execveat },
};
diff --git a/include/syscalls-x86_64.h b/include/syscalls-x86_64.h
index c75f4dee142f..cc67889e7e23 100644
--- a/include/syscalls-x86_64.h
+++ b/include/syscalls-x86_64.h
@@ -328,7 +328,11 @@ struct syscalltable syscalls_x86_64[] = {
{ .entry = &syscall_seccomp },
{ .entry = &syscall_memfd_create },
{ .entry = &syscall_kexec_file_load },
+#ifdef USE_BPF
{ .entry = &syscall_bpf },
+#else
+ { .entry = NULL },
+#endif
{ .entry = &syscall_execveat },
{ .entry = &syscall_userfaultfd },
{ .entry = &syscall_membarrier },
diff --git a/syscalls/bpf.c b/syscalls/bpf.c
index b2f57d36feff..476a2778d8a0 100644
--- a/syscalls/bpf.c
+++ b/syscalls/bpf.c
@@ -1,6 +1,7 @@
/*
* SYSCALL_DEFINE3(bpf, int, cmd, union bpf_attr __user *, uattr, unsigned int, size)
*/
+#ifdef USE_BPF
#include <linux/bpf.h>
#include <linux/filter.h>
#include "arch.h"
@@ -102,3 +103,4 @@ struct syscallentry syscall_bpf = {
.sanitise = sanitise_bpf,
.post = post_bpf,
};
+#endif
diff --git a/tables-biarch.c b/tables-biarch.c
index 635aac966880..53e9b8330615 100644
--- a/tables-biarch.c
+++ b/tables-biarch.c
@@ -216,8 +216,12 @@ int setup_syscall_group_biarch(unsigned int group)
unsigned int i;
for_each_32bit_syscall(i) {
- if (syscalls_32bit[i].entry->group == group)
- toggle_syscall(syscalls_32bit[i].entry->name, TRUE);
+ struct syscallentry *entry = syscalls_32bit[i].entry;
+ if (entry == NULL)
+ continue;
+
+ if (entry->group == group)
+ toggle_syscall(entry->name, TRUE);
}
if (shm->nr_active_32bit_syscalls == 0)
@@ -227,8 +231,12 @@ int setup_syscall_group_biarch(unsigned int group)
/* now the 64 bit table*/
for_each_64bit_syscall(i) {
- if (syscalls_64bit[i].entry->group == group)
- toggle_syscall(syscalls_64bit[i].entry->name, TRUE);
+ struct syscallentry *entry = syscalls_64bit[i].entry;
+ if (entry == NULL)
+ continue;
+
+ if (entry->group == group)
+ toggle_syscall(entry->name, TRUE);
}
if (shm->nr_active_64bit_syscalls == 0) {
@@ -247,14 +255,20 @@ void mark_all_syscalls_active_biarch(void)
if (do_32_arch) {
for_each_32bit_syscall(i) {
- syscalls_32bit[i].entry->flags |= ACTIVE;
+ struct syscallentry *entry = syscalls_32bit[i].entry;
+ if (entry == NULL)
+ continue;
+ entry->flags |= ACTIVE;
activate_syscall32(i);
}
}
if (do_64_arch) {
for_each_64bit_syscall(i) {
- syscalls_64bit[i].entry->flags |= ACTIVE;
+ struct syscallentry *entry = syscalls_64bit[i].entry;
+ if (entry == NULL)
+ continue;
+ entry->flags |= ACTIVE;
activate_syscall64(i);
}
}
@@ -267,6 +281,9 @@ void init_syscalls_biarch(void)
for_each_64bit_syscall(i) {
entry = syscalls_64bit[i].entry;
+ if (entry == NULL)
+ continue;
+
if (entry->flags & ACTIVE)
if (entry->init)
entry->init();
@@ -274,6 +291,9 @@ void init_syscalls_biarch(void)
for_each_32bit_syscall(i) {
entry = syscalls_32bit[i].entry;
+ if (entry == NULL)
+ continue;
+
if (entry->flags & ACTIVE)
if (entry->init)
entry->init();
@@ -287,6 +307,9 @@ void deactivate_disabled_syscalls_biarch(void)
for_each_64bit_syscall(i) {
entry = syscalls_64bit[i].entry;
+ if (entry == NULL)
+ continue;
+
if (entry->flags & TO_BE_DEACTIVATED) {
entry->flags &= ~(ACTIVE|TO_BE_DEACTIVATED);
deactivate_syscall64(i);
@@ -297,6 +320,9 @@ void deactivate_disabled_syscalls_biarch(void)
for_each_32bit_syscall(i) {
entry = syscalls_32bit[i].entry;
+ if (entry == NULL)
+ continue;
+
if (entry->flags & TO_BE_DEACTIVATED) {
entry->flags &= ~(ACTIVE|TO_BE_DEACTIVATED);
deactivate_syscall32(i);
@@ -316,6 +342,9 @@ void dump_syscall_tables_biarch(void)
for_each_32bit_syscall(i) {
entry = syscalls_32bit[i].entry;
+ if (entry == NULL)
+ continue;
+
outputstd("entrypoint %d %s : [32-bit] ",
entry->number, entry->name);
show_state(entry->flags & ACTIVE);
@@ -328,6 +357,8 @@ void dump_syscall_tables_biarch(void)
for_each_64bit_syscall(i) {
entry = syscalls_64bit[i].entry;
+ if (entry == NULL)
+ continue;
outputstd("entrypoint %d %s : [64-bit] ",
entry->number, entry->name);
@@ -347,12 +378,18 @@ void display_enabled_syscalls_biarch(void)
for_each_64bit_syscall(i) {
entry = syscalls_64bit[i].entry;
+ if (entry == NULL)
+ continue;
+
if (entry->flags & ACTIVE)
output(0, "64-bit syscall %d:%s enabled.\n", i, entry->name);
}
for_each_32bit_syscall(i) {
entry = syscalls_32bit[i].entry;
+ if (entry == NULL)
+ continue;
+
if (entry->flags & ACTIVE)
output(0, "32-bit syscall %d:%s enabled.\n", i, entry->name);
}
diff --git a/tables-uniarch.c b/tables-uniarch.c
index 8f6bcd6553e1..5ba385e6fb74 100644
--- a/tables-uniarch.c
+++ b/tables-uniarch.c
@@ -100,7 +100,11 @@ void mark_all_syscalls_active_uniarch(void)
unsigned int i;
for_each_syscall(i) {
- syscalls[i].entry->flags |= ACTIVE;
+ struct syscallentry *entry = syscalls[i].entry;
+ if (entry == NULL)
+ continue;
+
+ entry->flags |= ACTIVE;
activate_syscall(i);
}
}
@@ -110,9 +114,10 @@ void init_syscalls_uniarch(void)
unsigned int i;
for_each_syscall(i) {
- struct syscallentry *entry;
+ struct syscallentry *entry = syscalls[i].entry;
+ if (entry == NULL)
+ continue;
- entry = syscalls[i].entry;
if (entry->flags & ACTIVE)
if (entry->init)
entry->init();
@@ -124,9 +129,11 @@ void deactivate_disabled_syscalls_uniarch(void)
unsigned int i;
for_each_syscall(i) {
- struct syscallentry *entry;
+ struct syscallentry *entry = syscalls[i].entry;
+
+ if (entry == NULL)
+ continue;
- entry = syscalls[i].entry;
if (entry->flags & TO_BE_DEACTIVATED) {
entry->flags &= ~(ACTIVE|TO_BE_DEACTIVATED);
deactivate_syscall_uniarch(i);
@@ -143,9 +150,11 @@ void dump_syscall_tables_uniarch(void)
outputstd("syscalls: %d\n", max_nr_syscalls);
for_each_syscall(i) {
- struct syscallentry *entry;
+ struct syscallentry *entry = syscalls[i].entry;
+
+ if (entry == NULL)
+ continue;
- entry = syscalls[i].entry;
outputstd("entrypoint %d %s : ", entry->number, entry->name);
show_state(entry->flags & ACTIVE);
if (entry->flags & AVOID_SYSCALL)
@@ -159,9 +168,10 @@ void display_enabled_syscalls_uniarch(void)
unsigned int i;
for_each_syscall(i) {
- struct syscallentry *entry;
+ struct syscallentry *entry = syscalls[i].entry;
- entry = syscalls[i].entry;
+ if (entry == NULL)
+ continue;
if (entry->flags & ACTIVE)
output(0, "syscall %d:%s enabled.\n", i, entry->name);
diff --git a/tables.c b/tables.c
index 7d5d35b7d2fa..8d3f4d7d8a6e 100644
--- a/tables.c
+++ b/tables.c
@@ -211,6 +211,8 @@ static void check_syscall(struct syscallentry *entry)
{
/* check that we have a name set. */
#define CHECK(NUMARGS, ARGNUM, ARGTYPE, ARGNAME) \
+ if (entry == NULL) \
+ return; \
if (entry->num_args > 0) { \
if (entry->num_args > NUMARGS) { \
if (entry->ARGNAME == NULL) { \
@@ -231,6 +233,8 @@ static void check_syscall(struct syscallentry *entry)
/* note: not enabled by default, because we haven't annotated everything yet. */
#undef CHECK
#define CHECK(NUMARGS, ARGNUM, ARGTYPE, ARGNAME) \
+ if (entry == NULL) \
+ return; \
if (entry->num_args > 0) { \
if (entry->num_args > NUMARGS) { \
if (entry->ARGTYPE == ARG_UNDEFINED) { \
@@ -379,6 +383,9 @@ static void show_unannotated_biarch(void)
for_each_32bit_syscall(i) {
entry = syscalls_32bit[i].entry;
+ if (entry == NULL)
+ continue;
+
count = 0;
for (j = 1; j <= entry->num_args; j++) {
@@ -415,6 +422,9 @@ static void show_unannotated_biarch(void)
for_each_64bit_syscall(i) {
entry = syscalls_64bit[i].entry;
+ if (entry == NULL)
+ continue;
+
count = 0;
for (j = 1; j <= entry->num_args; j++) {
@@ -469,18 +479,24 @@ void show_unannotated_args(void)
*/
static struct syscalltable * copy_syscall_table(struct syscalltable *from, unsigned int nr)
{
- unsigned int n;
+ unsigned int n, m;
struct syscallentry *copy;
copy = alloc_shared(nr * sizeof(struct syscallentry));
if (copy == NULL)
exit(EXIT_FAILURE);
- for (n = 0; n < nr; n++) {
- memcpy(copy + n , from[n].entry, sizeof(struct syscallentry));
- copy[n].number = n;
- copy[n].active_number = 0;
- from[n].entry = ©[n];
+ for (n = 0, m = 0; n < nr; n++) {
+ struct syscallentry *entry = from[n].entry;
+
+ if (entry == NULL)
+ continue;
+
+ memcpy(copy + m , from[n].entry, sizeof(struct syscallentry));
+ copy[m].number = n;
+ copy[m].active_number = 0;
+ from[n].entry = ©[m];
+ m++;
}
return from;
}
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2] Fix build on older kernels without BPF.
2016-08-04 20:36 ` Dave Jones
@ 2016-08-05 18:44 ` Dave Jones
0 siblings, 0 replies; 8+ messages in thread
From: Dave Jones @ 2016-08-05 18:44 UTC (permalink / raw)
To: Vinson Lee; +Cc: trinity
On Thu, Aug 04, 2016 at 04:36:06PM -0400, Dave Jones wrote:
> > We might segv somewhere else after patching this up. It's been so long since
> > I touched this stuff I don't fully recall how it works. I'll poke at it
> > some tomorrow.
>
> Just getting around to this. It's a bit more involved than I hoped.
> Spraying a bunch of null checks around like this seems to be the thing to do..
Now committed and pushed out, with an additional typo fix.
Dave
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2016-08-05 18:44 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-12 18:43 [PATCH] Fix build on older kernels without BPF Vinson Lee
2016-07-12 19:02 ` Dave Jones
2016-07-12 21:33 ` [PATCH v2] " Vinson Lee
2016-07-21 20:10 ` Dave Jones
2016-07-26 0:24 ` Vinson Lee
2016-07-26 0:59 ` Dave Jones
2016-08-04 20:36 ` Dave Jones
2016-08-05 18:44 ` Dave Jones
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).