public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH rdma-next v2 0/9] Check CAP_NET_RAW in right namespace
@ 2025-06-26 18:58 Leon Romanovsky
  2025-06-26 18:58 ` [PATCH rdma-next v2 1/9] RDMA/uverbs: Check CAP_NET_RAW in user namespace for flow create Leon Romanovsky
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: Leon Romanovsky @ 2025-06-26 18:58 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: Eric W . Biederman, linux-rdma, Mark Bloch, Parav Pandit

Changelog:
v2:
 * Resend right series
 * Split "RDMA/uverbs: Check CAP_NET_RAW in user namespace for QP create"
 * to three small patches. Maybe I should squash them when I'll  apply.
v1: https://lore.kernel.org/all/cover.1750938869.git.leon@kernel.org
 * Moved QP checks to be earlier.
v0: https://lore.kernel.org/all/cover.1750148509.git.leon@kernel.org

The following series from Parav clears the mud where against which
namespace the CAP_NET_RAW should be checked.

It is followup of this discussion:
https://lore.kernel.org/all/20250313050832.113030-1-parav@nvidia.com

Thanks


Parav Pandit (9):
  RDMA/uverbs: Check CAP_NET_RAW in user namespace for flow create
  RDMA/mlx5: Check CAP_NET_RAW in user namespace for flow create
  RDMA/mlx5: Check CAP_NET_RAW in user namespace for anchor create
  RDMA/uverbs: Check CAP_NET_RAW in user namespace for QP create
  RDMA/uverbs: Check CAP_NET_RAW in user namespace for RAW QP create
  RDMA/uverbs: Check CAP_NET_RAW in user namespace for RAW QP create
  RDMA/mlx5: Check CAP_NET_RAW in user namespace for devx create
  RDMA/nldev: Check CAP_NET_RAW in user namespace for QP modify
  RDMA/counter: Check CAP_NET_RAW check in user namespace for RDMA
    counters

 drivers/infiniband/core/counters.c            |  2 +-
 drivers/infiniband/core/device.c              | 27 +++++++++++++++++
 drivers/infiniband/core/nldev.c               |  2 +-
 drivers/infiniband/core/rdma_core.c           | 29 +++++++++++++++++++
 drivers/infiniband/core/uverbs_cmd.c          | 10 +++----
 drivers/infiniband/core/uverbs_std_types_qp.c |  2 +-
 drivers/infiniband/hw/mlx5/devx.c             |  2 +-
 drivers/infiniband/hw/mlx5/fs.c               |  4 +--
 include/rdma/ib_verbs.h                       |  3 ++
 9 files changed, 70 insertions(+), 11 deletions(-)

-- 
2.49.0


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH rdma-next v2 1/9] RDMA/uverbs: Check CAP_NET_RAW in user namespace for flow create
  2025-06-26 18:58 [PATCH rdma-next v2 0/9] Check CAP_NET_RAW in right namespace Leon Romanovsky
@ 2025-06-26 18:58 ` Leon Romanovsky
  2025-06-26 18:58 ` [PATCH rdma-next v2 2/9] RDMA/mlx5: " Leon Romanovsky
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Leon Romanovsky @ 2025-06-26 18:58 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: Parav Pandit, Eric W . Biederman, linux-rdma, Mark Bloch

From: Parav Pandit <parav@nvidia.com>

Currently, the capability check is done in the default
init_user_ns user namespace. When a process runs in a
non default user namespace, such check fails. Due to this
when a process is running using Podman, it fails to create
the flow resource.

Since the RDMA device is a resource within a network namespace,
use the network namespace associated with the RDMA device to
determine its owning user namespace.

Fixes: 436f2ad05a0b ("IB/core: Export ib_create/destroy_flow through uverbs")
Signed-off-by: Parav Pandit <parav@nvidia.com>
Suggested-by: Eric W. Biederman <ebiederm@xmission.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
 drivers/infiniband/core/device.c     | 27 ++++++++++++++++++++++++++
 drivers/infiniband/core/rdma_core.c  | 29 ++++++++++++++++++++++++++++
 drivers/infiniband/core/uverbs_cmd.c |  2 +-
 include/rdma/ib_verbs.h              |  3 +++
 4 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
index c0f8b8cba7c0..1ca6a9b7ba1a 100644
--- a/drivers/infiniband/core/device.c
+++ b/drivers/infiniband/core/device.c
@@ -145,6 +145,33 @@ bool rdma_dev_access_netns(const struct ib_device *dev, const struct net *net)
 }
 EXPORT_SYMBOL(rdma_dev_access_netns);
 
+/**
+ * rdma_dev_has_raw_cap() - Returns whether a specified rdma device has
+ *			    CAP_NET_RAW capability or not.
+ *
+ * @dev:	Pointer to rdma device whose capability to be checked
+ *
+ * Returns true if a rdma device's owning user namespace has CAP_NET_RAW
+ * capability, otherwise false. When rdma subsystem is in legacy shared network,
+ * namespace mode, the default net namespace is considered.
+ */
+bool rdma_dev_has_raw_cap(const struct ib_device *dev)
+{
+	const struct net *net;
+
+	/* Network namespace is the resource whose user namespace
+	 * to be considered. When in shared mode, there is no reliable
+	 * network namespace resource, so consider the default net namespace.
+	 */
+	if (ib_devices_shared_netns)
+		net = &init_net;
+	else
+		net = read_pnet(&dev->coredev.rdma_net);
+
+	return ns_capable(net->user_ns, CAP_NET_RAW);
+}
+EXPORT_SYMBOL(rdma_dev_has_raw_cap);
+
 /*
  * xarray has this behavior where it won't iterate over NULL values stored in
  * allocated arrays.  So we need our own iterator to see all values stored in
diff --git a/drivers/infiniband/core/rdma_core.c b/drivers/infiniband/core/rdma_core.c
index 90c177edf9b0..18918f463361 100644
--- a/drivers/infiniband/core/rdma_core.c
+++ b/drivers/infiniband/core/rdma_core.c
@@ -1019,3 +1019,32 @@ void uverbs_finalize_object(struct ib_uobject *uobj,
 		WARN_ON(true);
 	}
 }
+
+/**
+ * rdma_uattrs_has_raw_cap() - Returns whether a rdma device linked to the
+ *			       uverbs attributes file has CAP_NET_RAW
+ *			       capability or not.
+ *
+ * @attrs:       Pointer to uverbs attributes
+ *
+ * Returns true if a rdma device's owning user namespace has CAP_NET_RAW
+ * capability, otherwise false.
+ */
+bool rdma_uattrs_has_raw_cap(const struct uverbs_attr_bundle *attrs)
+{
+	struct ib_uverbs_file *ufile = attrs->ufile;
+	struct ib_ucontext *ucontext;
+	bool has_cap = false;
+	int srcu_key;
+
+	srcu_key = srcu_read_lock(&ufile->device->disassociate_srcu);
+	ucontext = ib_uverbs_get_ucontext_file(ufile);
+	if (IS_ERR(ucontext))
+		goto out;
+	has_cap = rdma_dev_has_raw_cap(ucontext->device);
+
+out:
+	srcu_read_unlock(&ufile->device->disassociate_srcu, srcu_key);
+	return has_cap;
+}
+EXPORT_SYMBOL(rdma_uattrs_has_raw_cap);
diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c
index bc9fe3ceca4d..6700c2c66167 100644
--- a/drivers/infiniband/core/uverbs_cmd.c
+++ b/drivers/infiniband/core/uverbs_cmd.c
@@ -3225,7 +3225,7 @@ static int ib_uverbs_ex_create_flow(struct uverbs_attr_bundle *attrs)
 	if (cmd.comp_mask)
 		return -EINVAL;
 
-	if (!capable(CAP_NET_RAW))
+	if (!rdma_uattrs_has_raw_cap(attrs))
 		return -EPERM;
 
 	if (cmd.flow_attr.flags >= IB_FLOW_ATTR_FLAGS_RESERVED)
diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h
index 7da27f01eeb6..010594dc755b 100644
--- a/include/rdma/ib_verbs.h
+++ b/include/rdma/ib_verbs.h
@@ -4817,6 +4817,8 @@ static inline int uverbs_destroy_def_handler(struct uverbs_attr_bundle *attrs)
 }
 #endif
 
+bool rdma_uattrs_has_raw_cap(const struct uverbs_attr_bundle *attrs);
+
 struct net_device *rdma_alloc_netdev(struct ib_device *device, u32 port_num,
 				     enum rdma_netdev_t type, const char *name,
 				     unsigned char name_assign_type,
@@ -4871,6 +4873,7 @@ static inline int ibdev_to_node(struct ib_device *ibdev)
 bool rdma_dev_access_netns(const struct ib_device *device,
 			   const struct net *net);
 
+bool rdma_dev_has_raw_cap(const struct ib_device *dev);
 static inline struct net *rdma_dev_net(struct ib_device *device)
 {
 	return read_pnet(&device->coredev.rdma_net);
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH rdma-next v2 2/9] RDMA/mlx5: Check CAP_NET_RAW in user namespace for flow create
  2025-06-26 18:58 [PATCH rdma-next v2 0/9] Check CAP_NET_RAW in right namespace Leon Romanovsky
  2025-06-26 18:58 ` [PATCH rdma-next v2 1/9] RDMA/uverbs: Check CAP_NET_RAW in user namespace for flow create Leon Romanovsky
@ 2025-06-26 18:58 ` Leon Romanovsky
  2025-06-26 18:58 ` [PATCH rdma-next v2 3/9] RDMA/mlx5: Check CAP_NET_RAW in user namespace for anchor create Leon Romanovsky
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Leon Romanovsky @ 2025-06-26 18:58 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: Parav Pandit, Eric W . Biederman, linux-rdma, Mark Bloch

From: Parav Pandit <parav@nvidia.com>

Currently, the capability check is done in the default
init_user_ns user namespace. When a process runs in a
non default user namespace, such check fails. Due to this
when a process is running using Podman, it fails to create
the flow.

Since the RDMA device is a resource within a network namespace,
use the network namespace associated with the RDMA device to
determine its owning user namespace.

Fixes: 322694412400 ("IB/mlx5: Introduce driver create and destroy flow methods")
Signed-off-by: Parav Pandit <parav@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
 drivers/infiniband/hw/mlx5/fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/infiniband/hw/mlx5/fs.c b/drivers/infiniband/hw/mlx5/fs.c
index ebcc05f766e1..58e058c067d3 100644
--- a/drivers/infiniband/hw/mlx5/fs.c
+++ b/drivers/infiniband/hw/mlx5/fs.c
@@ -2459,7 +2459,7 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_CREATE_FLOW)(
 	struct mlx5_ib_dev *dev;
 	u32 flags;
 
-	if (!capable(CAP_NET_RAW))
+	if (!rdma_uattrs_has_raw_cap(attrs))
 		return -EPERM;
 
 	fs_matcher = uverbs_attr_get_obj(attrs,
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH rdma-next v2 3/9] RDMA/mlx5: Check CAP_NET_RAW in user namespace for anchor create
  2025-06-26 18:58 [PATCH rdma-next v2 0/9] Check CAP_NET_RAW in right namespace Leon Romanovsky
  2025-06-26 18:58 ` [PATCH rdma-next v2 1/9] RDMA/uverbs: Check CAP_NET_RAW in user namespace for flow create Leon Romanovsky
  2025-06-26 18:58 ` [PATCH rdma-next v2 2/9] RDMA/mlx5: " Leon Romanovsky
@ 2025-06-26 18:58 ` Leon Romanovsky
  2025-06-26 18:58 ` [PATCH rdma-next v2 4/9] RDMA/uverbs: Check CAP_NET_RAW in user namespace for QP create Leon Romanovsky
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Leon Romanovsky @ 2025-06-26 18:58 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: Parav Pandit, Eric W . Biederman, linux-rdma, Mark Bloch

From: Parav Pandit <parav@nvidia.com>

Currently, the capability check is done in the default
init_user_ns user namespace. When a process runs in a
non default user namespace, such check fails. Due to this
when a process is running using Podman, it fails to create
the anchor.

Since the RDMA device is a resource within a network namespace,
use the network namespace associated with the RDMA device to
determine its owning user namespace.

Fixes: 0c6ab0ca9a66 ("RDMA/mlx5: Expose steering anchor to userspace")
Signed-off-by: Parav Pandit <parav@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
 drivers/infiniband/hw/mlx5/fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/infiniband/hw/mlx5/fs.c b/drivers/infiniband/hw/mlx5/fs.c
index 58e058c067d3..bab2f58240c9 100644
--- a/drivers/infiniband/hw/mlx5/fs.c
+++ b/drivers/infiniband/hw/mlx5/fs.c
@@ -2990,7 +2990,7 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_STEERING_ANCHOR_CREATE)(
 	u32 ft_id;
 	int err;
 
-	if (!capable(CAP_NET_RAW))
+	if (!rdma_dev_has_raw_cap(&dev->ib_dev))
 		return -EPERM;
 
 	err = uverbs_get_const(&ib_uapi_ft_type, attrs,
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH rdma-next v2 4/9] RDMA/uverbs: Check CAP_NET_RAW in user namespace for QP create
  2025-06-26 18:58 [PATCH rdma-next v2 0/9] Check CAP_NET_RAW in right namespace Leon Romanovsky
                   ` (2 preceding siblings ...)
  2025-06-26 18:58 ` [PATCH rdma-next v2 3/9] RDMA/mlx5: Check CAP_NET_RAW in user namespace for anchor create Leon Romanovsky
@ 2025-06-26 18:58 ` Leon Romanovsky
  2025-06-26 18:58 ` [PATCH rdma-next v2 5/9] RDMA/uverbs: Check CAP_NET_RAW in user namespace for RAW " Leon Romanovsky
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Leon Romanovsky @ 2025-06-26 18:58 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: Parav Pandit, Eric W . Biederman, linux-rdma, Mark Bloch

From: Parav Pandit <parav@nvidia.com>

Currently, the capability check is done in the default
init_user_ns user namespace. When a process runs in a
non default user namespace, such check fails. Due to this
when a process is running using Podman, it fails to create
the QP.

Since the RDMA device is a resource within a network namespace,
use the network namespace associated with the RDMA device to
determine its owning user namespace.

Fixes: 2dee0e545894 ("IB/uverbs: Enable QP creation with a given source QP number")
Signed-off-by: Parav Pandit <parav@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
 drivers/infiniband/core/uverbs_cmd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c
index 6700c2c66167..4d96e4a678f3 100644
--- a/drivers/infiniband/core/uverbs_cmd.c
+++ b/drivers/infiniband/core/uverbs_cmd.c
@@ -1451,7 +1451,7 @@ static int create_qp(struct uverbs_attr_bundle *attrs,
 	}
 
 	if (attr.create_flags & IB_QP_CREATE_SOURCE_QPN) {
-		if (!capable(CAP_NET_RAW)) {
+		if (!rdma_uattrs_has_raw_cap(attrs)) {
 			ret = -EPERM;
 			goto err_put;
 		}
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH rdma-next v2 5/9] RDMA/uverbs: Check CAP_NET_RAW in user namespace for RAW QP create
  2025-06-26 18:58 [PATCH rdma-next v2 0/9] Check CAP_NET_RAW in right namespace Leon Romanovsky
                   ` (3 preceding siblings ...)
  2025-06-26 18:58 ` [PATCH rdma-next v2 4/9] RDMA/uverbs: Check CAP_NET_RAW in user namespace for QP create Leon Romanovsky
@ 2025-06-26 18:58 ` Leon Romanovsky
  2025-06-26 18:58 ` [PATCH rdma-next v2 6/9] " Leon Romanovsky
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Leon Romanovsky @ 2025-06-26 18:58 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: Parav Pandit, Eric W . Biederman, linux-rdma, Mark Bloch

From: Parav Pandit <parav@nvidia.com>

Currently, the capability check is done in the default
init_user_ns user namespace. When a process runs in a
non default user namespace, such check fails. Due to this
when a process is running using Podman, it fails to create
the QP.

Since the RDMA device is a resource within a network namespace,
use the network namespace associated with the RDMA device to
determine its owning user namespace.

Fixes: 6d1e7ba241e9 ("IB/uverbs: Introduce create/destroy QP commands over ioctl")
Signed-off-by: Parav Pandit <parav@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
 drivers/infiniband/core/uverbs_std_types_qp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/infiniband/core/uverbs_std_types_qp.c b/drivers/infiniband/core/uverbs_std_types_qp.c
index 7b4773fa4bc0..be0730e8509e 100644
--- a/drivers/infiniband/core/uverbs_std_types_qp.c
+++ b/drivers/infiniband/core/uverbs_std_types_qp.c
@@ -133,7 +133,7 @@ static int UVERBS_HANDLER(UVERBS_METHOD_QP_CREATE)(
 		device = xrcd->device;
 		break;
 	case IB_UVERBS_QPT_RAW_PACKET:
-		if (!capable(CAP_NET_RAW))
+		if (!rdma_uattrs_has_raw_cap(attrs))
 			return -EPERM;
 		fallthrough;
 	case IB_UVERBS_QPT_RC:
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH rdma-next v2 6/9] RDMA/uverbs: Check CAP_NET_RAW in user namespace for RAW QP create
  2025-06-26 18:58 [PATCH rdma-next v2 0/9] Check CAP_NET_RAW in right namespace Leon Romanovsky
                   ` (4 preceding siblings ...)
  2025-06-26 18:58 ` [PATCH rdma-next v2 5/9] RDMA/uverbs: Check CAP_NET_RAW in user namespace for RAW " Leon Romanovsky
@ 2025-06-26 18:58 ` Leon Romanovsky
  2025-06-26 18:58 ` [PATCH rdma-next v2 7/9] RDMA/mlx5: Check CAP_NET_RAW in user namespace for devx create Leon Romanovsky
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Leon Romanovsky @ 2025-06-26 18:58 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: Parav Pandit, Eric W . Biederman, linux-rdma, Mark Bloch

From: Parav Pandit <parav@nvidia.com>

Currently, the capability check is done in the default
init_user_ns user namespace. When a process runs in a
non default user namespace, such check fails. Due to this
when a process is running using Podman, it fails to create
the QP.

Since the RDMA device is a resource within a network namespace,
use the network namespace associated with the RDMA device to
determine its owning user namespace.

Signed-off-by: Parav Pandit <parav@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
 drivers/infiniband/core/uverbs_cmd.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c
index 4d96e4a678f3..deb9f3370db7 100644
--- a/drivers/infiniband/core/uverbs_cmd.c
+++ b/drivers/infiniband/core/uverbs_cmd.c
@@ -1312,9 +1312,8 @@ static int create_qp(struct uverbs_attr_bundle *attrs,
 
 	switch (cmd->qp_type) {
 	case IB_QPT_RAW_PACKET:
-		if (!capable(CAP_NET_RAW))
+		if (!rdma_uattrs_has_raw_cap(attrs))
 			return -EPERM;
-		break;
 	case IB_QPT_RC:
 	case IB_QPT_UC:
 	case IB_QPT_UD:
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH rdma-next v2 7/9] RDMA/mlx5: Check CAP_NET_RAW in user namespace for devx create
  2025-06-26 18:58 [PATCH rdma-next v2 0/9] Check CAP_NET_RAW in right namespace Leon Romanovsky
                   ` (5 preceding siblings ...)
  2025-06-26 18:58 ` [PATCH rdma-next v2 6/9] " Leon Romanovsky
@ 2025-06-26 18:58 ` Leon Romanovsky
  2025-06-26 18:58 ` [PATCH rdma-next v2 8/9] RDMA/nldev: Check CAP_NET_RAW in user namespace for QP modify Leon Romanovsky
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Leon Romanovsky @ 2025-06-26 18:58 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: Parav Pandit, Eric W . Biederman, linux-rdma, Mark Bloch

From: Parav Pandit <parav@nvidia.com>

Currently, the capability check is done in the default
init_user_ns user namespace. When a process runs in a
non default user namespace, such check fails. Due to this
when a process is running using Podman, it fails to create
the devx object.

Since the RDMA device is a resource within a network namespace,
use the network namespace associated with the RDMA device to
determine its owning user namespace.

Fixes: a8b92ca1b0e5 ("IB/mlx5: Introduce DEVX")
Signed-off-by: Parav Pandit <parav@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
 drivers/infiniband/hw/mlx5/devx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/infiniband/hw/mlx5/devx.c b/drivers/infiniband/hw/mlx5/devx.c
index e5551736ee14..44b4521619c4 100644
--- a/drivers/infiniband/hw/mlx5/devx.c
+++ b/drivers/infiniband/hw/mlx5/devx.c
@@ -159,7 +159,7 @@ int mlx5_ib_devx_create(struct mlx5_ib_dev *dev, bool is_user, u64 req_ucaps)
 	uctx = MLX5_ADDR_OF(create_uctx_in, in, uctx);
 	if (is_user &&
 	    (MLX5_CAP_GEN(dev->mdev, uctx_cap) & MLX5_UCTX_CAP_RAW_TX) &&
-	    capable(CAP_NET_RAW))
+	    rdma_dev_has_raw_cap(&dev->ib_dev))
 		cap |= MLX5_UCTX_CAP_RAW_TX;
 	if (is_user &&
 	    (MLX5_CAP_GEN(dev->mdev, uctx_cap) &
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH rdma-next v2 8/9] RDMA/nldev: Check CAP_NET_RAW in user namespace for QP modify
  2025-06-26 18:58 [PATCH rdma-next v2 0/9] Check CAP_NET_RAW in right namespace Leon Romanovsky
                   ` (6 preceding siblings ...)
  2025-06-26 18:58 ` [PATCH rdma-next v2 7/9] RDMA/mlx5: Check CAP_NET_RAW in user namespace for devx create Leon Romanovsky
@ 2025-06-26 18:58 ` Leon Romanovsky
  2025-06-26 18:58 ` [PATCH rdma-next v2 9/9] RDMA/counter: Check CAP_NET_RAW check in user namespace for RDMA counters Leon Romanovsky
  2025-07-01  9:22 ` [PATCH rdma-next v2 0/9] Check CAP_NET_RAW in right namespace Leon Romanovsky
  9 siblings, 0 replies; 11+ messages in thread
From: Leon Romanovsky @ 2025-06-26 18:58 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: Parav Pandit, Eric W . Biederman, linux-rdma, Mark Bloch

From: Parav Pandit <parav@nvidia.com>

Currently, the capability check is done in the default
init_user_ns user namespace. When a process runs in a
non default user namespace, such check fails. Due to this
when a process is running using Podman, it fails to modify
the QP.

Since the RDMA device is a resource within a network namespace,
use the network namespace associated with the RDMA device to
determine its owning user namespace.

Fixes: 0cadb4db79e1 ("RDMA/uverbs: Restrict usage of privileged QKEYs")
Signed-off-by: Parav Pandit <parav@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
 drivers/infiniband/core/nldev.c      | 2 +-
 drivers/infiniband/core/uverbs_cmd.c | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/core/nldev.c b/drivers/infiniband/core/nldev.c
index e9b7a6419291..2220a2dfab24 100644
--- a/drivers/infiniband/core/nldev.c
+++ b/drivers/infiniband/core/nldev.c
@@ -255,7 +255,7 @@ EXPORT_SYMBOL(rdma_nl_put_driver_u64_hex);
 
 bool rdma_nl_get_privileged_qkey(void)
 {
-	return privileged_qkey || capable(CAP_NET_RAW);
+	return privileged_qkey;
 }
 EXPORT_SYMBOL(rdma_nl_get_privileged_qkey);
 
diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c
index deb9f3370db7..dfaaf161d3f2 100644
--- a/drivers/infiniband/core/uverbs_cmd.c
+++ b/drivers/infiniband/core/uverbs_cmd.c
@@ -1876,7 +1876,8 @@ static int modify_qp(struct uverbs_attr_bundle *attrs,
 		attr->path_mig_state = cmd->base.path_mig_state;
 	if (cmd->base.attr_mask & IB_QP_QKEY) {
 		if (cmd->base.qkey & IB_QP_SET_QKEY &&
-		    !rdma_nl_get_privileged_qkey()) {
+		    !(rdma_nl_get_privileged_qkey() ||
+		      rdma_uattrs_has_raw_cap(attrs))) {
 			ret = -EPERM;
 			goto release_qp;
 		}
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH rdma-next v2 9/9] RDMA/counter: Check CAP_NET_RAW check in user namespace for RDMA counters
  2025-06-26 18:58 [PATCH rdma-next v2 0/9] Check CAP_NET_RAW in right namespace Leon Romanovsky
                   ` (7 preceding siblings ...)
  2025-06-26 18:58 ` [PATCH rdma-next v2 8/9] RDMA/nldev: Check CAP_NET_RAW in user namespace for QP modify Leon Romanovsky
@ 2025-06-26 18:58 ` Leon Romanovsky
  2025-07-01  9:22 ` [PATCH rdma-next v2 0/9] Check CAP_NET_RAW in right namespace Leon Romanovsky
  9 siblings, 0 replies; 11+ messages in thread
From: Leon Romanovsky @ 2025-06-26 18:58 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: Parav Pandit, Eric W . Biederman, linux-rdma, Mark Bloch

From: Parav Pandit <parav@nvidia.com>

Currently, the capability check is done in the default
init_user_ns user namespace. When a process runs in a
non default user namespace, such check fails.

Since the RDMA device is a resource within a network namespace,
use the network namespace associated with the RDMA device to
determine its owning user namespace.

Fixes: 1bd8e0a9d0fd ("RDMA/counter: Allow manual mode configuration support")
Signed-off-by: Parav Pandit <parav@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
 drivers/infiniband/core/counters.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/infiniband/core/counters.c b/drivers/infiniband/core/counters.c
index e6ec7b7a40af..c3aa6d7fc66b 100644
--- a/drivers/infiniband/core/counters.c
+++ b/drivers/infiniband/core/counters.c
@@ -461,7 +461,7 @@ static struct ib_qp *rdma_counter_get_qp(struct ib_device *dev, u32 qp_num)
 		return NULL;
 
 	qp = container_of(res, struct ib_qp, res);
-	if (qp->qp_type == IB_QPT_RAW_PACKET && !capable(CAP_NET_RAW))
+	if (qp->qp_type == IB_QPT_RAW_PACKET && !rdma_dev_has_raw_cap(dev))
 		goto err;
 
 	return qp;
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH rdma-next v2 0/9] Check CAP_NET_RAW in right namespace
  2025-06-26 18:58 [PATCH rdma-next v2 0/9] Check CAP_NET_RAW in right namespace Leon Romanovsky
                   ` (8 preceding siblings ...)
  2025-06-26 18:58 ` [PATCH rdma-next v2 9/9] RDMA/counter: Check CAP_NET_RAW check in user namespace for RDMA counters Leon Romanovsky
@ 2025-07-01  9:22 ` Leon Romanovsky
  9 siblings, 0 replies; 11+ messages in thread
From: Leon Romanovsky @ 2025-07-01  9:22 UTC (permalink / raw)
  To: Jason Gunthorpe, Leon Romanovsky
  Cc: Eric W . Biederman, linux-rdma, Mark Bloch, Parav Pandit


On Thu, 26 Jun 2025 21:58:03 +0300, Leon Romanovsky wrote:
> Changelog:
> v2:
>  * Resend right series
>  * Split "RDMA/uverbs: Check CAP_NET_RAW in user namespace for QP create"
>  * to three small patches. Maybe I should squash them when I'll  apply.
> v1: https://lore.kernel.org/all/cover.1750938869.git.leon@kernel.org
>  * Moved QP checks to be earlier.
> v0: https://lore.kernel.org/all/cover.1750148509.git.leon@kernel.org
> 
> [...]

Applied, thanks!

[1/9] RDMA/uverbs: Check CAP_NET_RAW in user namespace for flow create
      https://git.kernel.org/rdma/rdma/c/f458ccd2aa2c5a
[2/9] RDMA/mlx5: Check CAP_NET_RAW in user namespace for flow create
      https://git.kernel.org/rdma/rdma/c/95a89ec304c38f
[3/9] RDMA/mlx5: Check CAP_NET_RAW in user namespace for anchor create
      https://git.kernel.org/rdma/rdma/c/14957e8125e767
[4/9] RDMA/uverbs: Check CAP_NET_RAW in user namespace for QP create
      https://git.kernel.org/rdma/rdma/c/0498c2d9984ed2
[5/9] RDMA/uverbs: Check CAP_NET_RAW in user namespace for RAW QP create
      https://git.kernel.org/rdma/rdma/c/c961a341c2c2c2
[6/9] RDMA/uverbs: Check CAP_NET_RAW in user namespace for RAW QP create
      https://git.kernel.org/rdma/rdma/c/c961a341c2c2c2
[7/9] RDMA/mlx5: Check CAP_NET_RAW in user namespace for devx create
      https://git.kernel.org/rdma/rdma/c/b5911befe2f910
[8/9] RDMA/nldev: Check CAP_NET_RAW in user namespace for QP modify
      https://git.kernel.org/rdma/rdma/c/282742fd826ba5
[9/9] RDMA/counter: Check CAP_NET_RAW check in user namespace for RDMA counters
      https://git.kernel.org/rdma/rdma/c/d7d403f74f236d

Best regards,
-- 
Leon Romanovsky <leon@kernel.org>


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-07-01  9:22 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-26 18:58 [PATCH rdma-next v2 0/9] Check CAP_NET_RAW in right namespace Leon Romanovsky
2025-06-26 18:58 ` [PATCH rdma-next v2 1/9] RDMA/uverbs: Check CAP_NET_RAW in user namespace for flow create Leon Romanovsky
2025-06-26 18:58 ` [PATCH rdma-next v2 2/9] RDMA/mlx5: " Leon Romanovsky
2025-06-26 18:58 ` [PATCH rdma-next v2 3/9] RDMA/mlx5: Check CAP_NET_RAW in user namespace for anchor create Leon Romanovsky
2025-06-26 18:58 ` [PATCH rdma-next v2 4/9] RDMA/uverbs: Check CAP_NET_RAW in user namespace for QP create Leon Romanovsky
2025-06-26 18:58 ` [PATCH rdma-next v2 5/9] RDMA/uverbs: Check CAP_NET_RAW in user namespace for RAW " Leon Romanovsky
2025-06-26 18:58 ` [PATCH rdma-next v2 6/9] " Leon Romanovsky
2025-06-26 18:58 ` [PATCH rdma-next v2 7/9] RDMA/mlx5: Check CAP_NET_RAW in user namespace for devx create Leon Romanovsky
2025-06-26 18:58 ` [PATCH rdma-next v2 8/9] RDMA/nldev: Check CAP_NET_RAW in user namespace for QP modify Leon Romanovsky
2025-06-26 18:58 ` [PATCH rdma-next v2 9/9] RDMA/counter: Check CAP_NET_RAW check in user namespace for RDMA counters Leon Romanovsky
2025-07-01  9:22 ` [PATCH rdma-next v2 0/9] Check CAP_NET_RAW in right namespace Leon Romanovsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox