Skip to contentSkip to conversation

net: add generation of semi-random BPF filters

PATCH In review Daniel Borkmann 2 participants 4 messages May 16, 2013 Networking

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: add generation of semi-random BPF filters

BPF filters are used in networking and in application sand-boxing and even have a arch-dependant JIT compiler in the kernel, so add a more detailed semi-random BPF generator.

---
Compile-tested only!

 include/net.h         |   3 +
 net/bpf.c             | 205 ++++++++++++++++++++++++++++++++++++++++++++++++++
 syscalls/setsockopt.c |   2 +
 3 files changed, 210 insertions(+)
 create mode 100644 net/bpf.c
include/net.h +3 -0
index e14430c..256533c 100644
@@ -35,6 +35,9 @@ void gen_pppox(unsigned long *addr, unsigned long *addrlen);
 /* unix */
 void gen_unixsock(unsigned long *addr, unsigned long *addrlen);
 
+/* bpf */
+void gen_bpf(unsigned long *addr, unsigned long *addrlen);
+
 /* caif */
 void gen_caif(unsigned long *addr, unsigned long *addrlen);
 
net/bpf.c new file +205 -0

205 lines not on this page · raw message

syscalls/setsockopt.c +2 -0
index 1c18847..43ffb05 100644
@@ -9,6 +9,7 @@
 #include "compat.h"
 #include "maps.h"
 #include "shm.h"
+#include "net.h"
 #include "config.h"
 #include "syscalls/setsockopt.h"
 
@@ -84,6 +85,7 @@ void sanitise_setsockopt(int childno)
 			shm->a5[childno] = sizeof(struct timeval);
 			break;
 		case SO_ATTACH_FILTER:
+			gen_bpf((unsigned long *) page_rand, NULL);
 			shm->a5[childno] = sizeof(struct sock_fprog);
 			break;
 		default:
Signature · 1 line
1.7.11.7
#1 lore raw
Quoted 7 lines · Daniel Borkmann

BPF filters are used in networking and in application sand-boxing and even have a arch-dependant JIT compiler in the kernel, so add a more detailed semi-random BPF generator.

---
Compile-tested only!

Very nice.

merged and pushed.

thanks,

Dave

#2 lore raw
Quoted 5 lines · Dave Jones
Quoted 4 lines · Daniel Borkmann

BPF filters are used in networking and in application sand-boxing and even have a arch-dependant JIT compiler in the kernel, so add a more detailed semi-random BPF generator.

Quoted 7 lines
Quoted 3 lines

---
Compile-tested only!

Very nice.

merged and pushed.

Thanks, just for the record, in case someone might need this e.g. when trinity hits here ... in the kernel source tree under tools/net/ is a BPF JIT disassembler.

Quoted 4 lines

thanks,

Dave

#3 lore raw
Quoted 10 lines · Daniel Borkmann
Quoted 9 lines · Dave Jones
Quoted 7 lines · Daniel Borkmann

BPF filters are used in networking and in application sand-boxing and even have a arch-dependant JIT compiler in the kernel, so add a more detailed semi-random BPF generator.

---
Compile-tested only!

Quoted 7 lines
Quoted 3 lines

Very nice.

merged and pushed.

Thanks, just for the record, in case someone might need this e.g. when trinity hits here ... in the kernel source tree under tools/net/ is a BPF JIT disassembler.

Hmm, I suppose at some point I should add some way of dumping page_rand too. Given that can be changed by multiple processes at the same time though, it's a bit of a mess. Also it would be spamming the hell out of the logs.

Perhaps instead of page_rand, the bpf code should do it's own allocation and then we have a pre-do-syscall hook to do hexdumping of allocations.

This is another case where we really need some post-syscall cleanup operations too, to free the allocation. (There are a few of these, grep for leak in syscalls/)

I'm probably going to cut a 1.2 release later this month when I get back from vacation, because it's been a while, and things are pretty quiet right now, and this stuff is probably going to be for after that.

Dave