public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
From: Yuval Shaia <yuval.shaia@oracle.com>
To: Dan Jurgens <danielj@mellanox.com>
Cc: 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, selinux@tycho.nsa.gov,
	linux-security-module@vger.kernel.org,
	linux-rdma@vger.kernel.org, yevgenyp@mellanox.com
Subject: Re: [PATCH 06/12] selinux: Add IB End Port SMP access vector
Date: Thu, 30 Jun 2016 18:31:16 +0300	[thread overview]
Message-ID: <20160630153113.GF22107@yuval-lap.uk.oracle.com> (raw)
In-Reply-To: <1466711578-64398-7-git-send-email-danielj@mellanox.com>

On Thu, Jun 23, 2016 at 10:52:52PM +0300, Dan Jurgens wrote:
> From: Daniel Jurgens <danielj@mellanox.com>
> 
> Add a type for Infiniband end ports and an access vector for subnet
> management packets. Implement the ib_end_port_smp hook to check that the
> caller has permission to send and receive SMPs on the end port specified
> by the device name and port.  Add interface to query the SID for a IB

Extra space before " Add"

> end port, which walks the IB_END_PORT ocontexts to find an entry for the
> given name and port.
> 
> Signed-off-by: Daniel Jurgens <danielj@mellanox.com>
> Reviewed-by: Eli Cohen <eli@mellanox.com>
> ---
>  include/linux/lsm_audit.h                        | 32 +++++++++++-------
>  security/selinux/hooks.c                         | 27 +++++++++++++++
>  security/selinux/include/classmap.h              |  2 ++
>  security/selinux/include/initial_sid_to_string.h |  1 +
>  security/selinux/include/security.h              |  2 ++
>  security/selinux/ss/services.c                   | 43 ++++++++++++++++++++++++
>  6 files changed, 95 insertions(+), 12 deletions(-)
> 
> diff --git a/include/linux/lsm_audit.h b/include/linux/lsm_audit.h
> index 8ff7eae..acf6de7 100644
> --- a/include/linux/lsm_audit.h
> +++ b/include/linux/lsm_audit.h
> @@ -21,6 +21,7 @@
>  #include <linux/path.h>
>  #include <linux/key.h>
>  #include <linux/skbuff.h>
> +#include <rdma/ib_verbs.h>
>  
>  struct lsm_network_audit {
>  	int netif;
> @@ -50,21 +51,27 @@ struct lsm_pkey_audit {
>  	u16	pkey;
>  };
>  
> +struct lsm_ib_end_port_audit {
> +	char	dev_name[IB_DEVICE_NAME_MAX];
> +	u8	port;
> +};
> +
>  /* Auxiliary data to use in generating the audit record. */
>  struct common_audit_data {
>  	char type;
> -#define LSM_AUDIT_DATA_PATH	1
> -#define LSM_AUDIT_DATA_NET	2
> -#define LSM_AUDIT_DATA_CAP	3
> -#define LSM_AUDIT_DATA_IPC	4
> -#define LSM_AUDIT_DATA_TASK	5
> -#define LSM_AUDIT_DATA_KEY	6
> -#define LSM_AUDIT_DATA_NONE	7
> -#define LSM_AUDIT_DATA_KMOD	8
> -#define LSM_AUDIT_DATA_INODE	9
> -#define LSM_AUDIT_DATA_DENTRY	10
> -#define LSM_AUDIT_DATA_IOCTL_OP	11
> -#define LSM_AUDIT_DATA_PKEY	12
> +#define LSM_AUDIT_DATA_PATH		1
> +#define LSM_AUDIT_DATA_NET		2
> +#define LSM_AUDIT_DATA_CAP		3
> +#define LSM_AUDIT_DATA_IPC		4
> +#define LSM_AUDIT_DATA_TASK		5
> +#define LSM_AUDIT_DATA_KEY		6
> +#define LSM_AUDIT_DATA_NONE		7
> +#define LSM_AUDIT_DATA_KMOD		8
> +#define LSM_AUDIT_DATA_INODE		9
> +#define LSM_AUDIT_DATA_DENTRY		10
> +#define LSM_AUDIT_DATA_IOCTL_OP		11
> +#define LSM_AUDIT_DATA_PKEY		12
> +#define LSM_AUDIT_DATA_IB_END_PORT	13
>  	union 	{
>  		struct path path;
>  		struct dentry *dentry;
> @@ -82,6 +89,7 @@ struct common_audit_data {
>  		char *kmod_name;
>  		struct lsm_ioctlop_audit *op;
>  		struct lsm_pkey_audit *pkey;
> +		struct lsm_ib_end_port_audit *ib_end_port;
>  	} u;
>  	/* this union contains LSM specific data */
>  	union {
> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> index 5a40b10..fc44542 100644
> --- a/security/selinux/hooks.c
> +++ b/security/selinux/hooks.c
> @@ -6056,6 +6056,32 @@ static int selinux_ib_mad_agent_pkey_access(u64 subnet_prefix, u16 pkey_val,
>  					mad_agent->m_security);
>  }
>  
> +static int selinux_ib_end_port_smp(const char *dev_name, u8 port,
> +				   struct ib_mad_agent *mad_agent)
> +{
> +	struct common_audit_data ad;
> +	int err;
> +	u32 sid = 0;
> +	struct ib_security_struct *sec = mad_agent->m_security;
> +	struct lsm_ib_end_port_audit ib_end_port;
> +
> +	err = security_ib_end_port_sid(dev_name, port, &sid);
> +
> +	if (err)
> +		goto out;
> +
> +	ad.type = LSM_AUDIT_DATA_IB_END_PORT;
> +	strncpy(ib_end_port.dev_name, dev_name, sizeof(ib_end_port.dev_name));
> +	ib_end_port.port = port;
> +	ad.u.ib_end_port = &ib_end_port;
> +	err = avc_has_perm(sec->sid, sid,
> +			   SECCLASS_INFINIBAND_END_PORT,
> +			   INFINIBAND_END_PORT__SMP, &ad);
> +
> +out:
> +	return err;
> +}
> +
>  static int selinux_ib_qp_alloc_security(struct ib_qp_security *qp_sec)
>  {
>  	struct ib_security_struct *sec;
> @@ -6289,6 +6315,7 @@ static struct security_hook_list selinux_hooks[] = {
>  	LSM_HOOK_INIT(ib_qp_pkey_access, selinux_ib_qp_pkey_access),
>  	LSM_HOOK_INIT(ib_mad_agent_pkey_access,
>  		      selinux_ib_mad_agent_pkey_access),
> +	LSM_HOOK_INIT(ib_end_port_smp, selinux_ib_end_port_smp),
>  	LSM_HOOK_INIT(ib_qp_alloc_security,
>  		      selinux_ib_qp_alloc_security),
>  	LSM_HOOK_INIT(ib_qp_free_security,
> diff --git a/security/selinux/include/classmap.h b/security/selinux/include/classmap.h
> index d42dd4d..21972c8 100644
> --- a/security/selinux/include/classmap.h
> +++ b/security/selinux/include/classmap.h
> @@ -167,5 +167,7 @@ struct security_class_mapping secclass_map[] = {
>  	  { COMMON_CAP2_PERMS, NULL } },
>  	{ "infiniband_pkey",
>  	  { "access", NULL } },
> +	{ "infiniband_end_port",
> +	  { "smp", NULL } },
>  	{ NULL }
>    };
> diff --git a/security/selinux/include/initial_sid_to_string.h b/security/selinux/include/initial_sid_to_string.h
> index 8f2eefc..ba47169 100644
> --- a/security/selinux/include/initial_sid_to_string.h
> +++ b/security/selinux/include/initial_sid_to_string.h
> @@ -30,5 +30,6 @@ static const char *initial_sid_to_string[] =
>      "scmp_packet",
>      "devnull",
>      "pkey",
> +    "ib_end_port",
>  };
>  
> diff --git a/security/selinux/include/security.h b/security/selinux/include/security.h
> index 8f1a66e..f5d9d4e 100644
> --- a/security/selinux/include/security.h
> +++ b/security/selinux/include/security.h
> @@ -182,6 +182,8 @@ int security_port_sid(u8 protocol, u16 port, u32 *out_sid);
>  
>  int security_pkey_sid(u64 subnet_prefix, u16 pkey_num, u32 *out_sid);
>  
> +int security_ib_end_port_sid(const char *dev_name, u8 port, u32 *out_sid);
> +
>  int security_netif_sid(char *name, u32 *if_sid);
>  
>  int security_node_sid(u16 domain, void *addr, u32 addrlen,
> diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
> index 49701a5..9afabee 100644
> --- a/security/selinux/ss/services.c
> +++ b/security/selinux/ss/services.c
> @@ -53,6 +53,7 @@
>  #include <linux/flex_array.h>
>  #include <linux/vmalloc.h>
>  #include <net/netlabel.h>
> +#include <rdma/ib_verbs.h>
>  
>  #include "flask.h"
>  #include "avc.h"
> @@ -2270,6 +2271,48 @@ out:
>  }
>  
>  /**
> + * security_ib_end_port_sid - Obtain the SID for a subnet management interface.
> + * @dev_name: device name
> + * @port: port number
> + * @out_sid: security identifier
> + */
> +int security_ib_end_port_sid(const char *dev_name, u8 port, u32 *out_sid)
> +{
> +	struct ocontext *c;
> +	int rc = 0;
> +
> +	read_lock(&policy_rwlock);
> +
> +	c = policydb.ocontexts[OCON_IB_END_PORT];
> +	while (c) {
> +		if (c->u.ib_end_port.port == port &&
> +		    !strncmp(c->u.ib_end_port.dev_name,
> +			    dev_name,
> +			    IB_DEVICE_NAME_MAX))
> +			break;
> +
> +		c = c->next;
> +	}
> +
> +	if (c) {
> +		if (!c->sid[0]) {
> +			rc = sidtab_context_to_sid(&sidtab,
> +						   &c->context[0],
> +						   &c->sid[0]);
> +			if (rc)
> +				goto out;
> +		}
> +		*out_sid = c->sid[0];
> +	} else {
> +		*out_sid = SECINITSID_IB_END_PORT;
> +	}

Curly braces are not allowed here

> +
> +out:
> +	read_unlock(&policy_rwlock);
> +	return rc;
> +}
> +
> +/**
>   * security_netif_sid - Obtain the SID for a network interface.
>   * @name: interface name
>   * @if_sid: interface SID
> -- 
> 1.8.3.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2016-06-30 15:31 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-23 19:52 [PATCH 00/12] SELinux support for Infiniband RDMA Dan Jurgens
2016-06-23 19:52 ` [PATCH 01/12] security: Add LSM hooks for Infiniband security Dan Jurgens
     [not found]   ` <1466711578-64398-2-git-send-email-danielj-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2016-06-30 14:57     ` Yuval Shaia
2016-06-30 20:27     ` Paul Moore
2016-06-30 21:09       ` Daniel Jurgens
2016-06-30 21:27         ` Paul Moore
2016-06-30 21:34           ` Daniel Jurgens
2016-06-30 20:33     ` Paul Moore
2016-06-30 21:27       ` Daniel Jurgens
     [not found]         ` <AM4PR0501MB2257674DEA1F81F53A35AC21C4240-dp/nxUn679hpbkYrVjfdjcDSnupUy6xnnBOFsp37pqbUKgpGm//BTAC/G2K4zDHf@public.gmane.org>
2016-06-30 21:30           ` Paul Moore
2016-06-23 19:52 ` [PATCH 02/12] selinux: Create policydb version for Infiniband support Dan Jurgens
     [not found]   ` <1466711578-64398-3-git-send-email-danielj-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2016-06-30 15:01     ` Yuval Shaia
     [not found]       ` <20160630150140.GB22107-Hxa29pjIrETlQW142y8m19+IiqhCXseY@public.gmane.org>
2016-07-01 12:50         ` Leon Romanovsky
2016-07-01 13:49           ` Daniel Jurgens
     [not found]             ` <DB6PR0501MB2261C7D467873122250A1F3EC4250-wTfl6qNNZ1NK98U9gK7MJ8DSnupUy6xnnBOFsp37pqbUKgpGm//BTAC/G2K4zDHf@public.gmane.org>
2016-07-01 20:48               ` Leon Romanovsky
2016-06-30 20:17     ` Paul Moore
2016-06-30 20:59       ` Daniel Jurgens
     [not found]         ` <AM4PR0501MB22579221434714783B0AFC68C4240-dp/nxUn679hpbkYrVjfdjcDSnupUy6xnnBOFsp37pqbUKgpGm//BTAC/G2K4zDHf@public.gmane.org>
2016-06-30 21:18           ` Paul Moore
2016-06-30 21:32             ` Daniel Jurgens
     [not found]               ` <AM4PR0501MB2257CB8E6F84835315734487C4240-dp/nxUn679hpbkYrVjfdjcDSnupUy6xnnBOFsp37pqbUKgpGm//BTAC/G2K4zDHf@public.gmane.org>
2016-06-30 21:37                 ` Paul Moore
2016-06-23 19:52 ` [PATCH 10/12] IB/core: Enforce PKey security on management datagrams Dan Jurgens
     [not found] ` <1466711578-64398-1-git-send-email-danielj-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2016-06-23 19:52   ` [PATCH 03/12] selinux: Implement Infiniband flush callback Dan Jurgens
     [not found]     ` <1466711578-64398-4-git-send-email-danielj-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2016-06-30 15:10       ` Yuval Shaia
2016-06-30 15:44         ` Daniel Jurgens
     [not found]           ` <AM4PR0501MB22578AA5FF8B4062F650C581C4240-dp/nxUn679hpbkYrVjfdjcDSnupUy6xnnBOFsp37pqbUKgpGm//BTAC/G2K4zDHf@public.gmane.org>
2016-06-30 19:52             ` Paul Moore
     [not found]               ` <CAGH-Kgtn0EFxYc+UOvVQk-0Bco0oOG=STZA+aGYza4TmbNXq3A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-06-30 20:16                 ` Casey Schaufler
     [not found]                   ` <13cf2b8b-1d4e-e61f-80fe-110af2a719cf-iSGtlc1asvQWG2LlvL+J4A@public.gmane.org>
2016-06-30 20:24                     ` Paul Moore
2016-06-30 20:39               ` Daniel Jurgens
2016-06-23 19:52   ` [PATCH 04/12] selinux: Allocate and free infiniband security hooks Dan Jurgens
     [not found]     ` <1466711578-64398-5-git-send-email-danielj-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2016-06-30 15:15       ` Yuval Shaia
2016-06-30 20:42       ` Paul Moore
     [not found]         ` <CAGH-KgvtN8T7e5bKq0jJZvSzrGfFwA2VpmPf5gJuqdLZi6odEw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-06-30 21:06           ` Casey Schaufler
2016-06-30 21:48             ` Daniel Jurgens
     [not found]               ` <AM4PR0501MB2257ADAB527392547179F779C4240-dp/nxUn679hpbkYrVjfdjcDSnupUy6xnnBOFsp37pqbUKgpGm//BTAC/G2K4zDHf@public.gmane.org>
2016-07-01 18:54                 ` Paul Moore
2016-07-01 18:59                   ` Daniel Jurgens
2016-07-01 19:17                     ` Paul Moore
2016-07-01 20:13                       ` Casey Schaufler
2016-07-01 20:46                         ` Daniel Jurgens
     [not found]                           ` <DB6PR0501MB226138FF74D031F6BD1C48C6C4250-wTfl6qNNZ1NK98U9gK7MJ8DSnupUy6xnnBOFsp37pqbUKgpGm//BTAC/G2K4zDHf@public.gmane.org>
2016-07-01 21:16                             ` Casey Schaufler
2016-07-01 22:15                           ` Paul Moore
2016-06-23 19:52   ` [PATCH 05/12] selinux: Implement Infiniband PKey "Access" access vector Dan Jurgens
     [not found]     ` <1466711578-64398-6-git-send-email-danielj-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2016-06-30 15:23       ` Yuval Shaia
2016-06-30 15:35         ` Daniel Jurgens
2016-07-01 16:29       ` Paul Moore
2016-07-01 18:21         ` Daniel Jurgens
2016-07-01 18:58           ` Paul Moore
2016-07-01 19:16             ` Daniel Jurgens
     [not found]               ` <DB6PR0501MB22614C80007D7408544B4B30C4250-wTfl6qNNZ1NK98U9gK7MJ8DSnupUy6xnnBOFsp37pqbUKgpGm//BTAC/G2K4zDHf@public.gmane.org>
2016-07-01 19:26                 ` Paul Moore
2016-07-01 19:57                   ` Daniel Jurgens
     [not found]                     ` <DB6PR0501MB2261C903AB4CE9644604B9E8C4250-wTfl6qNNZ1NK98U9gK7MJ8DSnupUy6xnnBOFsp37pqbUKgpGm//BTAC/G2K4zDHf@public.gmane.org>
2016-07-01 20:42                       ` Paul Moore
2016-07-11 14:46     ` Stephen Smalley
2016-07-11 19:03       ` Daniel Jurgens
     [not found]       ` <1c637b46-7352-b369-4891-4b695ff80b3b-+05T5uksL2qpZYMLLGbcSA@public.gmane.org>
2016-07-12 20:28         ` Paul Moore
2016-06-23 19:52   ` [PATCH 06/12] selinux: Add IB End Port SMP " Dan Jurgens
2016-06-30 15:31     ` Yuval Shaia [this message]
     [not found]     ` <1466711578-64398-7-git-send-email-danielj-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2016-07-01 18:48       ` Paul Moore
2016-06-23 19:52   ` [PATCH 07/12] selinux: Add a cache for quicker retreival of PKey SIDs Dan Jurgens
     [not found]     ` <1466711578-64398-8-git-send-email-danielj-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2016-06-23 21:59       ` kbuild test robot
2016-06-30 15:41       ` Yuval Shaia
2016-07-01 18:51       ` Paul Moore
2016-06-23 19:52   ` [PATCH 08/12] IB/core: IB cache enhancements to support Infiniband security Dan Jurgens
     [not found]     ` <1466711578-64398-9-git-send-email-danielj-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2016-06-30 15:47       ` Yuval Shaia
2016-06-23 19:52   ` [PATCH 09/12] IB/core: Enforce PKey security on QPs Dan Jurgens
2016-06-23 19:52   ` [PATCH 11/12] IB/core: Enforce Infiniband device SMI security Dan Jurgens
2016-06-23 19:52   ` [PATCH 12/12] IB/core: Implement the Infiniband flush callback Dan Jurgens
2016-06-30 14:43   ` [PATCH 00/12] SELinux support for Infiniband RDMA Yuval Shaia
2016-06-30 14:47     ` Daniel Jurgens
2016-06-29 17:33 ` Paul Moore
2016-06-29 19:09   ` Daniel Jurgens
     [not found]     ` <DB6PR0501MB22611E2BA664DD033571AEDEC4230-wTfl6qNNZ1NK98U9gK7MJ8DSnupUy6xnnBOFsp37pqbUKgpGm//BTAC/G2K4zDHf@public.gmane.org>
2016-06-30 15:18       ` Paul Moore

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160630153113.GF22107@yuval-lap.uk.oracle.com \
    --to=yuval.shaia@oracle.com \
    --cc=chrisw@sous-sol.org \
    --cc=danielj@mellanox.com \
    --cc=dledford@redhat.com \
    --cc=eparis@parisplace.org \
    --cc=hal.rosenstock@gmail.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=paul@paul-moore.com \
    --cc=sds@tycho.nsa.gov \
    --cc=sean.hefty@intel.com \
    --cc=selinux@tycho.nsa.gov \
    --cc=yevgenyp@mellanox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox