Skip to contentSkip to conversation

eBPF Seccomp filters

PATCH Tom Hromatka 4 participants 5 messages Feb 13, 2018 2 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw
Quoted 10 lines · Sargun Dhillon

This patchset enables seccomp filters to be written in eBPF. Although, this patchset doesn't introduce much of the functionality enabled by eBPF, it lays the ground work for it.

It also introduces the capability to dump eBPF filters via the PTRACE API in order to make it so that CHECKPOINT_RESTORE will be satisifed. In the attached samples, there's an example of this. One can then use BPF_OBJ_GET_INFO_BY_FD in order to get the actual code of the program, and use that at reload time.

Quoted 7 lines

The primary reason for not adding maps support in this patchset is to avoid introducing new complexities around PR_SET_NO_NEW_PRIVS. If we have a map that the BPF program can read, it can potentially "change" privileges after running. It seems like doing writes only is safe, because it can be pure, and side effect free, and therefore not negatively effect PR_SET_NO_NEW_PRIVS. Nonetheless, if we come to an agreement, this can be in a follow-up patchset.

Coincidentally I also sent an RFC for adding eBPF hash maps to the seccomp userspace mailing list just last week:
https://groups.google.com/forum/#!topic/libseccomp/pX6QkVF0F74

The kernel changes I proposed are in this email:
https://groups.google.com/d/msg/libseccomp/pX6QkVF0F74/ZUJlwI5qAwAJ

In that email thread, Kees requested that I try out a binary tree in cBPF and evaluate its performance. I just got a rough prototype working, and while not as fast as an eBPF hash map, the cBPF binary tree was a significant improvement over the linear list of ifs that are currently generated. Also, it only required changing a single function within the libseccomp libary itself.

https://github.com/drakenclimber/libseccomp/commit/87b36369f17385f5a7a4d95101185577fbf6203b

Here are the results I am currently seeing using an in-house customer's seccomp filter and a simplistic test program that runs getppid() thousands of times.

Test Case minimum TSC ticks to make syscall
----------------------------------------------------------------
seccomp disabled 620
getppid() at the front of 306-syscall seccomp filter 722
getppid() in middle of 306-syscall seccomp filter 1392
getppid() at the end of the 306-syscall filter 2452
seccomp using a 306-syscall-sized EBPF hash map 800
cBPF filter using a binary tree 922

Thanks.

Tom

A message that is not in the archive (sent off-list or not yet received): 7eb1497e-e5f3-c5ba-e255-7f510795b51d-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org

#2 lore raw
Quoted 43 lines · Tom Hromatka
Quoted 11 lines · Sargun Dhillon

This patchset enables seccomp filters to be written in eBPF. Although, this patchset doesn't introduce much of the functionality enabled by eBPF, it lays the ground work for it.

It also introduces the capability to dump eBPF filters via the PTRACE API in order to make it so that CHECKPOINT_RESTORE will be satisifed. In the attached samples, there's an example of this. One can then use BPF_OBJ_GET_INFO_BY_FD in order to get the actual code of the program, and use that at reload time.

Quoted 7 lines

The primary reason for not adding maps support in this patchset is to avoid introducing new complexities around PR_SET_NO_NEW_PRIVS. If we have a map that the BPF program can read, it can potentially "change" privileges after running. It seems like doing writes only is safe, because it can be pure, and side effect free, and therefore not negatively effect PR_SET_NO_NEW_PRIVS. Nonetheless, if we come to an agreement, this can be in a follow-up patchset.

Coincidentally I also sent an RFC for adding eBPF hash maps to the seccomp userspace mailing list just last week:
https://groups.google.com/forum/#!topic/libseccomp/pX6QkVF0F74

The kernel changes I proposed are in this email:
https://groups.google.com/d/msg/libseccomp/pX6QkVF0F74/ZUJlwI5qAwAJ

In that email thread, Kees requested that I try out a binary tree in cBPF and evaluate its performance. I just got a rough prototype working, and while not as fast as an eBPF hash map, the cBPF binary tree was a significant
improvement over the linear list of ifs that are currently generated. Also, it only required changing a single function within the libseccomp libary itself.

https://github.com/drakenclimber/libseccomp/commit/87b36369f17385f5a7a4d95101185577fbf6203b

Here are the results I am currently seeing using an in-house customer's seccomp filter and a simplistic test program that runs getppid() thousands of times.

Quoted 8 lines

Test Case minimum TSC ticks to make syscall
----------------------------------------------------------------
seccomp disabled 620
getppid() at the front of 306-syscall seccomp filter 722
getppid() in middle of 306-syscall seccomp filter 1392
getppid() at the end of the 306-syscall filter 2452
seccomp using a 306-syscall-sized EBPF hash map 800
cBPF filter using a binary tree 922

I still think that's a crazy filter. :) It should be inverted to just check the 26 syscalls and a final "greater than" test. I would expect it to be faster still. :)

-Kees

Signature · 2 lines
Kees Cook
Pixel Security
#3 lore raw
In reply to Tom Hromatka
Quoted 43 lines · Tom Hromatka
Quoted 11 lines · Sargun Dhillon

This patchset enables seccomp filters to be written in eBPF. Although, this patchset doesn't introduce much of the functionality enabled by eBPF, it lays the ground work for it.

It also introduces the capability to dump eBPF filters via the PTRACE API in order to make it so that CHECKPOINT_RESTORE will be satisifed. In the attached samples, there's an example of this. One can then use BPF_OBJ_GET_INFO_BY_FD in order to get the actual code of the program, and use that at reload time.

Quoted 7 lines

The primary reason for not adding maps support in this patchset is to avoid introducing new complexities around PR_SET_NO_NEW_PRIVS. If we have a map that the BPF program can read, it can potentially "change" privileges after running. It seems like doing writes only is safe, because it can be pure, and side effect free, and therefore not negatively effect PR_SET_NO_NEW_PRIVS. Nonetheless, if we come to an agreement, this can be in a follow-up patchset.

Coincidentally I also sent an RFC for adding eBPF hash maps to the seccomp userspace mailing list just last week:
https://groups.google.com/forum/#!topic/libseccomp/pX6QkVF0F74

The kernel changes I proposed are in this email:
https://groups.google.com/d/msg/libseccomp/pX6QkVF0F74/ZUJlwI5qAwAJ

In that email thread, Kees requested that I try out a binary tree in cBPF and evaluate its performance. I just got a rough prototype working, and while not as fast as an eBPF hash map, the cBPF binary tree was a significant
improvement over the linear list of ifs that are currently generated. Also, it only required changing a single function within the libseccomp libary itself.

https://github.com/drakenclimber/libseccomp/commit/87b36369f17385f5a7a4d95101185577fbf6203b

Here are the results I am currently seeing using an in-house customer's seccomp filter and a simplistic test program that runs getppid() thousands of times.

Quoted 8 lines

Test Case minimum TSC ticks to make syscall
----------------------------------------------------------------
seccomp disabled 620
getppid() at the front of 306-syscall seccomp filter 722
getppid() in middle of 306-syscall seccomp filter 1392
getppid() at the end of the 306-syscall filter 2452
seccomp using a 306-syscall-sized EBPF hash map 800
cBPF filter using a binary tree 922

I still think that's a crazy filter. :) It should be inverted to just check the 26 syscalls and a final "greater than" test. I would expect it to be faster still. :)

-Kees

Signature · 2 lines
Kees Cook
Pixel Security

A message that is not in the archive (sent off-list or not yet received): CAGXu5jJZgrgLrhkZO33RNdOds8zwnnOZh+rqwguxJM+zm=EJ7g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#5 lore raw
Quoted 50 lines · Kees Cook
Quoted 41 lines · Tom Hromatka
Quoted 10 lines · Sargun Dhillon

This patchset enables seccomp filters to be written in eBPF. Although, this patchset doesn't introduce much of the functionality enabled by eBPF, it lays the ground work for it.

It also introduces the capability to dump eBPF filters via the PTRACE API in order to make it so that CHECKPOINT_RESTORE will be satisifed. In the attached samples, there's an example of this. One can then use BPF_OBJ_GET_INFO_BY_FD in order to get the actual code of the program, and use that at reload time.

Quoted 7 lines

The primary reason for not adding maps support in this patchset is to avoid introducing new complexities around PR_SET_NO_NEW_PRIVS. If we have a map that the BPF program can read, it can potentially "change" privileges after running. It seems like doing writes only is safe, because it can be pure, and side effect free, and therefore not negatively effect PR_SET_NO_NEW_PRIVS. Nonetheless, if we come to an agreement, this can be in a follow-up patchset.

Coincidentally I also sent an RFC for adding eBPF hash maps to the seccomp userspace mailing list just last week:
https://groups.google.com/forum/#!topic/libseccomp/pX6QkVF0F74

The kernel changes I proposed are in this email:
https://groups.google.com/d/msg/libseccomp/pX6QkVF0F74/ZUJlwI5qAwAJ

In that email thread, Kees requested that I try out a binary tree in cBPF and evaluate its performance. I just got a rough prototype working, and while not as fast as an eBPF hash map, the cBPF binary tree was a significant
improvement over the linear list of ifs that are currently generated. Also, it only required changing a single function within the libseccomp libary itself.

https://github.com/drakenclimber/libseccomp/commit/87b36369f17385f5a7a4d95101185577fbf6203b

Here are the results I am currently seeing using an in-house customer's seccomp filter and a simplistic test program that runs getppid() thousands of times.

Quoted 8 lines

Test Case minimum TSC ticks to make syscall
----------------------------------------------------------------
seccomp disabled 620
getppid() at the front of 306-syscall seccomp filter 722
getppid() in middle of 306-syscall seccomp filter 1392
getppid() at the end of the 306-syscall filter 2452
seccomp using a 306-syscall-sized EBPF hash map 800
cBPF filter using a binary tree 922

Quoted 5 lines

I still think that's a crazy filter. :) It should be inverted to just check the 26 syscalls and a final "greater than" test. I would expect it to be faster still. :)

-Kees

I completely agree it's a crazy filter, but it seems to be a common "mistake" our users are making.  It would be nice to help them out if we can.

Tom

_______________________________________________
Containers mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/containers

#6 lore raw
In reply to Kees Cook
Quoted 50 lines · Kees Cook
Quoted 41 lines · Tom Hromatka
Quoted 10 lines · Sargun Dhillon

This patchset enables seccomp filters to be written in eBPF. Although, this patchset doesn't introduce much of the functionality enabled by eBPF, it lays the ground work for it.

It also introduces the capability to dump eBPF filters via the PTRACE API in order to make it so that CHECKPOINT_RESTORE will be satisifed. In the attached samples, there's an example of this. One can then use BPF_OBJ_GET_INFO_BY_FD in order to get the actual code of the program, and use that at reload time.

Quoted 7 lines

The primary reason for not adding maps support in this patchset is to avoid introducing new complexities around PR_SET_NO_NEW_PRIVS. If we have a map that the BPF program can read, it can potentially "change" privileges after running. It seems like doing writes only is safe, because it can be pure, and side effect free, and therefore not negatively effect PR_SET_NO_NEW_PRIVS. Nonetheless, if we come to an agreement, this can be in a follow-up patchset.

Coincidentally I also sent an RFC for adding eBPF hash maps to the seccomp userspace mailing list just last week:
https://groups.google.com/forum/#!topic/libseccomp/pX6QkVF0F74

The kernel changes I proposed are in this email:
https://groups.google.com/d/msg/libseccomp/pX6QkVF0F74/ZUJlwI5qAwAJ

In that email thread, Kees requested that I try out a binary tree in cBPF and evaluate its performance. I just got a rough prototype working, and while not as fast as an eBPF hash map, the cBPF binary tree was a significant
improvement over the linear list of ifs that are currently generated. Also, it only required changing a single function within the libseccomp libary itself.

https://github.com/drakenclimber/libseccomp/commit/87b36369f17385f5a7a4d95101185577fbf6203b

Here are the results I am currently seeing using an in-house customer's seccomp filter and a simplistic test program that runs getppid() thousands of times.

Quoted 8 lines

Test Case minimum TSC ticks to make syscall
----------------------------------------------------------------
seccomp disabled 620
getppid() at the front of 306-syscall seccomp filter 722
getppid() in middle of 306-syscall seccomp filter 1392
getppid() at the end of the 306-syscall filter 2452
seccomp using a 306-syscall-sized EBPF hash map 800
cBPF filter using a binary tree 922

Quoted 5 lines

I still think that's a crazy filter. :) It should be inverted to just check the 26 syscalls and a final "greater than" test. I would expect it to be faster still. :)

-Kees

I completely agree it's a crazy filter, but it seems to be a common "mistake" our users are making.  It would be nice to help them out if we can.

Tom