RDMA/restrack: Remove PID namespace support
authorLeon Romanovsky <leonro@mellanox.com>
Thu, 10 Oct 2019 07:11:04 +0000 (10:11 +0300)
committerJason Gunthorpe <jgg@mellanox.com>
Wed, 23 Oct 2019 18:58:31 +0000 (15:58 -0300)
IB resources are bounded to IB device and file descriptors, both entities
are unaware to PID namespaces and to task lifetime.

The difference in model caused to unpredictable behavior for the following
scenario:
 1. Create FD and context
 2. Share it with ephemeral child
 3. Create any object and exit that child

The end result of this flow, that those newly created objects will be
tracked by restrack, but won't be visible for users because task_struct
associated with them already exited.

The right thing is to rely on net namespace only for any filtering
purposes and drop PID namespace.

Link: https://lore.kernel.org/r/20191010071105.25538-2-leon@kernel.org
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Reviewed-by: Jason Gunthorpe <jgg@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
drivers/infiniband/core/counters.c
drivers/infiniband/core/nldev.c
drivers/infiniband/core/restrack.c
drivers/infiniband/core/restrack.h

index 736ab760025d4e62a591924129fb50b7195e2040..12ba2685abcf83f4015423b0f50e24a857242233 100644 (file)
@@ -149,9 +149,6 @@ static bool auto_mode_match(struct ib_qp *qp, struct rdma_counter *counter,
        struct auto_mode_param *param = &counter->mode.param;
        bool match = true;
 
-       if (!rdma_is_visible_in_pid_ns(&qp->res))
-               return false;
-
        /* Ensure that counter belongs to the right PID */
        if (task_pid_nr(counter->res.task) != task_pid_nr(qp->res.task))
                return false;
@@ -229,9 +226,6 @@ static struct rdma_counter *rdma_get_counter_auto_mode(struct ib_qp *qp,
        rt = &dev->res[RDMA_RESTRACK_COUNTER];
        xa_lock(&rt->xa);
        xa_for_each(&rt->xa, id, res) {
-               if (!rdma_is_visible_in_pid_ns(res))
-                       continue;
-
                counter = container_of(res, struct rdma_counter, res);
                if ((counter->device != qp->device) || (counter->port != port))
                        goto next;
@@ -412,9 +406,6 @@ static struct ib_qp *rdma_counter_get_qp(struct ib_device *dev, u32 qp_num)
        if (IS_ERR(res))
                return NULL;
 
-       if (!rdma_is_visible_in_pid_ns(res))
-               goto err;
-
        qp = container_of(res, struct ib_qp, res);
        if (qp->qp_type == IB_QPT_RAW_PACKET && !capable(CAP_NET_RAW))
                goto err;
@@ -445,11 +436,6 @@ static struct rdma_counter *rdma_get_counter_by_id(struct ib_device *dev,
        if (IS_ERR(res))
                return NULL;
 
-       if (!rdma_is_visible_in_pid_ns(res)) {
-               rdma_restrack_put(res);
-               return NULL;
-       }
-
        counter = container_of(res, struct rdma_counter, res);
        kref_get(&counter->kref);
        rdma_restrack_put(res);
index 3bb208557c45abacf0ae485ef216809f4d1799c5..2f052c23c8c70e8207fc9d6fada1b5b163ff3940 100644 (file)
@@ -722,9 +722,6 @@ static int fill_stat_counter_qps(struct sk_buff *msg,
        rt = &counter->device->res[RDMA_RESTRACK_QP];
        xa_lock(&rt->xa);
        xa_for_each(&rt->xa, id, res) {
-               if (!rdma_is_visible_in_pid_ns(res))
-                       continue;
-
                qp = container_of(res, struct ib_qp, res);
                if (qp->qp_type == IB_QPT_RAW_PACKET && !capable(CAP_NET_RAW))
                        continue;
@@ -1258,15 +1255,10 @@ static int res_get_common_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
                goto err;
        }
 
-       if (!rdma_is_visible_in_pid_ns(res)) {
-               ret = -ENOENT;
-               goto err_get;
-       }
-
        msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
        if (!msg) {
                ret = -ENOMEM;
-               goto err;
+               goto err_get;
        }
 
        nlh = nlmsg_put(msg, NETLINK_CB(skb).portid, nlh->nlmsg_seq,
@@ -1373,9 +1365,6 @@ static int res_get_common_dumpit(struct sk_buff *skb,
         * objects.
         */
        xa_for_each(&rt->xa, id, res) {
-               if (!rdma_is_visible_in_pid_ns(res))
-                       continue;
-
                if (idx < start || !rdma_restrack_get(res))
                        goto next;
 
index a07665f7ef8ceffa81d9dd1ede9b4c71e4c977b7..62fbb0ae9cb4a66a24c921f27cbf98460e95a199 100644 (file)
@@ -116,11 +116,8 @@ int rdma_restrack_count(struct ib_device *dev, enum rdma_restrack_type type)
        u32 cnt = 0;
 
        xa_lock(&rt->xa);
-       xas_for_each(&xas, e, U32_MAX) {
-               if (!rdma_is_visible_in_pid_ns(e))
-                       continue;
+       xas_for_each(&xas, e, U32_MAX)
                cnt++;
-       }
        xa_unlock(&rt->xa);
        return cnt;
 }
@@ -346,18 +343,3 @@ out:
        }
 }
 EXPORT_SYMBOL(rdma_restrack_del);
-
-bool rdma_is_visible_in_pid_ns(struct rdma_restrack_entry *res)
-{
-       /*
-        * 1. Kern resources should be visible in init
-        *    namespace only
-        * 2. Present only resources visible in the current
-        *     namespace
-        */
-       if (rdma_is_kernel_res(res))
-               return task_active_pid_ns(current) == &init_pid_ns;
-
-       /* PID 0 means that resource is not found in current namespace */
-       return task_pid_vnr(res->task);
-}
index 7bd177cc0a6179c635532ed7f718ab432d07a069..d084e5f8984911460399af83df0a2447171c42b2 100644 (file)
@@ -27,5 +27,4 @@ int rdma_restrack_init(struct ib_device *dev);
 void rdma_restrack_clean(struct ib_device *dev);
 void rdma_restrack_attach_task(struct rdma_restrack_entry *res,
                               struct task_struct *task);
-bool rdma_is_visible_in_pid_ns(struct rdma_restrack_entry *res);
 #endif /* _RDMA_CORE_RESTRACK_H_ */