From patchwork Fri Jan 8 09:52:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huw Davies X-Patchwork-Id: 7983631 Return-Path: X-Original-To: patchwork-selinux@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id F2602BEEE5 for ; Fri, 8 Jan 2016 10:00:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4CCD120107 for ; Fri, 8 Jan 2016 10:00:09 +0000 (UTC) Received: from emvm-gh1-uea08.nsa.gov (emvm-gh1-uea08.nsa.gov [63.239.67.9]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7006A20103 for ; Fri, 8 Jan 2016 10:00:08 +0000 (UTC) X-TM-IMSS-Message-ID: <8892fc6500149b8c@nsa.gov> Received: from tarius.tycho.ncsc.mil ([144.51.242.1]) by nsa.gov ([10.208.42.193]) with ESMTP (TREND IMSS SMTP Service 7.1) id 8892fc6500149b8c ; Fri, 8 Jan 2016 04:58:02 -0500 Received: from prometheus.infosec.tycho.ncsc.mil (prometheus [192.168.25.40]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id u089vL8o028427; Fri, 8 Jan 2016 04:57:22 -0500 Received: from tarius.tycho.ncsc.mil (tarius.infosec.tycho.ncsc.mil [144.51.242.1]) by prometheus.infosec.tycho.ncsc.mil (8.15.2/8.15.2) with ESMTP id u089r1YX017690 for ; Fri, 8 Jan 2016 04:53:01 -0500 Received: from goalie.tycho.ncsc.mil (goalie [144.51.242.250]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id u089r02N028019 for ; Fri, 8 Jan 2016 04:53:01 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1DdAwCphY9WgYO9+9heGQEBAQEPAQEBAYRJiFmxSIN5DBiFd4FtAQEBAQEBEgEBFjOEZioZAQE3AYEcIhKILgGwIoVUAQWMBAaPeYMVDEGBNo0+iVScUo5OgmhGgUByhBaBSwEBAQ X-IPAS-Result: A1DdAwCphY9WgYO9+9heGQEBAQEPAQEBAYRJiFmxSIN5DBiFd4FtAQEBAQEBEgEBFjOEZioZAQE3AYEcIhKILgGwIoVUAQWMBAaPeYMVDEGBNo0+iVScUo5OgmhGgUByhBaBSwEBAQ X-IronPort-AV: E=Sophos;i="5.20,537,1444708800"; d="scan'208";a="5082810" Received: from emvm-gh1-uea08.nsa.gov ([10.208.42.193]) by goalie.tycho.ncsc.mil with ESMTP; 08 Jan 2016 04:53:01 -0500 X-TM-IMSS-Message-ID: <888de56c00149ae7@nsa.gov> Received: from mail.codeweavers.com (mail.codeweavers.com [216.251.189.131]) by nsa.gov ([10.208.42.193]) with ESMTP (TREND IMSS SMTP Service 7.1; TLSv1/SSLv3 DHE-RSA-AES128-SHA (128/128)) id 888de56c00149ae7 ; Fri, 8 Jan 2016 04:52:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=6377696661; h=Message-Id:Date:Subject:Cc:To:From; bh=WxRgtfYMq1kNPOwG62FbWqw/gh4P7GAMDRSjgF/hclY=; b=tMnuIfnPNPu2wJABmpzX9WIwvt7kfIp0QnZC5AEffK31Zykx4dESgbOamBLjXeO5TbpEZxD7PZVXzo/7TNGZHcAU/xYkCwr31X6B1Ex0mYG+yNKwWKJfTweVoxjRySIoFgVGfzCzH7rjq3NuflNz6OJqihdbfbQIcxNZbNSdvRE=; Received: from merlot.physics.ox.ac.uk ([163.1.241.98]) by mail.codeweavers.com with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1aHTj8-00069O-Ql; Fri, 08 Jan 2016 03:52:59 -0600 Received: from daviesh by merlot.physics.ox.ac.uk with local (Exim 4.71) (envelope-from ) id 1aHTj7-0003fX-Fe; Fri, 08 Jan 2016 09:52:57 +0000 From: Huw Davies To: netdev@vger.kernel.org, linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov Subject: [RFC PATCH v2 11/18] netlabel: Prevent setsockopt() from changing the hop-by-hop option. Date: Fri, 8 Jan 2016 09:52:47 +0000 Message-Id: <1452246774-13241-12-git-send-email-huw@codeweavers.com> X-Mailer: git-send-email 1.8.0 X-Spam-Score: -2.9 X-TM-AS-MML: disable X-BeenThere: selinux@tycho.nsa.gov X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Security-Enhanced Linux \(SELinux\) mailing list" List-Post: List-Help: MIME-Version: 1.0 Errors-To: selinux-bounces@tycho.nsa.gov Sender: "Selinux" X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If a socket has a netlabel in place then don't let setsockopt() alter the socket's IPv6 hop-by-hop option. This is in the same spirit as the existing check for IPv4. Signed-off-by: Huw Davies --- security/selinux/netlabel.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/security/selinux/netlabel.c b/security/selinux/netlabel.c index 5470f32..2477a75 100644 --- a/security/selinux/netlabel.c +++ b/security/selinux/netlabel.c @@ -410,6 +410,21 @@ int selinux_netlbl_sock_rcv_skb(struct sk_security_struct *sksec, } /** + * selinux_netlbl_option - Is this a NetLabel option + * @level: the socket level or protocol + * @optname: the socket option name + * + * Description: + * Returns true if @level and @optname refer to a NetLabel option. + * Helper for selinux_netlbl_socket_setsockopt(). + */ +static inline int selinux_netlbl_option(int level, int optname) +{ + return (level == IPPROTO_IP && optname == IP_OPTIONS) || + (level == IPPROTO_IPV6 && optname == IPV6_HOPOPTS); +} + +/** * selinux_netlbl_socket_setsockopt - Do not allow users to remove a NetLabel * @sock: the socket * @level: the socket level or protocol @@ -431,7 +446,7 @@ int selinux_netlbl_socket_setsockopt(struct socket *sock, struct sk_security_struct *sksec = sk->sk_security; struct netlbl_lsm_secattr secattr; - if (level == IPPROTO_IP && optname == IP_OPTIONS && + if (selinux_netlbl_option(level, optname) && (sksec->nlbl_state == NLBL_LABELED || sksec->nlbl_state == NLBL_CONNLABELED)) { netlbl_secattr_init(&secattr);