BACKPORT: seccomp: split filter prep from check and apply

In preparation for adding seccomp locking, move filter creation away
from where it is checked and applied. This will allow for locking where
no memory allocation is happening. The validation, filter attachment,
and seccomp mode setting can all happen under the future locks.

For extreme defensiveness, I've added a BUG_ON check for the calculated
size of the buffer allocation in case BPF_MAXINSN ever changes, which
shouldn't ever happen. The compiler should actually optimize out this
check since the test above it makes it impossible.

Signed-off-by: Kees Cook <>
Reviewed-by: Oleg Nesterov <>
Reviewed-by: Andy Lutomirski <>


Bug: 28020023
Patchset: seccomp

(cherry picked from kernel/msm commit 25b84f016ab6096061963821914fe062757829f4)
Signed-off-by: Kees Cook <>
Change-Id: Iea5bea468827cd16024a5b1ab01bc18a1c6b80b4
1 file changed