Skip to content

Commit a1ae7d0

Browse files
KAGA-KOKOjgunthorpe
authored andcommitted
RDMA/core: Avoid that ib_drain_qp() triggers an out-of-bounds stack access
This patch fixes the following KASAN complaint: ================================================================== BUG: KASAN: stack-out-of-bounds in rxe_post_send+0x77d/0x9b0 [rdma_rxe] Read of size 8 at addr ffff880061aef860 by task 01/1080 CPU: 2 PID: 1080 Comm: 01 Not tainted 4.16.0-rc3-dbg+ #2 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.0.0-prebuilt.qemu-project.org 04/01/2014 Call Trace: dump_stack+0x85/0xc7 print_address_description+0x65/0x270 kasan_report+0x231/0x350 rxe_post_send+0x77d/0x9b0 [rdma_rxe] __ib_drain_sq+0x1ad/0x250 [ib_core] ib_drain_qp+0x9/0x30 [ib_core] srp_destroy_qp+0x51/0x70 [ib_srp] srp_free_ch_ib+0xfc/0x380 [ib_srp] srp_create_target+0x1071/0x19e0 [ib_srp] kernfs_fop_write+0x180/0x210 __vfs_write+0xb1/0x2e0 vfs_write+0xf6/0x250 SyS_write+0x99/0x110 do_syscall_64+0xee/0x2b0 entry_SYSCALL_64_after_hwframe+0x42/0xb7 The buggy address belongs to the page: page:ffffea000186bbc0 count:0 mapcount:0 mapping:0000000000000000 index:0x0 flags: 0x4000000000000000() raw: 4000000000000000 0000000000000000 0000000000000000 00000000ffffffff raw: 0000000000000000 ffffea000186bbe0 0000000000000000 0000000000000000 page dumped because: kasan: bad access detected Memory state around the buggy address: ffff880061aef700: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ffff880061aef780: 00 00 00 00 00 00 00 00 00 00 00 f1 f1 f1 f1 00 >ffff880061aef800: f2 f2 f2 f2 f2 f2 f2 00 00 00 00 00 f2 f2 f2 f2 ^ ffff880061aef880: f2 f2 f2 00 00 00 00 00 00 00 00 00 00 00 f2 f2 ffff880061aef900: f2 f2 f2 00 00 00 00 00 00 00 00 00 00 00 00 00 ================================================================== Fixes: 765d677 ("IB: new common API for draining queues") Signed-off-by: Bart Van Assche <[email protected]> Cc: Steve Wise <[email protected]> Cc: Sagi Grimberg <[email protected]> Cc: [email protected] Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 042932f commit a1ae7d0

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

drivers/infiniband/core/verbs.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2194,7 +2194,13 @@ static void __ib_drain_sq(struct ib_qp *qp)
21942194
struct ib_cq *cq = qp->send_cq;
21952195
struct ib_qp_attr attr = { .qp_state = IB_QPS_ERR };
21962196
struct ib_drain_cqe sdrain;
2197-
struct ib_send_wr swr = {}, *bad_swr;
2197+
struct ib_send_wr *bad_swr;
2198+
struct ib_rdma_wr swr = {
2199+
.wr = {
2200+
.opcode = IB_WR_RDMA_WRITE,
2201+
.wr_cqe = &sdrain.cqe,
2202+
},
2203+
};
21982204
int ret;
21992205

22002206
ret = ib_modify_qp(qp, &attr, IB_QP_STATE);
@@ -2203,11 +2209,10 @@ static void __ib_drain_sq(struct ib_qp *qp)
22032209
return;
22042210
}
22052211

2206-
swr.wr_cqe = &sdrain.cqe;
22072212
sdrain.cqe.done = ib_drain_qp_done;
22082213
init_completion(&sdrain.done);
22092214

2210-
ret = ib_post_send(qp, &swr, &bad_swr);
2215+
ret = ib_post_send(qp, &swr.wr, &bad_swr);
22112216
if (ret) {
22122217
WARN_ONCE(ret, "failed to drain send queue: %d\n", ret);
22132218
return;

0 commit comments

Comments
 (0)