From: Kees Cook Date: Tue, 17 Feb 2015 21:48:00 +0000 (-0800) Subject: seccomp: cap SECCOMP_RET_ERRNO data to MAX_ERRNO X-Git-Tag: v4.9.8~4784^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=580c57f1076872ebc2427f898b927944ce170f2d;p=platform%2Fkernel%2Flinux-rpi3.git 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 Reported-by: Dmitry V. Levin Cc: Andy Lutomirski Cc: Will Drewry Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/kernel/seccomp.c b/kernel/seccomp.c index 4ef9687..4f44028 100644 --- a/kernel/seccomp.c +++ b/kernel/seccomp.c @@ -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;