Skip to contentSkip to conversation

seccomp: cap SECCOMP_RET_ERRNO data to MAX_ERRNO

PATCH In review Kees Cook 2 participants 2 messages Feb 6, 2015 Secure computing

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 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.

---
 kernel/seccomp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/seccomp.c +3 -1
index 4ef9687ac115..4f44028943e6 100644
@@ -629,7 +629,9 @@ static u32 __seccomp_phase1_filter(int this_syscall, struct seccomp_data *sd)
 
 	switch (action) {
 	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, task_pt_regs(current),
 					 -data, 0);
 		goto skip;
Signature · 6 lines
1.9.1


-- 
Kees Cook
Chrome OS Security
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Kees Cook

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.

Signature · 1 line
ldv