Commit 60c78668 authored by Leon Romanovsky's avatar Leon Romanovsky Committed by Doug Ledford

RDMA/restrack: Rewrite PID namespace check to be reliable

task_active_pid_ns() is wrong API to check PID namespace because it
posses some restrictions and return PID namespace where the process
was allocated. It created mismatches with current namespace, which
can be different.

Rewrite whole rdma_is_visible_in_pid_ns() logic to provide reliable
results without any relation to allocated PID namespace.

Fixes: 8be565e6 ("RDMA/nldev: Factor out the PID namespace check")
Fixes: 6a6c306a ("RDMA/restrack: Make is_visible_in_pid_ns() as an API")
Reviewed-by: default avatarMark Zhang <markz@mellanox.com>
Signed-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Link: https://lore.kernel.org/r/20190815083834.9245-4-leon@kernel.orgSigned-off-by: default avatarDoug Ledford <dledford@redhat.com>
parent c8b32408
...@@ -382,8 +382,7 @@ static int fill_res_info(struct sk_buff *msg, struct ib_device *device) ...@@ -382,8 +382,7 @@ static int fill_res_info(struct sk_buff *msg, struct ib_device *device)
for (i = 0; i < RDMA_RESTRACK_MAX; i++) { for (i = 0; i < RDMA_RESTRACK_MAX; i++) {
if (!names[i]) if (!names[i])
continue; continue;
curr = rdma_restrack_count(device, i, curr = rdma_restrack_count(device, i);
task_active_pid_ns(current));
ret = fill_res_info_entry(msg, names[i], curr); ret = fill_res_info_entry(msg, names[i], curr);
if (ret) if (ret)
goto err; goto err;
......
...@@ -107,10 +107,8 @@ void rdma_restrack_clean(struct ib_device *dev) ...@@ -107,10 +107,8 @@ void rdma_restrack_clean(struct ib_device *dev)
* rdma_restrack_count() - the current usage of specific object * rdma_restrack_count() - the current usage of specific object
* @dev: IB device * @dev: IB device
* @type: actual type of object to operate * @type: actual type of object to operate
* @ns: PID namespace
*/ */
int rdma_restrack_count(struct ib_device *dev, enum rdma_restrack_type type, int rdma_restrack_count(struct ib_device *dev, enum rdma_restrack_type type)
struct pid_namespace *ns)
{ {
struct rdma_restrack_root *rt = &dev->res[type]; struct rdma_restrack_root *rt = &dev->res[type];
struct rdma_restrack_entry *e; struct rdma_restrack_entry *e;
...@@ -119,9 +117,8 @@ int rdma_restrack_count(struct ib_device *dev, enum rdma_restrack_type type, ...@@ -119,9 +117,8 @@ int rdma_restrack_count(struct ib_device *dev, enum rdma_restrack_type type,
xa_lock(&rt->xa); xa_lock(&rt->xa);
xas_for_each(&xas, e, U32_MAX) { xas_for_each(&xas, e, U32_MAX) {
if (ns == &init_pid_ns || if (!rdma_is_visible_in_pid_ns(e))
(!rdma_is_kernel_res(e) && continue;
ns == task_active_pid_ns(e->task)))
cnt++; cnt++;
} }
xa_unlock(&rt->xa); xa_unlock(&rt->xa);
...@@ -360,5 +357,7 @@ bool rdma_is_visible_in_pid_ns(struct rdma_restrack_entry *res) ...@@ -360,5 +357,7 @@ bool rdma_is_visible_in_pid_ns(struct rdma_restrack_entry *res)
*/ */
if (rdma_is_kernel_res(res)) if (rdma_is_kernel_res(res))
return task_active_pid_ns(current) == &init_pid_ns; return task_active_pid_ns(current) == &init_pid_ns;
return task_active_pid_ns(current) == task_active_pid_ns(res->task);
/* PID 0 means that resource is not found in current namespace */
return task_pid_vnr(res->task);
} }
...@@ -105,8 +105,7 @@ struct rdma_restrack_entry { ...@@ -105,8 +105,7 @@ struct rdma_restrack_entry {
}; };
int rdma_restrack_count(struct ib_device *dev, int rdma_restrack_count(struct ib_device *dev,
enum rdma_restrack_type type, enum rdma_restrack_type type);
struct pid_namespace *ns);
void rdma_restrack_kadd(struct rdma_restrack_entry *res); void rdma_restrack_kadd(struct rdma_restrack_entry *res);
void rdma_restrack_uadd(struct rdma_restrack_entry *res); void rdma_restrack_uadd(struct rdma_restrack_entry *res);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment