Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

RDMA/restrack: Fix potential invalid address access

struct rdma_restrack_entry's kern_name was set to KBUILD_MODNAME
in ib_create_cq(), while if the module exited but forgot del this
rdma_restrack_entry, it would cause a invalid address access in
rdma_restrack_clean() when print the owner of this rdma_restrack_entry.

These code is used to help find one forgotten PD release in one of the
ULPs. But it is not needed anymore, so delete them.

Signed-off-by: Wenchao Hao <haowenchao2@huawei.com>
Link: https://lore.kernel.org/r/20240318092320.1215235-1-haowenchao2@huawei.com
Signed-off-by: Leon Romanovsky <leon@kernel.org>

authored by

Wenchao Hao and committed by
Leon Romanovsky
ca537a34 df0e16ba

+1 -50
+1 -50
drivers/infiniband/core/restrack.c
··· 37 37 return 0; 38 38 } 39 39 40 - static const char *type2str(enum rdma_restrack_type type) 41 - { 42 - static const char * const names[RDMA_RESTRACK_MAX] = { 43 - [RDMA_RESTRACK_PD] = "PD", 44 - [RDMA_RESTRACK_CQ] = "CQ", 45 - [RDMA_RESTRACK_QP] = "QP", 46 - [RDMA_RESTRACK_CM_ID] = "CM_ID", 47 - [RDMA_RESTRACK_MR] = "MR", 48 - [RDMA_RESTRACK_CTX] = "CTX", 49 - [RDMA_RESTRACK_COUNTER] = "COUNTER", 50 - [RDMA_RESTRACK_SRQ] = "SRQ", 51 - }; 52 - 53 - return names[type]; 54 - }; 55 - 56 40 /** 57 41 * rdma_restrack_clean() - clean resource tracking 58 42 * @dev: IB device ··· 44 60 void rdma_restrack_clean(struct ib_device *dev) 45 61 { 46 62 struct rdma_restrack_root *rt = dev->res; 47 - struct rdma_restrack_entry *e; 48 - char buf[TASK_COMM_LEN]; 49 - bool found = false; 50 - const char *owner; 51 63 int i; 52 64 53 65 for (i = 0 ; i < RDMA_RESTRACK_MAX; i++) { 54 66 struct xarray *xa = &dev->res[i].xa; 55 67 56 - if (!xa_empty(xa)) { 57 - unsigned long index; 58 - 59 - if (!found) { 60 - pr_err("restrack: %s", CUT_HERE); 61 - dev_err(&dev->dev, "BUG: RESTRACK detected leak of resources\n"); 62 - } 63 - xa_for_each(xa, index, e) { 64 - if (rdma_is_kernel_res(e)) { 65 - owner = e->kern_name; 66 - } else { 67 - /* 68 - * There is no need to call get_task_struct here, 69 - * because we can be here only if there are more 70 - * get_task_struct() call than put_task_struct(). 71 - */ 72 - get_task_comm(buf, e->task); 73 - owner = buf; 74 - } 75 - 76 - pr_err("restrack: %s %s object allocated by %s is not freed\n", 77 - rdma_is_kernel_res(e) ? "Kernel" : 78 - "User", 79 - type2str(e->type), owner); 80 - } 81 - found = true; 82 - } 68 + WARN_ON(!xa_empty(xa)); 83 69 xa_destroy(xa); 84 70 } 85 - if (found) 86 - pr_err("restrack: %s", CUT_HERE); 87 - 88 71 kfree(rt); 89 72 } 90 73