From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755963AbbBFVDY (ORCPT ); Fri, 6 Feb 2015 16:03:24 -0500 Received: from smtp.outflux.net ([198.145.64.163]:40624 "EHLO smtp.outflux.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753082AbbBFVDW (ORCPT ); Fri, 6 Feb 2015 16:03:22 -0500 Date: Fri, 6 Feb 2015 13:03:09 -0800 From: Kees Cook To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, Andy Lutomirski , Will Drewry , "Dmitry V. Levin" Subject: [PATCH] seccomp: cap SECCOMP_RET_ERRNO data to MAX_ERRNO Message-ID: <20150206210309.GA32377@www.outflux.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-HELO: www.outflux.net Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.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. Reported-by: Dmitry V. Levin Signed-off-by: Kees Cook --- kernel/seccomp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel/seccomp.c b/kernel/seccomp.c index 4ef9687ac115..4f44028943e6 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; -- 1.9.1 -- Kees Cook Chrome OS Security