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

Brad Figg brad.figg at canonical.com
Tue Mar 1 17:47:05 UTC 2016


From: Kees Cook <keescook at 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 at chromium.org>
Reported-by: Dmitry V. Levin <ldv at altlinux.org>
Cc: Andy Lutomirski <luto at amacapital.net>
Cc: Will Drewry <wad at chromium.org>
Signed-off-by: Andrew Morton <akpm at linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
Signed-off-by: Brad Figg <brad.figg at canonical.com>
---
 kernel/seccomp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

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;
-- 
2.7.0





More information about the kernel-team mailing list