From patchwork Mon Apr 4 21:48: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: 8744611 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CF10D9F7C9 for ; Mon, 4 Apr 2016 21:50:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DDE2B201EF for ; Mon, 4 Apr 2016 21:50:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 868C420272 for ; Mon, 4 Apr 2016 21:50:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756286AbcDDVtw (ORCPT ); Mon, 4 Apr 2016 17:49:52 -0400 Received: from [193.47.165.129] ([193.47.165.129]:32991 "EHLO mellanox.co.il" rhost-flags-FAIL-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1756277AbcDDVtv (ORCPT ); Mon, 4 Apr 2016 17:49:51 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from danielj@mellanox.com) with ESMTPS (AES256-SHA encrypted); 5 Apr 2016 00:49:10 +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 u34Lmg68024860; Tue, 5 Apr 2016 00:49:09 +0300 From: Dan Jurgens To: selinux@tycho.nsa.gov, linux-security-module@vger.kernel.org Cc: linux-rdma@vger.kernel.org, yevgenyp@mellanox.com, Daniel Jurgens Subject: [RFC PATCH 4/7] selinux: Allocate and free infiniband security hooks Date: Tue, 5 Apr 2016 00:48:21 +0300 Message-Id: <1459806504-16135-5-git-send-email-danielj@mellanox.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1459806504-16135-1-git-send-email-danielj@mellanox.com> References: <1459806504-16135-1-git-send-email-danielj@mellanox.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, 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 From: Daniel Jurgens Implement and attach hooks to allocate and free infiniband security structures. Signed-off-by: Daniel Jurgens Reviewed-by: Eli Cohen --- security/selinux/hooks.c | 29 +++++++++++++++++++++++++++++ security/selinux/include/objsec.h | 6 ++++++ 2 files changed, 35 insertions(+), 0 deletions(-) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 156e232..cd0c6f4 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -17,6 +17,8 @@ * Paul Moore * Copyright (C) 2007 Hitachi Software Engineering Co., Ltd. * Yuichi Nakamura + * Copyright (C) 2016 Mellanox Technologies, + * Dan Jurgens * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -5934,6 +5936,26 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer) #endif +#ifdef CONFIG_SECURITY_INFINIBAND +static int selinux_infiniband_alloc_security(void **security) +{ + struct infiniband_security_struct *sec; + + sec = kzalloc(sizeof(*sec), GFP_ATOMIC); + if (!sec) + return -ENOMEM; + sec->sid = current_sid(); + + *security = sec; + return 0; +} + +static void selinux_infiniband_free_security(void *security) +{ + kfree(security); +} +#endif + static struct security_hook_list selinux_hooks[] = { LSM_HOOK_INIT(binder_set_context_mgr, selinux_binder_set_context_mgr), LSM_HOOK_INIT(binder_transaction, selinux_binder_transaction), @@ -6115,6 +6137,13 @@ static struct security_hook_list selinux_hooks[] = { LSM_HOOK_INIT(tun_dev_attach, selinux_tun_dev_attach), LSM_HOOK_INIT(tun_dev_open, selinux_tun_dev_open), +#ifdef CONFIG_SECURITY_INFINIBAND + LSM_HOOK_INIT(infiniband_alloc_security, + selinux_infiniband_alloc_security), + LSM_HOOK_INIT(infiniband_free_security, + selinux_infiniband_free_security), +#endif + #ifdef CONFIG_SECURITY_NETWORK_XFRM LSM_HOOK_INIT(xfrm_policy_alloc_security, selinux_xfrm_policy_alloc), LSM_HOOK_INIT(xfrm_policy_clone_security, selinux_xfrm_policy_clone), diff --git a/security/selinux/include/objsec.h b/security/selinux/include/objsec.h index a2ae054..4e36976 100644 --- a/security/selinux/include/objsec.h +++ b/security/selinux/include/objsec.h @@ -10,6 +10,8 @@ * * Copyright (C) 2001,2002 Networks Associates Technology, Inc. * Copyright (C) 2003 Red Hat, Inc., James Morris + * Copyright (C) 2016 Mellanox Technologies, + * Dan Jurgens * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -129,6 +131,10 @@ struct key_security_struct { u32 sid; /* SID of key */ }; +struct infiniband_security_struct { + u32 sid; /* SID of the queue pair or MAD agent */ +}; + extern unsigned int selinux_checkreqprot; #endif /* _SELINUX_OBJSEC_H_ */