Skip to content

Commit 60c7866

Browse files
Leon Romanovskydledford
authored andcommitted
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: 8be565e ("RDMA/nldev: Factor out the PID namespace check") Fixes: 6a6c306 ("RDMA/restrack: Make is_visible_in_pid_ns() as an API") Reviewed-by: Mark Zhang <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Doug Ledford <[email protected]>
1 parent c8b3240 commit 60c7866

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

drivers/infiniband/core/nldev.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,7 @@ static int fill_res_info(struct sk_buff *msg, struct ib_device *device)
382382
for (i = 0; i < RDMA_RESTRACK_MAX; i++) {
383383
if (!names[i])
384384
continue;
385-
curr = rdma_restrack_count(device, i,
386-
task_active_pid_ns(current));
385+
curr = rdma_restrack_count(device, i);
387386
ret = fill_res_info_entry(msg, names[i], curr);
388387
if (ret)
389388
goto err;

drivers/infiniband/core/restrack.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,8 @@ void rdma_restrack_clean(struct ib_device *dev)
107107
* rdma_restrack_count() - the current usage of specific object
108108
* @dev: IB device
109109
* @type: actual type of object to operate
110-
* @ns: PID namespace
111110
*/
112-
int rdma_restrack_count(struct ib_device *dev, enum rdma_restrack_type type,
113-
struct pid_namespace *ns)
111+
int rdma_restrack_count(struct ib_device *dev, enum rdma_restrack_type type)
114112
{
115113
struct rdma_restrack_root *rt = &dev->res[type];
116114
struct rdma_restrack_entry *e;
@@ -119,10 +117,9 @@ int rdma_restrack_count(struct ib_device *dev, enum rdma_restrack_type type,
119117

120118
xa_lock(&rt->xa);
121119
xas_for_each(&xas, e, U32_MAX) {
122-
if (ns == &init_pid_ns ||
123-
(!rdma_is_kernel_res(e) &&
124-
ns == task_active_pid_ns(e->task)))
125-
cnt++;
120+
if (!rdma_is_visible_in_pid_ns(e))
121+
continue;
122+
cnt++;
126123
}
127124
xa_unlock(&rt->xa);
128125
return cnt;
@@ -360,5 +357,7 @@ bool rdma_is_visible_in_pid_ns(struct rdma_restrack_entry *res)
360357
*/
361358
if (rdma_is_kernel_res(res))
362359
return task_active_pid_ns(current) == &init_pid_ns;
363-
return task_active_pid_ns(current) == task_active_pid_ns(res->task);
360+
361+
/* PID 0 means that resource is not found in current namespace */
362+
return task_pid_vnr(res->task);
364363
}

include/rdma/restrack.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ struct rdma_restrack_entry {
105105
};
106106

107107
int rdma_restrack_count(struct ib_device *dev,
108-
enum rdma_restrack_type type,
109-
struct pid_namespace *ns);
108+
enum rdma_restrack_type type);
110109

111110
void rdma_restrack_kadd(struct rdma_restrack_entry *res);
112111
void rdma_restrack_uadd(struct rdma_restrack_entry *res);

0 commit comments

Comments
 (0)