From patchwork Thu Aug 25 10:32:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Micka=C3=ABl_Sala=C3=BCn?= X-Patchwork-Id: 9299211 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A07BA60459 for ; Thu, 25 Aug 2016 10:48:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8FAE3291F7 for ; Thu, 25 Aug 2016 10:48:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 831A329252; Thu, 25 Aug 2016 10:48:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E635291F7 for ; Thu, 25 Aug 2016 10:48:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933887AbcHYKpv (ORCPT ); Thu, 25 Aug 2016 06:45:51 -0400 Received: from smtp-sh.infomaniak.ch ([128.65.195.4]:41943 "EHLO smtp-sh.infomaniak.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933653AbcHYKps (ORCPT ); Thu, 25 Aug 2016 06:45:48 -0400 Received: from smtp6.infomaniak.ch (smtp6.infomaniak.ch [83.166.132.19]) by smtp-sh.infomaniak.ch (8.14.5/8.14.5) with ESMTP id u7PAYdt2026571 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 25 Aug 2016 12:34:39 +0200 Received: from localhost (ns3096276.ip-94-23-54.eu [94.23.54.103]) (authenticated bits=0) by smtp6.infomaniak.ch (8.14.5/8.14.5) with ESMTP id u7PAYcf3002700; Thu, 25 Aug 2016 12:34:38 +0200 From: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= To: linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Alexei Starovoitov , Andy Lutomirski , Arnd Bergmann , Casey Schaufler , Daniel Borkmann , Daniel Mack , David Drysdale , "David S . Miller" , Elena Reshetova , James Morris , Kees Cook , Paul Moore , Sargun Dhillon , "Serge E . Hallyn" , Will Drewry , kernel-hardening@lists.openwall.com, linux-api@vger.kernel.org, linux-security-module@vger.kernel.org, netdev@vger.kernel.org Subject: [RFC v2 07/10] landlock: Add errno check Date: Thu, 25 Aug 2016 12:32:42 +0200 Message-Id: <1472121165-29071-8-git-send-email-mic@digikod.net> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1472121165-29071-1-git-send-email-mic@digikod.net> References: <1472121165-29071-1-git-send-email-mic@digikod.net> MIME-Version: 1.0 X-Antivirus: Dr.Web (R) for Unix mail servers drweb plugin ver.6.0.2.8 X-Antivirus-Code: 0x100000 Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Add a max errno value. This is not strictly needed but should improve reliability. Signed-off-by: Mickaël Salaün Cc: Arnd Bergmann Cc: Serge E. Hallyn Cc: James Morris Cc: Kees Cook --- include/uapi/asm-generic/errno-base.h | 1 + security/landlock/lsm.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/uapi/asm-generic/errno-base.h b/include/uapi/asm-generic/errno-base.h index 65115978510f..43407a403e72 100644 --- a/include/uapi/asm-generic/errno-base.h +++ b/include/uapi/asm-generic/errno-base.h @@ -35,5 +35,6 @@ #define EPIPE 32 /* Broken pipe */ #define EDOM 33 /* Math argument out of domain of func */ #define ERANGE 34 /* Math result not representable */ +#define _ERRNO_LAST ERANGE #endif diff --git a/security/landlock/lsm.c b/security/landlock/lsm.c index aa9d4a64826e..322309068066 100644 --- a/security/landlock/lsm.c +++ b/security/landlock/lsm.c @@ -11,7 +11,6 @@ #include #include /* enum bpf_reg_type, struct landlock_data */ #include -#include /* MAX_ERRNO */ #include /* struct bpf_prog, BPF_PROG_RUN() */ #include /* FIELD_SIZEOF() */ #include @@ -104,8 +103,9 @@ static int landlock_run_prog(__u64 args[6]) } } if (!ret) { - if (cur_ret > MAX_ERRNO) - ret = MAX_ERRNO; + /* check errno to not mess with kernel code */ + if (cur_ret > _ERRNO_LAST) + ret = EPERM; else ret = cur_ret; }