UPSTREAM: seccomp: cap SECCOMP_RET_ERRNO data to MAX_ERRNO

The value resulting from the SECCOMP_RET_DATA mask could exceed MAX_ERRNO
when setting errno during a SECCOMP_RET_ERRNO filter action.  This makes
sure we have a reliable value being set, so that an invalid errno will not
be ignored by userspace.

Signed-off-by: Kees Cook <keescook@chromium.org>
Reported-by: Dmitry V. Levin <ldv@altlinux.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Will Drewry <wad@chromium.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

(cherry picked from commit 580c57f1076872ebc2427f898b927944ce170f2d)
Signed-off-by: Kees Cook <keescook@google.com>
Change-Id: I069b2e858c626283819b9f0fc308c35c3c847b55
This commit is contained in:
Kees Cook 2015-02-17 13:48:00 -08:00 committed by Srinivasarao P
parent 59b22ca066
commit fb0ef85108
1 changed files with 3 additions and 1 deletions

View File

@ -600,7 +600,9 @@ int __secure_computing(int this_syscall)
ret &= SECCOMP_RET_ACTION;
switch (ret) {
case SECCOMP_RET_ERRNO:
/* Set the low-order 16-bits as a errno. */
/* Set low-order bits as an errno, capped at MAX_ERRNO. */
if (data > MAX_ERRNO)
data = MAX_ERRNO;
syscall_set_return_value(current, regs,
-data, 0);
goto skip;