[openib-general] [PATCH] [uCM] prevent userspace from using SDP/CMA SIDs

Sean Hefty sean.hefty at intel.com
Fri Dec 9 14:55:18 PST 2005


The following patch rejects requests from userspace to use either the SDP
or CMA service IDs.

Signed-off-by: Sean Hefty <sean.hefty at intel.com>


Index: core/ucm.c
===================================================================
--- core/ucm.c	(revision 4356)
+++ core/ucm.c	(working copy)
@@ -645,6 +645,17 @@ out:
 	return result;
 }
 
+static int ucm_validate_listen(__be64 service_id, __be64 service_mask)
+{
+	service_id &= service_mask;
+
+	if (((service_id & IB_CMA_SERVICE_ID_MASK) == IB_CMA_SERVICE_ID) ||
+	    ((service_id & IB_SDP_SERVICE_ID_MASK) == IB_SDP_SERVICE_ID))
+		return -EINVAL;
+
+	return 0;
+}
+
 static ssize_t ib_ucm_listen(struct ib_ucm_file *file,
 			     const char __user *inbuf,
 			     int in_len, int out_len)
@@ -660,8 +671,13 @@ static ssize_t ib_ucm_listen(struct ib_u
 	if (IS_ERR(ctx))
 		return PTR_ERR(ctx);
 
+	result = ucm_validate_listen(cmd.service_id, cmd.service_mask);
+	if (result)
+		goto out;
+
 	result = ib_cm_listen(ctx->cm_id, cmd.service_id, cmd.service_mask,
 			      NULL);
+out:
 	ib_ucm_ctx_put(ctx);
 	return result;
 }
Index: include/rdma/ib_cm.h
===================================================================
--- include/rdma/ib_cm.h	(revision 4356)
+++ include/rdma/ib_cm.h	(working copy)
@@ -317,6 +317,10 @@ void ib_destroy_cm_id(struct ib_cm_id *c
 
 #define IB_SERVICE_ID_AGN_MASK	__constant_cpu_to_be64(0xFF00000000000000ULL)
 #define IB_CM_ASSIGN_SERVICE_ID __constant_cpu_to_be64(0x0200000000000000ULL)
+#define IB_CMA_SERVICE_ID	__constant_cpu_to_be64(0x0000000001000000ULL)
+#define IB_CMA_SERVICE_ID_MASK	__constant_cpu_to_be64(0xFFFFFFFFFF000000ULL)
+#define IB_SDP_SERVICE_ID	__constant_cpu_to_be64(0x0000000000010000ULL)
+#define IB_SDP_SERVICE_ID_MASK	__constant_cpu_to_be64(0xFFFFFFFFFFFF0000ULL)
 
 struct ib_cm_private_data_compare {
 	u8  data[IB_CM_PRIVATE_DATA_COMPARE_SIZE];






More information about the general mailing list