RDMA/core: Avoid that ib_drain_qp() triggers an out-of-bounds stack access
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/3 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
==================================================================--- drivers/infiniband/core/verbs.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/infiniband/core/verbs.c +8 -3
@@ -2194,7 +2194,13 @@ static void __ib_drain_sq(struct ib_qp *qp)struct ib_cq *cq = qp->send_cq;struct ib_qp_attr attr = { .qp_state =IB_QPS_ERR };struct ib_drain_cqe sdrain; -struct ib_send_wr swr = {}, *bad_swr; +struct ib_send_wr *bad_swr; +struct ib_rdma_wr swr = { + .wr = { + .opcode =IB_WR_RDMA_WRITE , + .wr_cqe = &sdrain.cqe, + }, + };int ret; ret =ib_modify_qp (qp, &attr,IB_QP_STATE );
@@ -2203,11 +2209,10 @@ static void __ib_drain_sq(struct ib_qp *qp)return ; } - swr.wr_cqe = &sdrain.cqe; sdrain.cqe.done = ib_drain_qp_done;init_completion (&sdrain.done); - ret =ib_post_send (qp, &swr, &bad_swr); + ret =ib_post_send (qp, &swr.wr, &bad_swr);if (ret) {WARN_ONCE (ret,"failed to drain send queue: %d\n" , ret);return ;
Signature · 1 line
2.16.2
Quoted 54 lines · Bart Van Assche
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 765d67748bcf ("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]>drivers/infiniband/core/verbs.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)drivers/infiniband/core/verbs.c +1
-0+++ b/drivers/infiniband/core/verbs.c@@ -2194,7 +2194,13 @@ static void __ib_drain_sq(struct ib_qp *qp)struct ib_cq *cq = qp->send_cq;
drivers/infiniband/core/verbs.c static void __ib_drain_sq(struct ib_qp *qp) · line 2203
Quoted 10 lines
drivers/infiniband/core/verbs.c +7
-1struct ib_qp_attr attr = { .qp_state =IB_QPS_ERR };struct ib_drain_cqe sdrain; -struct ib_send_wr swr = {}, *bad_swr; +struct ib_send_wr *bad_swr; +struct ib_rdma_wr swr = { + .wr = { + .opcode =IB_WR_RDMA_WRITE , + .wr_cqe = &sdrain.cqe, + }, + };
I don't get it..
Since when did ib_post_send() start requiring a ib_rdma_wr?
IB_WR_RDMA_WRITE == 0, so even missing that is 'OK' but ugly.
What is the actual bug here?
Jason
Quoted 53 lines
=
Quoted 5 lines
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
Quoted 18 lines
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:Quoted 1 line
page:ffffea000186bbc0 count:0 mapcount:0 mapping:0000000000000000
index:0x0
Quoted 2 lines
flags: 0x4000000000000000()
raw: 4000000000000000 0000000000000000 0000000000000000
00000000ffffffffQuoted 1 line
raw: 0000000000000000 ffffea000186bbe0 00000000000000000000000000000000
Quoted 10 lines
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=================================================================
=Quoted 9 lines
Fixes 765d67748bcf ("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]>drivers/infiniband/core/verbs.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
Quoted 1 line
Review
Quoted 1 line
(quoted diff) +0
-0
b/drivers/infiniband/core/verbs.c
Quoted 17 lines
Quoted 4 lines
index
2c7b0ceb46e6..4e2b231b03f7100644
+++b/drivers/infiniband/core/verbs.cdrivers/infiniband/core/verbs.c +0
-0@@ -2194,7 +2194,13 @@ static void __ib_drain_sq(struct ib_qp *qp)struct ib_cq *cq = qp->send_cq;drivers/infiniband/core/verbs.c static void __ib_drain_sq(struct ib_qp *qp) · line 2203
Quoted 10 lines
drivers/infiniband/core/verbs.c +7
-1struct ib_qp_attr attr = { .qp_state =IB_QPS_ERR };struct ib_drain_cqe sdrain; -struct ib_send_wr swr = {}, *bad_swr; +struct ib_send_wr *bad_swr; +struct ib_rdma_wr swr = { + .wr = { + .opcode =IB_WR_RDMA_WRITE , + .wr_cqe = &sdrain.cqe, + }, + };I don't get it..
Quoted 6 lines
Since when did
ib_post_send()start requiring aib_rdma_wr?
IB_WR_RDMA_WRITE== 0, so even missing that is 'OK' but ugly.What is the actual bug here?
The WRs are now split up, so struct ib_send_wr doesn't encompass the full size of all the possible WRs. See ib_rdma_wr, for example, which includes ib_send_wr. So the bug is the drain code is posting a WRITE wr, but not including the entire struct ib_rdma_wr.
Steve
Quoted 6 lines · Steve Wise
Quoted 6 lines
I don't get it..
Since when did
ib_post_send()start requiring aib_rdma_wr?
IB_WR_RDMA_WRITE== 0, so even missing that is 'OK' but ugly.
Quoted 7 lines
Quoted 2 lines
What is the actual bug here?
The WRs are now split up, so struct
ib_send_wrdoesn't encompass the full size of all the possible WRs. Seeib_rdma_wr, for example, which includesib_send_wr. So the bug is the drain code is posting a WRITE wr, but not including the entire structib_rdma_wr.
Oh.. yes, I forgot about that patch. Thanks, OK.
Jason
PATCH 2/3 RDMA/rxe: Fix an out-of-bounds read
In reply to a message not in the archiveThis patch avoids that KASAN reports the following when the SRP initiator calls srp_post_send():
==================================================================
BUG: KASAN: stack-out-of-bounds in rxe_post_send+0x5c4/0x980 [rdma_rxe]
Read of size 8 at addr ffff880066606e30 by task 02-mq/1074
CPU: 2 PID: 1074 Comm: 02-mq Not tainted 4.16.0-rc3-dbg+ #1
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+0x5c4/0x980 [rdma_rxe]
srp_post_send.isra.16+0x149/0x190 [ib_srp]
srp_queuecommand+0x94d/0x1670 [ib_srp]
scsi_dispatch_cmd+0x1c2/0x550 [scsi_mod]
scsi_queue_rq+0x843/0xa70 [scsi_mod]
blk_mq_dispatch_rq_list+0x143/0xac0
blk_mq_do_dispatch_ctx+0x1c5/0x260
blk_mq_sched_dispatch_requests+0x2bf/0x2f0
__blk_mq_run_hw_queue+0xdb/0x160
__blk_mq_delay_run_hw_queue+0xba/0x100
blk_mq_run_hw_queue+0xf2/0x190
blk_mq_sched_insert_request+0x163/0x2f0
blk_execute_rq+0xb0/0x130
scsi_execute+0x14e/0x260 [scsi_mod]
scsi_probe_and_add_lun+0x366/0x13d0 [scsi_mod]
__scsi_scan_target+0x18a/0x810 [scsi_mod]
scsi_scan_target+0x11e/0x130 [scsi_mod]
srp_create_target+0x1522/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:ffffea0001998180 count:0 mapcount:0 mapping:0000000000000000 index:0x0
flags: 0x4000000000000000()
raw: 4000000000000000 0000000000000000 0000000000000000 00000000ffffffff
raw: dead000000000100 dead000000000200 0000000000000000 0000000000000000
page dumped because: kasan: bad access detected
Memory state around the buggy address:
ffff880066606d00: 00 00 00 00 00 00 00 00 00 00 00 00 00 f1 f1 f1
ffff880066606d80: f1 00 f2 f2 f2 f2 f2 f2 f2 00 00 f2 f2 f2 f2 f2
>ffff880066606e00: f2 00 00 00 00 00 f2 f2 f2 f3 f3 f3 f3 00 00 00
^
ffff880066606e80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ffff880066606f00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
==================================================================--- drivers/infiniband/sw/rxe/rxe_verbs.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/infiniband/sw/rxe/rxe_verbs.c +2 -3
@@ -711,9 +711,8 @@ static int init_send_wqe(struct rxe_qp *qp, const struct ib_send_wr *ibwr,memcpy (wqe->dma.sge, ibwr->sg_list, num_sge *sizeof (struct ib_sge )); - wqe->iova = (mask &WR_ATOMIC_MASK ) ? -atomic_wr (ibwr)->remote_addr : -rdma_wr (ibwr)->remote_addr; + wqe->iova = mask &WR_ATOMIC_MASK ?atomic_wr (ibwr)->remote_addr : + mask &WR_READ_OR_WRITE_MASK ?rdma_wr (ibwr)->remote_addr :0 ; wqe->mask = mask; wqe->dma.length = length; wqe->dma.resid = length;
Signature · 1 line
2.16.2
PATCH 3/3 IB/srpt: Fix an out-of-bounds stack access in srpt_zerolength_write()
In reply to a message not in the archiveAvoid triggering an out-of-bounds stack access by changing the type of 'wr' from ib_send_wr into ib_rdma_wr.
This patch fixes the following KASAN bug report:
BUG: KASAN: stack-out-of-bounds in rxe_post_send+0x7a9/0x9a0 [rdma_rxe] Read of size 8 at addr ffff880068197a48 by task kworker/2:1/44 Workqueue: ib_cm cm_work_handler [ib_cm] Call Trace: dump_stack+0x8e/0xcd print_address_description+0x6f/0x280 kasan_report+0x25a/0x380 __asan_load8+0x54/0x90 rxe_post_send+0x7a9/0x9a0 [rdma_rxe] srpt_zerolength_write+0xf0/0x180 [ib_srpt] srpt_cm_rtu_recv+0x68/0x110 [ib_srpt] srpt_rdma_cm_handler+0xbb/0x15b [ib_srpt] cma_ib_handler+0x1aa/0x4a0 [rdma_cm] cm_process_work+0x30/0x100 [ib_cm] cm_work_handler+0xa86/0x351b [ib_cm] process_one_work+0x475/0x9f0 worker_thread+0x69/0x690 kthread+0x1ad/0x1d0 ret_from_fork+0x3a/0x50
--- drivers/infiniband/ulp/srpt/ib_srpt.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/infiniband/ulp/srpt/ib_srpt.c +9 -6
@@ -848,16 +848,19 @@ static int srpt_post_recv(struct srpt_device *sdev, struct srpt_rdma_ch *ch,*/ static int srpt_zerolength_write (struct srpt_rdma_ch *ch) { -struct ib_send_wr wr, *bad_wr; +struct ib_send_wr *bad_wr; +struct ib_rdma_wr wr = { + .wr = { + .opcode =IB_WR_RDMA_WRITE , + .wr_cqe = &ch->zw_cqe, + .send_flags =IB_SEND_SIGNALED , + } + };pr_debug ("%s-%d: queued zerolength write\n" , ch->sess_name, ch->qp->qp_num); -memset (&wr,0 ,sizeof (wr)); - wr.opcode =IB_WR_RDMA_WRITE ; - wr.wr_cqe = &ch->zw_cqe; - wr.send_flags =IB_SEND_SIGNALED ; -return ib_post_send (ch->qp, &wr, &bad_wr); +return ib_post_send (ch->qp, &wr.wr, &bad_wr); }static void srpt_zerolength_write_done (struct ib_cq *cq,struct ib_wc *wc)
Signature · 1 line
2.16.2