From patchwork Tue Nov 8 21:06:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Jurgens X-Patchwork-Id: 9418165 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 F335060459 for ; Tue, 8 Nov 2016 21:08:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E3982288EB for ; Tue, 8 Nov 2016 21:08:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D8559288F8; Tue, 8 Nov 2016 21:08:52 +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=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from emsm-gh1-uea10.nsa.gov (smtp.nsa.gov [8.44.101.8]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 116FE288EB for ; Tue, 8 Nov 2016 21:08:51 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.31,611,1473120000"; d="scan'208";a="749892" IronPort-PHdr: =?us-ascii?q?9a23=3AVfvZ2BYP4/R+T5vlRKoz9jz/LSx+4OfEezUN459i?= =?us-ascii?q?sYplN5qZpMuybnLW6fgltlLVR4KTs6sC0LuM9fG/EjFdqb+681k6OKRWUBEEjc?= =?us-ascii?q?hE1ycBO+WiTXPBEfjxciYhF95DXlI2t1uyMExSBdqsLwaK+i760zceF13FOBZv?= =?us-ascii?q?IaytQ8iJ3p7xhr/5psCbSj4LrQL1Wal1IhSyoFeZnegtqqwmFJwMzADUqGBDYe?= =?us-ascii?q?VcyDAgD1uSmxHh+pX4p8Y7oGxtofZpy+psGeW/Jvx5HvRkC2EtM3o0/9LDrh7e?= =?us-ascii?q?Vk6U4X9aVX8Z1lJQChXBxAnzQ5O0tyz9rOc70y6feYXtQascRSWp76AtTgThzi?= =?us-ascii?q?gAKXpx/XnekM1rpLpSuhO6vxh2yIOSZ5uacLJyeq7Rc9QASUJbU8pRXjAHCYS5?= =?us-ascii?q?K8MUAuMHe+ZVoZXsj1oIsRa6QwKrAaenyjZMwGXxxqA8yPgmGgLu0wkpHtZIu3?= =?us-ascii?q?PR//vvM6JHfemzhIvV1zrOaegejTv07onFdhIJpPyIWbt2dtqXwk4qQVCWxm6M?= =?us-ascii?q?oJDoamvGnt8GtHKWuq85De8=3D?= X-IPAS-Result: =?us-ascii?q?A2HeBABJPiJY/wHyM5BdHAEBBAEBCgEBGAEFAQsBgwQBAQE?= =?us-ascii?q?BAR+BV6Q+llQliBtTAQEBAQEBAQECAQJfKIIzBAMTBYIQAgQBAiQTFCALAwMJA?= =?us-ascii?q?QEXCCEICAMBLRURBwcLBRYCBIg7BLN7UjgCixEBAQgBAQEBI48vEQGFfAWaL4l?= =?us-ascii?q?BhwmBbIghDIV5hzKFfoQGVUEVJBuFEXCFDXiBNQEBAQ?= Received: from unknown (HELO tarius.tycho.ncsc.mil) ([144.51.242.1]) by emsm-gh1-uea10.nsa.gov with ESMTP; 08 Nov 2016 21:08:50 +0000 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 uA8L8nji002928; Tue, 8 Nov 2016 16:08:50 -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 uA8L7DD3246479 for ; Tue, 8 Nov 2016 16:07:13 -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 uA8L7DE4002566 for ; Tue, 8 Nov 2016 16:07:13 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1CnBAAnPiJY/4GlL8FdHQEFAQsBgy8BAQEBAYF2pD6SRIQXhiQCgmYBAgEBAQEBAmIohGICBCdSEBgIMVcHEhuIRbN6UotLAQEBBwIllT0Fmi+JQYcJgWyILYV5hzKFfoQGVUE5hSw8NIc6AQEB X-IPAS-Result: A1CnBAAnPiJY/4GlL8FdHQEFAQsBgy8BAQEBAYF2pD6SRIQXhiQCgmYBAgEBAQEBAmIohGICBCdSEBgIMVcHEhuIRbN6UotLAQEBBwIllT0Fmi+JQYcJgWyILYV5hzKFfoQGVUE5hSw8NIc6AQEB X-IronPort-AV: E=Sophos;i="5.31,611,1473134400"; d="scan'208";a="5812099" Received: from emsm-gh1-uea10.corp.nsa.gov (HELO emsm-gh1-uea10.nsa.gov) ([10.208.41.36]) by goalie.tycho.ncsc.mil with ESMTP; 08 Nov 2016 16:07:12 -0500 IronPort-PHdr: =?us-ascii?q?9a23=3Ai9a2VhdMGxhdXOKaUYdCY9BTlGMj4u6mDksu8pMi?= =?us-ascii?q?zoh2WeGdxc+yYR7h7PlgxGXEQZ/co6odzbGH6eaxBiddvN6oizMrSNR0TRgLiM?= =?us-ascii?q?EbzUQLIfWuLgnFFsPsdDEwB89YVVVorDmROElRH9viNRWJ+iXhpQAbFhi3Dwdp?= =?us-ascii?q?POO9QteU1JXtkbHtsMCOKyxzxxOFKYtoKxu3qQiD/uI3uqBFbpgL9x3Sv3FTcP?= =?us-ascii?q?5Xz247bXianhL7+9vitMU7q3cYk7sb+sVBSaT3ebgjBfwdVWx+cjN92Mq+vhnZ?= =?us-ascii?q?TBCQzmAbT35TiR1MRQ/f41WyRp7stgPiv/d5nSydOtf7C7szXHDq9KtwYAP5gy?= =?us-ascii?q?cAcTgi+SfYjdI0xK9DqQigvDRnypTVe5mRPfFzOKTHcpdSSW5MUshWTSBpGI6w?= =?us-ascii?q?b4ITSeEGOKIQtIT0oR0OoBWiFCGtAv/iznlDgXqyla0z16I7FhrL2hc8GNkNmH?= =?us-ascii?q?vRpdTxcqwVVLOb1q7NmBnKabt0xC3y5Y7TOkQtqPeNULZyWc/czU0mEQTVyF6X?= =?us-ascii?q?rNq2bHuuyu0Rvj3DvKJbXuW1hjti8lkprw=3D=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0GpBABJPiJY/4GlL8FdHQEFAQsBGQYMg?= =?us-ascii?q?wQBAQEBAYF2pD6SRIQXhiQCgmYBAQEBAQEBAQIBAl8ogjMEARUBBIIQAgQnUhA?= =?us-ascii?q?YCDFXBxIbiEWze1KLSwEBAQcCJZU9BZoviUGHCYFsiC2FeYcyhX6EBlVBOYUsP?= =?us-ascii?q?DSFbIFOAQEB?= X-IPAS-Result: =?us-ascii?q?A0GpBABJPiJY/4GlL8FdHQEFAQsBGQYMgwQBAQEBAYF2pD6?= =?us-ascii?q?SRIQXhiQCgmYBAQEBAQEBAQIBAl8ogjMEARUBBIIQAgQnUhAYCDFXBxIbiEWze?= =?us-ascii?q?1KLSwEBAQcCJZU9BZoviUGHCYFsiC2FeYcyhX6EBlVBOYUsPDSFbIFOAQEB?= X-IronPort-AV: E=Sophos;i="5.31,611,1473120000"; d="scan'208";a="749738" Received: from mail-il-dmz.mellanox.com (HELO mellanox.co.il) ([193.47.165.129]) by emsm-gh1-uea10.nsa.gov with ESMTP; 08 Nov 2016 21:06:53 +0000 Received: from Internal Mail-Server by MTLPINE1 (envelope-from danielj@mellanox.com) with ESMTPS (AES256-SHA encrypted); 8 Nov 2016 23:06:49 +0200 Received: from x-vnc01.mtx.labs.mlnx. (x-vnc01.mtx.labs.mlnx [10.12.150.16]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id uA8L6Se5009889; Tue, 8 Nov 2016 23:06:46 +0200 From: Dan Jurgens To: chrisw@sous-sol.org, paul@paul-moore.com, sds@tycho.nsa.gov, eparis@parisplace.org, dledford@redhat.com, sean.hefty@intel.com, hal.rosenstock@gmail.com Subject: [PATCH v4 5/9] selinux: Create policydb version for Infiniband support Date: Tue, 8 Nov 2016 23:06:21 +0200 Message-Id: <1478639185-47521-6-git-send-email-danielj@mellanox.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1478639185-47521-1-git-send-email-danielj@mellanox.com> References: <1478639185-47521-1-git-send-email-danielj@mellanox.com> X-Mailman-Approved-At: Tue, 08 Nov 2016 16:07:45 -0500 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: Cc: liranl@mellanox.com, leonro@mellanox.com, linux-rdma@vger.kernel.org, linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov MIME-Version: 1.0 Errors-To: selinux-bounces@tycho.nsa.gov Sender: "Selinux" X-Virus-Scanned: ClamAV using ClamSMTP From: Daniel Jurgens Support for Infiniband requires the addition of two new object contexts, one for infiniband PKeys and another IB Ports. Added handlers to read and write the new ocontext types when reading or writing a binary policy representation. issue: 736423 Change-Id: I906bf7a1e0bd59c3cccdce278e5fe98ba8c404b8 Signed-off-by: Daniel Jurgens Reviewed-by: Eli Cohen --- v2: - Shorten ib_end_port to ib_port. Paul Moore - Added bounds checking to port number. Paul Moore - Eliminated {} in OCON_PKEY case statement. Yuval Shaia v3: - ib_port -> ib_endport. Paul Moore v4: - removed unneeded brackets in ocontext_read. Paul Moore Signed-off-by: Daniel Jurgens --- security/selinux/include/security.h | 3 +- security/selinux/ss/policydb.c | 129 +++++++++++++++++++++++++++++++----- security/selinux/ss/policydb.h | 27 +++++--- 3 files changed, 135 insertions(+), 24 deletions(-) diff --git a/security/selinux/include/security.h b/security/selinux/include/security.h index 308a286..6bb9b0a 100644 --- a/security/selinux/include/security.h +++ b/security/selinux/include/security.h @@ -36,10 +36,11 @@ #define POLICYDB_VERSION_DEFAULT_TYPE 28 #define POLICYDB_VERSION_CONSTRAINT_NAMES 29 #define POLICYDB_VERSION_XPERMS_IOCTL 30 +#define POLICYDB_VERSION_INFINIBAND 31 /* Range of policy versions we understand*/ #define POLICYDB_VERSION_MIN POLICYDB_VERSION_BASE -#define POLICYDB_VERSION_MAX POLICYDB_VERSION_XPERMS_IOCTL +#define POLICYDB_VERSION_MAX POLICYDB_VERSION_INFINIBAND /* Mask for just the mount related flags */ #define SE_MNTMASK 0x0f diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c index d719db4..24e16da 100644 --- a/security/selinux/ss/policydb.c +++ b/security/selinux/ss/policydb.c @@ -17,6 +17,11 @@ * * Added support for the policy capability bitmap * + * Update: Mellanox Techonologies + * + * Added Infiniband support + * + * Copyright (C) 2016 Mellanox Techonologies * Copyright (C) 2007 Hewlett-Packard Development Company, L.P. * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc. * Copyright (C) 2003 - 2004 Tresys Technology, LLC @@ -76,81 +81,86 @@ struct policydb_compat_info { { .version = POLICYDB_VERSION_BASE, .sym_num = SYM_NUM - 3, - .ocon_num = OCON_NUM - 1, + .ocon_num = OCON_NUM - 3, }, { .version = POLICYDB_VERSION_BOOL, .sym_num = SYM_NUM - 2, - .ocon_num = OCON_NUM - 1, + .ocon_num = OCON_NUM - 3, }, { .version = POLICYDB_VERSION_IPV6, .sym_num = SYM_NUM - 2, - .ocon_num = OCON_NUM, + .ocon_num = OCON_NUM - 2, }, { .version = POLICYDB_VERSION_NLCLASS, .sym_num = SYM_NUM - 2, - .ocon_num = OCON_NUM, + .ocon_num = OCON_NUM - 2, }, { .version = POLICYDB_VERSION_MLS, .sym_num = SYM_NUM, - .ocon_num = OCON_NUM, + .ocon_num = OCON_NUM - 2, }, { .version = POLICYDB_VERSION_AVTAB, .sym_num = SYM_NUM, - .ocon_num = OCON_NUM, + .ocon_num = OCON_NUM - 2, }, { .version = POLICYDB_VERSION_RANGETRANS, .sym_num = SYM_NUM, - .ocon_num = OCON_NUM, + .ocon_num = OCON_NUM - 2, }, { .version = POLICYDB_VERSION_POLCAP, .sym_num = SYM_NUM, - .ocon_num = OCON_NUM, + .ocon_num = OCON_NUM - 2, }, { .version = POLICYDB_VERSION_PERMISSIVE, .sym_num = SYM_NUM, - .ocon_num = OCON_NUM, + .ocon_num = OCON_NUM - 2, }, { .version = POLICYDB_VERSION_BOUNDARY, .sym_num = SYM_NUM, - .ocon_num = OCON_NUM, + .ocon_num = OCON_NUM - 2, }, { .version = POLICYDB_VERSION_FILENAME_TRANS, .sym_num = SYM_NUM, - .ocon_num = OCON_NUM, + .ocon_num = OCON_NUM - 2, }, { .version = POLICYDB_VERSION_ROLETRANS, .sym_num = SYM_NUM, - .ocon_num = OCON_NUM, + .ocon_num = OCON_NUM - 2, }, { .version = POLICYDB_VERSION_NEW_OBJECT_DEFAULTS, .sym_num = SYM_NUM, - .ocon_num = OCON_NUM, + .ocon_num = OCON_NUM - 2, }, { .version = POLICYDB_VERSION_DEFAULT_TYPE, .sym_num = SYM_NUM, - .ocon_num = OCON_NUM, + .ocon_num = OCON_NUM - 2, }, { .version = POLICYDB_VERSION_CONSTRAINT_NAMES, .sym_num = SYM_NUM, - .ocon_num = OCON_NUM, + .ocon_num = OCON_NUM - 2, }, { .version = POLICYDB_VERSION_XPERMS_IOCTL, .sym_num = SYM_NUM, + .ocon_num = OCON_NUM - 2, + }, + { + .version = POLICYDB_VERSION_INFINIBAND, + .sym_num = SYM_NUM, .ocon_num = OCON_NUM, }, }; @@ -2222,6 +2232,60 @@ static int ocontext_read(struct policydb *p, struct policydb_compat_info *info, goto out; break; } + case OCON_PKEY: + rc = next_entry(nodebuf, fp, sizeof(u32) * 6); + if (rc) + goto out; + + c->u.pkey.subnet_prefix = be64_to_cpu(*((__be64 *)nodebuf)); + /* The subnet prefix is stored as an IPv6 + * address in the policy. + * + * Check that the lower 2 DWORDS are 0. + */ + if (nodebuf[2] || nodebuf[3]) { + rc = -EINVAL; + goto out; + } + + if (nodebuf[4] > 0xffff || + nodebuf[5] > 0xffff) { + rc = -EINVAL; + goto out; + } + + c->u.pkey.low_pkey = le32_to_cpu(nodebuf[4]); + c->u.pkey.high_pkey = le32_to_cpu(nodebuf[5]); + + rc = context_read_and_validate(&c->context[0], + p, + fp); + if (rc) + goto out; + break; + case OCON_IB_ENDPORT: + rc = next_entry(buf, fp, sizeof(u32) * 2); + if (rc) + goto out; + len = le32_to_cpu(buf[0]); + + rc = str_read(&c->u.ib_endport.dev_name, GFP_KERNEL, fp, len); + if (rc) + goto out; + + if (buf[1] > 0xff || buf[1] == 0) { + rc = -EINVAL; + goto out; + } + + c->u.ib_endport.port_num = le32_to_cpu(buf[1]); + + rc = context_read_and_validate(&c->context[0], + p, + fp); + if (rc) + goto out; + break; } } } @@ -3151,6 +3215,41 @@ static int ocontext_write(struct policydb *p, struct policydb_compat_info *info, if (rc) return rc; break; + case OCON_PKEY: + *((__be64 *)nodebuf) = cpu_to_be64(c->u.pkey.subnet_prefix); + + /* + * The low order 2 bits were confirmed to be 0 + * when the policy was loaded. Write them out + * as zero + */ + nodebuf[2] = 0; + nodebuf[3] = 0; + + nodebuf[4] = cpu_to_le32(c->u.pkey.low_pkey); + nodebuf[5] = cpu_to_le32(c->u.pkey.high_pkey); + + rc = put_entry(nodebuf, sizeof(u32), 6, fp); + if (rc) + return rc; + rc = context_write(p, &c->context[0], fp); + if (rc) + return rc; + break; + case OCON_IB_ENDPORT: + len = strlen(c->u.ib_endport.dev_name); + buf[0] = cpu_to_le32(len); + buf[1] = cpu_to_le32(c->u.ib_endport.port_num); + rc = put_entry(buf, sizeof(u32), 2, fp); + if (rc) + return rc; + rc = put_entry(c->u.ib_endport.dev_name, 1, len, fp); + if (rc) + return rc; + rc = context_write(p, &c->context[0], fp); + if (rc) + return rc; + break; } } } diff --git a/security/selinux/ss/policydb.h b/security/selinux/ss/policydb.h index 725d594..edb329d 100644 --- a/security/selinux/ss/policydb.h +++ b/security/selinux/ss/policydb.h @@ -187,6 +187,15 @@ struct ocontext { u32 addr[4]; u32 mask[4]; } node6; /* IPv6 node information */ + struct { + u64 subnet_prefix; + u16 low_pkey; + u16 high_pkey; + } pkey; + struct { + char *dev_name; + u8 port_num; + } ib_endport; } u; union { u32 sclass; /* security class for genfs */ @@ -215,14 +224,16 @@ struct genfs { #define SYM_NUM 8 /* object context array indices */ -#define OCON_ISID 0 /* initial SIDs */ -#define OCON_FS 1 /* unlabeled file systems */ -#define OCON_PORT 2 /* TCP and UDP port numbers */ -#define OCON_NETIF 3 /* network interfaces */ -#define OCON_NODE 4 /* nodes */ -#define OCON_FSUSE 5 /* fs_use */ -#define OCON_NODE6 6 /* IPv6 nodes */ -#define OCON_NUM 7 +#define OCON_ISID 0 /* initial SIDs */ +#define OCON_FS 1 /* unlabeled file systems */ +#define OCON_PORT 2 /* TCP and UDP port numbers */ +#define OCON_NETIF 3 /* network interfaces */ +#define OCON_NODE 4 /* nodes */ +#define OCON_FSUSE 5 /* fs_use */ +#define OCON_NODE6 6 /* IPv6 nodes */ +#define OCON_PKEY 7 /* Infiniband PKeys */ +#define OCON_IB_ENDPORT 8 /* Infiniband end ports */ +#define OCON_NUM 9 /* The policy database */ struct policydb {