From patchwork Tue Nov 8 21:06:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Jurgens X-Patchwork-Id: 9418155 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 3CBA160459 for ; Tue, 8 Nov 2016 21:07:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C4B4288EB for ; Tue, 8 Nov 2016 21:07:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 20D5F288F8; Tue, 8 Nov 2016 21:07:57 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from emsm-gh1-uea11.nsa.gov (emsm-gh1-uea11.nsa.gov [8.44.101.9]) (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 7CADF288EB for ; Tue, 8 Nov 2016 21:07:56 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.31,611,1473120000"; d="scan'208";a="606516" IronPort-PHdr: =?us-ascii?q?9a23=3AS58cvhKtZoPsWIl8FdmcpTZWNBhigK39O0sv0rFi?= =?us-ascii?q?tYgVLfTxwZ3uMQTl6Ol3ixeRBMOAuqgC2rWd7v2ocFdDyK7JiGoFfp1IWk1Nou?= =?us-ascii?q?QttCtkPvS4D1bmJuXhdS0wEZcKflZk+3amLRodQ56mNBXsq3G/pQQfBg/4fVIs?= =?us-ascii?q?YL+kQMiD0I/qiqibwN76W01wnj2zYLd/fl2djD76kY0ou7ZkMbs70RDTo3FFKK?= =?us-ascii?q?x8zGJsIk+PzV6nvp/jtKN592xsn95pt4sZCeSpN5g/GLdYFjU9LEgu49Dw8ALE?= =?us-ascii?q?SU2I/HRYGn0fjx5gGwHY6FT/WZDrv23xse85kDKWJuXqXLs0XnKk9K4tRxj2zG?= =?us-ascii?q?8KLzcj8Xr/ksVqjblDpBuqqlp42YGQKI2ROfZwebnRVckXSWpIQoBaUCkFSpix?= =?us-ascii?q?Zo1JD+cPIfdwro/hql9Iphy7QUGsDeep0DhTi3ntwaox0MwuFAjH2EorGNddnm?= =?us-ascii?q?7TqYDZPaFac/2vw6TO1n2XY/pQ2Dr56qDNfxQlqPeLTfR7ds+HmhpnLB/MkljF?= =?us-ascii?q?8d+tBDiSzOlY9jHD4g=3D=3D?= X-IPAS-Result: =?us-ascii?q?A2HdBABJPiJY/wHyM5BdHAEBBAEBCgEBFwEBBAEBCgEBgwQ?= =?us-ascii?q?BAQEBAR+BV6Q+llQliBtTAQEBAQEBAQECAQJfKIIzBAMTBYIQAgQBAiQTFCALA?= =?us-ascii?q?wMJAQEXCCEICAMBLRURBwcLBRgEiDsEs3tSOAKLEQEBCAEBAQEjjy8RAYV8BY5?= =?us-ascii?q?Zi1aQSooNhgWRNlVWJBuDFhyBX3CFAA0XB1qBNQEBAQ?= Received: from unknown (HELO tarius.tycho.ncsc.mil) ([144.51.242.1]) by emsm-gh1-uea11.nsa.gov with ESMTP; 08 Nov 2016 21:07:54 +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 uA8L7epi002680; Tue, 8 Nov 2016 16:07:42 -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 uA8L6s11246443 for ; Tue, 8 Nov 2016 16:06:54 -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 uA8L6rmm002347 for ; Tue, 8 Nov 2016 16:06:53 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1B4BAAnPiJY/4GlL8FdHAEBBAEBCgEBgy8BAQEBAYF2pD6SRIQXhiQCgmYBAgEBAQEBAmIohGICBCdSEBgIMVcHEohgs3pSi0sBAQgCJZU9BY5Zi1aQSpASkTZVeoMxHIFfPDSFACuCDwEBAQ X-IPAS-Result: A1B4BAAnPiJY/4GlL8FdHAEBBAEBCgEBgy8BAQEBAYF2pD6SRIQXhiQCgmYBAgEBAQEBAmIohGICBCdSEBgIMVcHEohgs3pSi0sBAQgCJZU9BY5Zi1aQSpASkTZVeoMxHIFfPDSFACuCDwEBAQ X-IronPort-AV: E=Sophos;i="5.31,611,1473134400"; d="scan'208";a="5812081" 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; 08 Nov 2016 16:06:39 -0500 IronPort-PHdr: =?us-ascii?q?9a23=3ArbxwNh+LVvVuBP9uRHKM819IXTAuvvDOBiVQ1KB8?= =?us-ascii?q?2+8cTK2v8tzYMVDF4r011RmSDN+duq0P1reempujcFRI2YyGvnEGfc4EfD4+ou?= =?us-ascii?q?JSoTYdBtWYA1bwNv/gYn9yNs1DUFh44yPzahANS47AblHf6ke/8SQVUk2mc1Ek?= =?us-ascii?q?fKKkRcWP0oye7KObw9XreQJGhT6wM/tZDS6dikHvjPQQmpZoMa0ryxHE8TNicu?= =?us-ascii?q?VSwn50dxrIx06vru/5xpNo8jxRtvQ97IYAFPyiJ+VrBYBfWT8mKWEu++XwsgTY?= =?us-ascii?q?CBCI4j0bSGpS2gJBHgzt9BjnWtL0tSzgu6x23yzeddb6VpgoSD+i6OFtUxauhy?= =?us-ascii?q?AZc3Y06GjNi9dYlKtBoQm5oxV0zsjTeo7RfPZ6c6/TeskWbXBMUsZYS2pKBYb4?= =?us-ascii?q?J5ACBuxHPetWs5jVpl0SoB/4Dg6pQKvvwzsOnHjt0Kshz+MqEinJ2QUhG5QFt3?= =?us-ascii?q?GHgs/yMfI+WOb97rTSwjjFdLsC1T776YXMcDgkrPWIVLR3YYzazkx5RFCNtUmZ?= =?us-ascii?q?tYGwZ2Dd7e8KqWXOqrM4De8=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0F4BADzPCJY/4GlL8FdHAEBBAEBCgEBF?= =?us-ascii?q?wEBBAEBCgEBgwQBAQEBAYF2pD6SRIQXhiQCgmYBAQEBAQEBAQIBAl8ogjMEARU?= =?us-ascii?q?BBIIQAgQnUhAYCDFXBxKIYLN3UotLAQEIAiWVPQWOWYtWkEqQEpE2VXqDMRyBX?= =?us-ascii?q?zw0hQArQYFOAQEB?= X-IPAS-Result: =?us-ascii?q?A0F4BADzPCJY/4GlL8FdHAEBBAEBCgEBFwEBBAEBCgEBgwQ?= =?us-ascii?q?BAQEBAYF2pD6SRIQXhiQCgmYBAQEBAQEBAQIBAl8ogjMEARUBBIIQAgQnUhAYC?= =?us-ascii?q?DFXBxKIYLN3UotLAQEIAiWVPQWOWYtWkEqQEpE2VXqDMRyBXzw0hQArQYFOAQE?= =?us-ascii?q?B?= X-IronPort-AV: E=Sophos;i="5.31,611,1473120000"; d="scan'208";a="606452" Received: from mail-il-dmz.mellanox.com (HELO mellanox.co.il) ([193.47.165.129]) by emsm-gh1-uea11.nsa.gov with ESMTP; 08 Nov 2016 21:06:38 +0000 Received: from Internal Mail-Server by MTLPINE1 (envelope-from danielj@mellanox.com) with ESMTPS (AES256-SHA encrypted); 8 Nov 2016 23:06:35 +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 uA8L6Se1009889; Tue, 8 Nov 2016 23:06:32 +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 1/9] IB/core: IB cache enhancements to support Infiniband security Date: Tue, 8 Nov 2016 23:06:17 +0200 Message-Id: <1478639185-47521-2-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:39 -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 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. issue: 736423 Change-Id: Ifdef64b097a8d1d55db65f08ce401d9d2e4b025e 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 Signed-off-by: Daniel Jurgens --- 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 1a2984c..affc8ef 100644 --- a/drivers/infiniband/core/cache.c +++ b/drivers/infiniband/core/cache.c @@ -934,6 +934,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, @@ -1110,6 +1130,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); @@ -1168,9 +1190,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; } @@ -1213,6 +1244,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 5ad43a4..db178fd 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h @@ -1761,6 +1761,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 {