Skip to content

Commit

Permalink
ptrace, seccomp: tweak get_metadata behavior slightly
Browse files Browse the repository at this point in the history
Previously if users passed a small size for the input structure size, they
would get get odd behavior. It doesn't make sense to pass a structure
smaller than at least filter_off size, so let's just give -EINVAL in this
case.

This changes userspace visible behavior, but was only introduced in commit
2650047 ("ptrace, seccomp: add support for retrieving seccomp
metadata") in 4.16-rc2, so should be safe to change if merged before then.

Reported-by: Eugene Syromiatnikov <esyr@redhat.com>
Signed-off-by: Tycho Andersen <tycho@tycho.ws>
CC: Kees Cook <keescook@chromium.org>
CC: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
  • Loading branch information
tych0 authored and kees committed Feb 22, 2018
1 parent 2a040f9 commit 63bb004
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions kernel/seccomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1076,14 +1076,16 @@ long seccomp_get_metadata(struct task_struct *task,

size = min_t(unsigned long, size, sizeof(kmd));

if (copy_from_user(&kmd, data, size))
if (size < sizeof(kmd.filter_off))
return -EINVAL;

if (copy_from_user(&kmd.filter_off, data, sizeof(kmd.filter_off)))
return -EFAULT;

filter = get_nth_filter(task, kmd.filter_off);
if (IS_ERR(filter))
return PTR_ERR(filter);

memset(&kmd, 0, sizeof(kmd));
if (filter->log)
kmd.flags |= SECCOMP_FILTER_FLAG_LOG;

Expand Down

0 comments on commit 63bb004

Please sign in to comment.