diff mbox

[1/1] seccomp: cap SECCOMP_RET_ERRNO data to MAX_ERRNO

Message ID 1456854425-64879-2-git-send-email-brad.figg@canonical.com
State New
Headers show

Commit Message

Brad Figg March 1, 2016, 5:47 p.m. UTC
From: Kees Cook <keescook@chromium.org>

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>
Signed-off-by: Brad Figg <brad.figg@canonical.com>
---
 kernel/seccomp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Tim Gardner March 1, 2016, 5:55 p.m. UTC | #1

diff mbox

Patch

diff --git a/kernel/seccomp.c b/kernel/seccomp.c
index bdaa55d..05e5c05 100644
--- a/kernel/seccomp.c
+++ b/kernel/seccomp.c
@@ -595,7 +595,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;