Check CAP_NET_RAW in right namespace
Subsystems (2)
v2 cover Check CAP_NET_RAW in right namespace
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/[email protected]
* Moved QP checks to be earlier.
v0: https://lore.kernel.org/all/[email protected]
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/[email protected]
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(-)
Signature · 1 line
2.49.0
PATCH v2 2/9 RDMA/mlx5: Check CAP_NET_RAW in user namespace for flow create
From: Parav Pandit <[email protected]>
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.
--- drivers/infiniband/hw/mlx5/fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/mlx5/fs.c +1 -1
@@ -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,
Signature · 1 line
2.49.0
PATCH v2 3/9 RDMA/mlx5: Check CAP_NET_RAW in user namespace for anchor create
In reply to Leon RomanovskyFrom: Parav Pandit <[email protected]>
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.
--- drivers/infiniband/hw/mlx5/fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/mlx5/fs.c +1 -1
@@ -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,
Signature · 1 line
2.49.0
PATCH v2 1/9 RDMA/uverbs: Check CAP_NET_RAW in user namespace for flow create
In reply to Leon RomanovskyFrom: Parav Pandit <[email protected]>
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.
--- 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(-)
drivers/infiniband/core/device.c +27 -0
@@ -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
drivers/infiniband/core/rdma_core.c +29 -0
@@ -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);
drivers/infiniband/core/uverbs_cmd.c +1 -1
@@ -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 )
include/rdma/ib_verbs.h +3 -0
@@ -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);
Signature · 1 line
2.49.0
PATCH v2 5/9 RDMA/uverbs: Check CAP_NET_RAW in user namespace for RAW QP create
In reply to Leon RomanovskyFrom: Parav Pandit <[email protected]>
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.
--- drivers/infiniband/core/uverbs_std_types_qp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/core/uverbs_std_types_qp.c +1 -1
@@ -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 :
Signature · 1 line
2.49.0
PATCH v2 6/9 RDMA/uverbs: Check CAP_NET_RAW in user namespace for RAW QP create
In reply to Leon RomanovskyFrom: Parav Pandit <[email protected]>
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.
--- drivers/infiniband/core/uverbs_cmd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/infiniband/core/uverbs_cmd.c +1 -2
@@ -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 :
Signature · 1 line
2.49.0
PATCH v2 7/9 RDMA/mlx5: Check CAP_NET_RAW in user namespace for devx create
In reply to Leon RomanovskyFrom: Parav Pandit <[email protected]>
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.
--- drivers/infiniband/hw/mlx5/devx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/mlx5/devx.c +1 -1
@@ -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) &
Signature · 1 line
2.49.0
PATCH v2 4/9 RDMA/uverbs: Check CAP_NET_RAW in user namespace for QP create
In reply to Leon RomanovskyFrom: Parav Pandit <[email protected]>
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.
--- drivers/infiniband/core/uverbs_cmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/core/uverbs_cmd.c +1 -1
@@ -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; }
Signature · 1 line
2.49.0
PATCH v2 9/9 RDMA/counter: Check CAP_NET_RAW check in user namespace for RDMA counters
In reply to Leon RomanovskyFrom: Parav Pandit <[email protected]>
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.
--- drivers/infiniband/core/counters.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/core/counters.c +1 -1
@@ -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;
Signature · 1 line
2.49.0
PATCH v2 8/9 RDMA/nldev: Check CAP_NET_RAW in user namespace for QP modify
In reply to Leon RomanovskyFrom: Parav Pandit <[email protected]>
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.
--- drivers/infiniband/core/nldev.c | 2 +- drivers/infiniband/core/uverbs_cmd.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
drivers/infiniband/core/nldev.c +1 -1
@@ -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);
drivers/infiniband/core/uverbs_cmd.c +2 -1
@@ -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; }
Signature · 1 line
2.49.0
Leon Romanovsky
AppliedQuoted 10 lines · Leon Romanovsky
Changelog:
v2:
* Resend right series
* Split "RDMA/uverbs: CheckCAP_NET_RAWin user namespace for QP create"
* to three small patches. Maybe I should squash them when I'll apply.
v1: https://lore.kernel.org/all/[email protected]
* Moved QP checks to be earlier.
v0: https://lore.kernel.org/all/[email protected][...]
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,
Signature · 1 line
Leon Romanovsky <[email protected]>