From patchwork Thu Jul 14 22:56:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Jurgens X-Patchwork-Id: 9231867 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 C02DB60865 for ; Fri, 15 Jul 2016 12:20:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF68F27F86 for ; Fri, 15 Jul 2016 12:20:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A41F127FB7; Fri, 15 Jul 2016 12:20:49 +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, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from emsm-gh1-uea10.nsa.gov (emsm-gh1-uea10.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 8419327F86 for ; Fri, 15 Jul 2016 12:20:48 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.28,368,1464652800"; d="scan'208";a="15609425" IronPort-PHdr: =?us-ascii?q?9a23=3Agx2GYh3kni1I9u1PsmDT+DRfVm0co7zxezQtwd8Z?= =?us-ascii?q?se8XKPad9pjvdHbS+e9qxAeQG96Ks7QY16GK7OjJYi8p2d65qncMcZhBBVcuqP?= =?us-ascii?q?49uEgeOvODElDxN/XwbiY3T4xoXV5h+GynYwAOQJ6tL2PbrnD61zMOABK3bVMz?= =?us-ascii?q?fbWtXNKOxJjon8mJuLTrKz1SgzS8Zb4gZD6Xli728vcsvI15N6wqwQHIqHYbM8?= =?us-ascii?q?5fxGdvOE7B102kvpT4wYRnuxh0l7phspcYEPayQqIjULYNDCg6KzJyo9XxshzO?= =?us-ascii?q?UQuC+2BaU2MYlQFFCE7Z/Rr6WdH3uTDx8O983G6fNMzySLkyHjO686ZsTgSvky?= =?us-ascii?q?oDNjgk4DLqjNdthvdeqROluxst2IPQYYeIJL9kc7rAcMgGbXZQVcZWESpaC8Wz?= =?us-ascii?q?aJVYFPcLP+tTs9zgoUATpwC1HwimCbDTzWpDhmX3xrISyOM8CkTd2whmGMgB9D?= =?us-ascii?q?zMpcjxHL8bTOTwya7P1ziFZPRTnX/m5JPgbgEqofbKW6l5N8XW1w1nGhvMlFSL?= =?us-ascii?q?gZTsJTKOzuAEuGXd6PBvEaqjj2MrpQZrrhC1y8ssg5WPjYUQjhjf+Cx/hoY4K8?= =?us-ascii?q?GpYE99fdOgVpBXsmXSN4JyBNklWGxuozo9wb4utpuyfSxMw5MilDDFbPnSX4GO?= =?us-ascii?q?qjD+TumcJyww0H5sfrOygxSa9EWkzuT6Udny21FP+HkW2uLQv2wAgkSAovOMTe?= =?us-ascii?q?FwqwL4gTs=3D?= X-IPAS-Result: =?us-ascii?q?A2EqBQD304hX/wHyM5BcHAEBgyCBUrplH4c5TAEBAQEBAQI?= =?us-ascii?q?CYieCMgQDEIIUAgQBAiQTDAgCHgsDAwECBgEBFwghCAgDAS0VEQcHCwUYBIgPB?= =?us-ascii?q?L9rAQEBAQYCASSPCREBhXcFjghxiiiOXYllhU6Qb4ILHIFPa4URDRcHgRcBAQE?= Received: from unknown (HELO tarius.tycho.ncsc.mil) ([144.51.242.1]) by emsm-gh1-uea10.nsa.gov with ESMTP; 15 Jul 2016 12:20:42 +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 u6FCGTDO022351; Fri, 15 Jul 2016 08:18:17 -0400 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 u6EMvT4I072596 for ; Thu, 14 Jul 2016 18:57:29 -0400 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 u6EMvTkC030247 for ; Thu, 14 Jul 2016 18:57:29 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1CeBACpF4hX/4GlL8FcHQGEcrZhhAqGGQKBewEBAQEBAWYnhF0CBCdSEBgIMVcHEog0wGIBMJUSBY4HcYonjluPL5AZVIIJHIFPOTKGLCuBFwEBAQ X-IPAS-Result: A1CeBACpF4hX/4GlL8FcHQGEcrZhhAqGGQKBewEBAQEBAWYnhF0CBCdSEBgIMVcHEog0wGIBMJUSBY4HcYonjluPL5AZVIIJHIFPOTKGLCuBFwEBAQ X-IronPort-AV: E=Sophos;i="5.28,365,1464667200"; d="scan'208";a="5582133" Received: from emsm-gh1-uea11.corp.nsa.gov (HELO emsm-gh1-uea11.nsa.gov) ([10.208.41.37]) by goalie.tycho.ncsc.mil with ESMTP; 14 Jul 2016 18:57:28 -0400 IronPort-PHdr: =?us-ascii?q?9a23=3AmJR8LxzoSAaoAQrXCy+O+j09IxM/srCxBDY+r6Qd?= =?us-ascii?q?0OITIJqq85mqBkHD//Il1AaPBtSDra4fwLCO+4nbGkU4qa6bt34DdJEeHzQksu?= =?us-ascii?q?4x2zIaPcieFEfgJ+TrZSFpVO5LVVti4m3peRMNQJW2WVTerzWI4CIIHV2nbEwu?= =?us-ascii?q?d7yzRtWZ1Zz//tvx0qWbWx9Piju5bOE6BzSNhiKViPMrh5B/IL060BrDrygAUe?= =?us-ascii?q?1XwWR1OQDbxE6ktY+YtaRu+CVIuv8n69UIEeCjJ/x5HvRkC2EtM3o0/9LDrh7e?= =?us-ascii?q?Vk6U4X9aVX8Z1lJQChXBxAnzQ5O0tyz9rOc70y6feYXtQascRSWp76AtTgThzi?= =?us-ascii?q?gAKXpx/XnekM1rpLpSuhO6vxh2yIOSZ5uacLJyeq7Rc9QASUJbU8pRXjAHCYS5?= =?us-ascii?q?K8MUAuMHe+ZVoZXsj1oIsRa6QwKrAaenyjZMwGXxxqA8yPgmGgLu0wkpHtZIu3?= =?us-ascii?q?PR//vvM6JHfemzhIvV1zrOaegejTv07onFdhIJpPyIWbt2dtqXwk4qQVCWxm6M?= =?us-ascii?q?oJDoamvGnt8GtHKWuq85Dbqi?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0GfBADVF4hX/4GlL8FcHQGEcrZhhAqGG?= =?us-ascii?q?QKBewEBAQEBAQICYieCMgQBEgGCEwIEJ1IQGAgxVwcSiDTAYgEwlRIFjgdxiie?= =?us-ascii?q?OW48vkBlUggkcgU85MoYsK4EXAQEB?= X-IPAS-Result: =?us-ascii?q?A0GfBADVF4hX/4GlL8FcHQGEcrZhhAqGGQKBewEBAQEBAQI?= =?us-ascii?q?CYieCMgQBEgGCEwIEJ1IQGAgxVwcSiDTAYgEwlRIFjgdxiieOW48vkBlUggkcg?= =?us-ascii?q?U85MoYsK4EXAQEB?= X-IronPort-AV: E=Sophos;i="5.28,365,1464652800"; d="scan'208";a="17666563" Received: from mail-il-dmz.mellanox.com (HELO mellanox.co.il) ([193.47.165.129]) by emsm-gh1-uea11.nsa.gov with ESMTP; 14 Jul 2016 22:57:27 +0000 Received: from Internal Mail-Server by MTLPINE1 (envelope-from danielj@mellanox.com) with ESMTPS (AES256-SHA encrypted); 15 Jul 2016 01:57:21 +0300 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 u6EMv9u2030854; Fri, 15 Jul 2016 01:57:17 +0300 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 v2 1/9] IB/core: IB cache enhancements to support Infiniband security Date: Fri, 15 Jul 2016 01:56:43 +0300 Message-Id: <1468537011-20407-2-git-send-email-danielj@mellanox.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1468537011-20407-1-git-send-email-danielj@mellanox.com> References: <1468537011-20407-1-git-send-email-danielj@mellanox.com> X-Mailman-Approved-At: Fri, 15 Jul 2016 08:13:30 -0400 X-BeenThere: selinux@tycho.nsa.gov X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Security-Enhanced Linux \(SELinux\) mailing list" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 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 Cache the subnet prefix and add a function to access it. Enforcing security requires frequent queries of the subnet prefix and the pkeys in the pkey table. Also removed an unneded pr_warn about memory allocation failure. Signed-off-by: Daniel Jurgens Reviewed-by: Eli Cohen Reviewed-by: Leon Romanovsky --- v2: - In ib_get_cached_subnet_prefix wait to initialize p until after validation. Yuval Shaia --- drivers/infiniband/core/cache.c | 36 +++++++++++++++++++++++++++++++++- drivers/infiniband/core/core_priv.h | 3 ++ include/rdma/ib_verbs.h | 1 + 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/core/cache.c b/drivers/infiniband/core/cache.c index 0409667..8a44894 100644 --- a/drivers/infiniband/core/cache.c +++ b/drivers/infiniband/core/cache.c @@ -932,6 +932,26 @@ int ib_get_cached_pkey(struct ib_device *device, } EXPORT_SYMBOL(ib_get_cached_pkey); +int ib_get_cached_subnet_prefix(struct ib_device *device, + u8 port_num, + u64 *sn_pfx) +{ + unsigned long flags; + int p; + + if (port_num < rdma_start_port(device) || + port_num > rdma_end_port(device)) + return -EINVAL; + + p = port_num - rdma_start_port(device); + read_lock_irqsave(&device->cache.lock, flags); + *sn_pfx = device->cache.subnet_prefix_cache[p]; + read_unlock_irqrestore(&device->cache.lock, flags); + + return 0; +} +EXPORT_SYMBOL(ib_get_cached_subnet_prefix); + int ib_find_cached_pkey(struct ib_device *device, u8 port_num, u16 pkey, @@ -1108,6 +1128,8 @@ static void ib_cache_update(struct ib_device *device, device->cache.lmc_cache[port - rdma_start_port(device)] = tprops->lmc; + device->cache.subnet_prefix_cache[port - rdma_start_port(device)] = + tprops->subnet_prefix; write_unlock_irq(&device->cache.lock); kfree(gid_cache); @@ -1166,9 +1188,18 @@ int ib_cache_setup_one(struct ib_device *device) (rdma_end_port(device) - rdma_start_port(device) + 1), GFP_KERNEL); + + device->cache.subnet_prefix_cache = + kcalloc((rdma_end_port(device) - rdma_start_port(device) + 1), + sizeof(*device->cache.subnet_prefix_cache), + GFP_KERNEL); + if (!device->cache.pkey_cache || - !device->cache.lmc_cache) { - pr_warn("Couldn't allocate cache for %s\n", device->name); + !device->cache.lmc_cache || + !device->cache.subnet_prefix_cache) { + kfree(device->cache.pkey_cache); + kfree(device->cache.lmc_cache); + kfree(device->cache.subnet_prefix_cache); return -ENOMEM; } @@ -1211,6 +1242,7 @@ void ib_cache_release_one(struct ib_device *device) gid_table_release_one(device); kfree(device->cache.pkey_cache); kfree(device->cache.lmc_cache); + kfree(device->cache.subnet_prefix_cache); } void ib_cache_cleanup_one(struct ib_device *device) diff --git a/drivers/infiniband/core/core_priv.h b/drivers/infiniband/core/core_priv.h index 19d499d..ce826e4 100644 --- a/drivers/infiniband/core/core_priv.h +++ b/drivers/infiniband/core/core_priv.h @@ -153,4 +153,7 @@ int ib_nl_handle_set_timeout(struct sk_buff *skb, int ib_nl_handle_ip_res_resp(struct sk_buff *skb, struct netlink_callback *cb); +int ib_get_cached_subnet_prefix(struct ib_device *device, + u8 port_num, + u64 *sn_pfx); #endif /* _CORE_PRIV_H */ diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h index 156673a..205ea09 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h @@ -1709,6 +1709,7 @@ struct ib_cache { struct ib_pkey_cache **pkey_cache; struct ib_gid_table **gid_cache; u8 *lmc_cache; + u64 *subnet_prefix_cache; }; struct ib_dma_mapping_ops {