diff options
| author | Kees Cook <keescook@chromium.org> | 2014-06-25 18:38:02 -0400 |
|---|---|---|
| committer | Kees Cook <keescook@chromium.org> | 2014-07-18 15:13:36 -0400 |
| commit | 1f41b450416e689b9b7c8bfb750a98604f687a9b (patch) | |
| tree | f3429ad4a8e75c3e1f601af95113e19f88da4560 /kernel | |
| parent | d78ab02c2c194257a03355fbb79eb721b381d105 (diff) | |
seccomp: extract check/assign mode helpers
To support splitting mode 1 from mode 2, extract the mode checking and
assignment logic into common functions.
Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Oleg Nesterov <oleg@redhat.com>
Reviewed-by: Andy Lutomirski <luto@amacapital.net>
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/seccomp.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/kernel/seccomp.c b/kernel/seccomp.c index afb916c7e890..9df7def86c3b 100644 --- a/kernel/seccomp.c +++ b/kernel/seccomp.c | |||
| @@ -194,7 +194,23 @@ static u32 seccomp_run_filters(int syscall) | |||
| 194 | } | 194 | } |
| 195 | return ret; | 195 | return ret; |
| 196 | } | 196 | } |
| 197 | #endif /* CONFIG_SECCOMP_FILTER */ | ||
| 197 | 198 | ||
| 199 | static inline bool seccomp_may_assign_mode(unsigned long seccomp_mode) | ||
| 200 | { | ||
| 201 | if (current->seccomp.mode && current->seccomp.mode != seccomp_mode) | ||
| 202 | return false; | ||
| 203 | |||
| 204 | return true; | ||
| 205 | } | ||
| 206 | |||
| 207 | static inline void seccomp_assign_mode(unsigned long seccomp_mode) | ||
| 208 | { | ||
| 209 | current->seccomp.mode = seccomp_mode; | ||
| 210 | set_tsk_thread_flag(current, TIF_SECCOMP); | ||
| 211 | } | ||
| 212 | |||
| 213 | #ifdef CONFIG_SECCOMP_FILTER | ||
| 198 | /** | 214 | /** |
| 199 | * seccomp_attach_filter: Attaches a seccomp filter to current. | 215 | * seccomp_attach_filter: Attaches a seccomp filter to current. |
| 200 | * @fprog: BPF program to install | 216 | * @fprog: BPF program to install |
| @@ -490,8 +506,7 @@ static long seccomp_set_mode(unsigned long seccomp_mode, char __user *filter) | |||
| 490 | { | 506 | { |
| 491 | long ret = -EINVAL; | 507 | long ret = -EINVAL; |
| 492 | 508 | ||
| 493 | if (current->seccomp.mode && | 509 | if (!seccomp_may_assign_mode(seccomp_mode)) |
| 494 | current->seccomp.mode != seccomp_mode) | ||
| 495 | goto out; | 510 | goto out; |
| 496 | 511 | ||
| 497 | switch (seccomp_mode) { | 512 | switch (seccomp_mode) { |
| @@ -512,8 +527,7 @@ static long seccomp_set_mode(unsigned long seccomp_mode, char __user *filter) | |||
| 512 | goto out; | 527 | goto out; |
| 513 | } | 528 | } |
| 514 | 529 | ||
| 515 | current->seccomp.mode = seccomp_mode; | 530 | seccomp_assign_mode(seccomp_mode); |
| 516 | set_thread_flag(TIF_SECCOMP); | ||
| 517 | out: | 531 | out: |
| 518 | return ret; | 532 | return ret; |
| 519 | } | 533 | } |
