Skip to content

Commit 7350cdd

Browse files
bharatpotnurijgunthorpe
authored andcommitted
RDMA/core: Save kernel caller name when creating CQ using ib_create_cq()
Few kernel applications like SCST-iSER create CQ using ib_create_cq(), where accessing CQ structures using rdma restrack tool leads to below NULL pointer dereference. This patch saves caller kernel module name similar to ib_alloc_cq(). BUG: unable to handle kernel NULL pointer dereference at (null) IP: [<ffffffff8132ca70>] skip_spaces+0x30/0x30 PGD 738bac067 PUD 8533f0067 PMD 0 Oops: 0000 [#1] SMP R10: ffff88017fc03300 R11: 0000000000000246 R12: 0000000000000000 R13: ffff88082fa5a668 R14: ffff88017475a000 R15: 0000000000000000 FS: 00002b32726582c0(0000) GS:ffff88087fc40000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000000 CR3: 00000008491a1000 CR4: 00000000003607e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: [<ffffffffc05af69c>] ? fill_res_name_pid+0x7c/0x90 [ib_core] [<ffffffffc05af79f>] fill_res_cq_entry+0xef/0x170 [ib_core] [<ffffffffc05af4c4>] res_get_common_dumpit+0x3c4/0x480 [ib_core] [<ffffffffc05af5d3>] nldev_res_get_cq_dumpit+0x13/0x20 [ib_core] [<ffffffff815bc1e7>] netlink_dump+0x117/0x2e0 [<ffffffff815bcb8b>] __netlink_dump_start+0x1ab/0x230 [<ffffffffc059fead>] ibnl_rcv_msg+0x11d/0x1f0 [ib_core] [<ffffffffc05af5c0>] ? nldev_res_get_mr_dumpit+0x20/0x20 [ib_core] [<ffffffffc059fd90>] ? rdma_nl_multicast+0x30/0x30 [ib_core] [<ffffffff815bea49>] netlink_rcv_skb+0xa9/0xc0 [<ffffffffc05a0018>] ibnl_rcv+0x98/0xb0 [ib_core] [<ffffffff815be132>] netlink_unicast+0xf2/0x1b0 [<ffffffff815be50f>] netlink_sendmsg+0x31f/0x6a0 [<ffffffff8156b580>] sock_sendmsg+0xb0/0xf0 [<ffffffff816ace9e>] ? _raw_spin_unlock_bh+0x1e/0x20 [<ffffffff8156f998>] ? release_sock+0x118/0x170 [<ffffffff8156b731>] SYSC_sendto+0x121/0x1c0 [<ffffffff81568340>] ? sock_alloc_file+0xa0/0x140 [<ffffffff81221265>] ? __fd_install+0x25/0x60 [<ffffffff8156c2ce>] SyS_sendto+0xe/0x10 [<ffffffff816b6c2a>] system_call_fastpath+0x16/0x1b RIP [<ffffffff8132ca70>] skip_spaces+0x30/0x30 RSP <ffff88072be97760> CR2: 0000000000000000 Cc: <[email protected]> Fixes: f66c8ba ("RDMA/core: Save kernel caller name when creating PD and CQ objects") Reviewed-by: Steve Wise <[email protected]> Signed-off-by: Potnuri Bharat Teja <[email protected]> Reviewed-by: Leon Romanovsky <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 1eb9364 commit 7350cdd

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

drivers/infiniband/core/verbs.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,11 +1562,12 @@ EXPORT_SYMBOL(ib_destroy_qp);
15621562

15631563
/* Completion queues */
15641564

1565-
struct ib_cq *ib_create_cq(struct ib_device *device,
1566-
ib_comp_handler comp_handler,
1567-
void (*event_handler)(struct ib_event *, void *),
1568-
void *cq_context,
1569-
const struct ib_cq_init_attr *cq_attr)
1565+
struct ib_cq *__ib_create_cq(struct ib_device *device,
1566+
ib_comp_handler comp_handler,
1567+
void (*event_handler)(struct ib_event *, void *),
1568+
void *cq_context,
1569+
const struct ib_cq_init_attr *cq_attr,
1570+
const char *caller)
15701571
{
15711572
struct ib_cq *cq;
15721573

@@ -1580,12 +1581,13 @@ struct ib_cq *ib_create_cq(struct ib_device *device,
15801581
cq->cq_context = cq_context;
15811582
atomic_set(&cq->usecnt, 0);
15821583
cq->res.type = RDMA_RESTRACK_CQ;
1584+
cq->res.kern_name = caller;
15831585
rdma_restrack_add(&cq->res);
15841586
}
15851587

15861588
return cq;
15871589
}
1588-
EXPORT_SYMBOL(ib_create_cq);
1590+
EXPORT_SYMBOL(__ib_create_cq);
15891591

15901592
int rdma_set_cq_moderation(struct ib_cq *cq, u16 cq_count, u16 cq_period)
15911593
{

include/rdma/ib_verbs.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3394,11 +3394,14 @@ int ib_process_cq_direct(struct ib_cq *cq, int budget);
33943394
*
33953395
* Users can examine the cq structure to determine the actual CQ size.
33963396
*/
3397-
struct ib_cq *ib_create_cq(struct ib_device *device,
3398-
ib_comp_handler comp_handler,
3399-
void (*event_handler)(struct ib_event *, void *),
3400-
void *cq_context,
3401-
const struct ib_cq_init_attr *cq_attr);
3397+
struct ib_cq *__ib_create_cq(struct ib_device *device,
3398+
ib_comp_handler comp_handler,
3399+
void (*event_handler)(struct ib_event *, void *),
3400+
void *cq_context,
3401+
const struct ib_cq_init_attr *cq_attr,
3402+
const char *caller);
3403+
#define ib_create_cq(device, cmp_hndlr, evt_hndlr, cq_ctxt, cq_attr) \
3404+
__ib_create_cq((device), (cmp_hndlr), (evt_hndlr), (cq_ctxt), (cq_attr), KBUILD_MODNAME)
34023405

34033406
/**
34043407
* ib_resize_cq - Modifies the capacity of the CQ.

0 commit comments

Comments
 (0)