1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
|
null-ptr dereference in megasas_command_complete
Hello,
While fuzzing, I found an input that triggers a null-pointer dereference in
megasas_command_complete:
==14959==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000003 (pc 0x55b1d11b4df1 bp 0x7ffeb55ca450 sp 0x7ffeb55ca1e0 T0)
==14959==The signal is caused by a WRITE memory access.
==14959==Hint: address points to the zero page.
#0 0x55b1d11b4df1 in megasas_command_complete /home/alxndr/Development/qemu/hw/scsi/megasas.c:1877:40
#1 0x55b1d11759ec in scsi_req_complete /home/alxndr/Development/qemu/hw/scsi/scsi-bus.c:1430:5
#2 0x55b1d115c98f in scsi_aio_complete /home/alxndr/Development/qemu/hw/scsi/scsi-disk.c:216:5
#3 0x55b1d151c638 in blk_aio_complete /home/alxndr/Development/qemu/block/block-backend.c:1375:9
#4 0x55b1d151c638 in blk_aio_complete_bh /home/alxndr/Development/qemu/block/block-backend.c:1385:5
#5 0x55b1d16f3a5b in aio_bh_call /home/alxndr/Development/qemu/util/async.c:136:5
#6 0x55b1d16f3a5b in aio_bh_poll /home/alxndr/Development/qemu/util/async.c:164:13
#7 0x55b1d16fe43e in aio_dispatch /home/alxndr/Development/qemu/util/aio-posix.c:380:5
#8 0x55b1d16f54fa in aio_ctx_dispatch /home/alxndr/Development/qemu/util/async.c:306:5
#9 0x7f47937c89ed in g_main_context_dispatch (/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x4e9ed)
#10 0x55b1d16fbef4 in glib_pollfds_poll /home/alxndr/Development/qemu/util/main-loop.c:219:9
#11 0x55b1d16fbef4 in os_host_main_loop_wait /home/alxndr/Development/qemu/util/main-loop.c:242:5
#12 0x55b1d16fbef4 in main_loop_wait /home/alxndr/Development/qemu/util/main-loop.c:518:11
#13 0x55b1d0cd16a6 in qemu_main_loop /home/alxndr/Development/qemu/softmmu/vl.c:1664:9
#14 0x55b1d1608dca in main /home/alxndr/Development/qemu/softmmu/main.c:49:5
#15 0x7f4792378e0a in __libc_start_main /build/glibc-GwnBeO/glibc-2.30/csu/../csu/libc-start.c:308:16
#16 0x55b1d091d7b9 in _start (/home/alxndr/Development/qemu/build/i386-softmmu/qemu-system-i386+0x8f47b9)
I can reproduce it in qemu 5.0 built with using:
cat << EOF | ~/Development/qemu/build/i386-softmmu/qemu-system-i386 -M pc-q35-5.0 -no-shutdown -M q35 -device megasas -device scsi-cd,drive=null0 -blockdev driver=null-co,read-zeroes=on,node-name=null0 -nographic -qtest stdio -monitor none -serial none
outl 0xcf8 0x80001814
outl 0xcfc 0xc021
outl 0xcf8 0x80001818
outl 0xcf8 0x80001804
outw 0xcfc 0x7
outl 0xcf8 0x80001810
outl 0xcfc 0xe10c0000
outl 0xcf8 0x8000f810
write 0x44b20 0x1 0x35
write 0x44b00 0x1 0x03
write 0xc021e10c0040 0x81 0x014b04000131000000014b04000138000000014b0400013f000000014b04000146000000014b0400014d000000014b04000154000000014b0400015b000000014b04000162000000014b04000169000000014b04000170000000014b04000177000000014b0400017e000000014b04000185000000014b0400018c000000014b04
EOF
I also attached the trace to this launchpad report, in case the formatting is broken:
qemu-system-i386 -qtest stdio -monitor none -serial none -M pc-q35-5.0 -no-shutdown -M q35 -device megasas -device scsi-cd,drive=null0 -blockdev driver=null-co,read-zeroes=on,node-name=null0 -nographic < attachment
Please let me know if I can provide any further info.
-Alex
Might be relevant:
commit 6df5718bd3ec56225c44cf96440c723c1b611b87
Author: Hannes Reinecke <email address hidden>
Date: Wed Oct 29 13:00:15 2014 +0100
megasas: Rework frame queueing algorithm
Windows requires the frames to be unmapped, otherwise we run
into a race condition where the updated frame data is not
visible to the guest.
With that we can simplify the queue algorithm and use a bitmap
for tracking free frames.
/*
* This absolutely needs to be locked if
* qemu ever goes multithreaded.
*/
static MegasasCmd *megasas_enqueue_frame(MegasasState *s,
hwaddr frame, uint64_t context, int count)
Using -trace scsi\* -trace megasas\*:
megasas_qf_enqueue frame 0x0 count 0 context 0x0 head 0x0 tail 0x0 busy 1
megasas_handle_scsi LD SCSI dev 1/0/0 sdev 0x5555573f5560 xfer 0
scsi_req_parsed target 0 lun 0 tag 0 command 53 dir 0 length 0
scsi_req_parsed_lba target 0 lun 0 tag 0 command 53 lba 0
scsi_req_alloc target 0 lun 0 tag 0
scsi_disk_new_request Command: lun=0 tag=0x0 data= 0x35 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
megasas_scsi_nodata scmd 0: no data to be transferred
megasas_mmio_invalid_writel addr 0x44: 0x3101
megasas_mmio_invalid_writel addr 0x48: 0x44b0100
megasas_mmio_invalid_writel addr 0x4c: 0x380100
megasas_mmio_invalid_writel addr 0x50: 0x4b010000
megasas_mmio_invalid_writel addr 0x54: 0x3f010004
megasas_mmio_invalid_writel addr 0x58: 0x1000000
megasas_mmio_invalid_writel addr 0x5c: 0x100044b
megasas_mmio_invalid_writel addr 0x60: 0x46
megasas_mmio_invalid_writel addr 0x64: 0x44b01
megasas_mmio_invalid_writel addr 0x68: 0x4d01
megasas_mmio_invalid_writel addr 0x6c: 0x44b0100
megasas_mmio_invalid_writel addr 0x70: 0x540100
megasas_mmio_invalid_writel addr 0x74: 0x4b010000
megasas_mmio_invalid_writel addr 0x78: 0x5b010004
megasas_mmio_invalid_writel addr 0x7c: 0x1000000
megasas_mmio_invalid_writel addr 0x80: 0x100044b
megasas_mmio_invalid_writel addr 0x84: 0x62
megasas_mmio_invalid_writel addr 0x88: 0x44b01
megasas_mmio_invalid_writel addr 0x8c: 0x6901
megasas_mmio_invalid_writel addr 0x90: 0x44b0100
megasas_mmio_invalid_writel addr 0x94: 0x700100
megasas_mmio_invalid_writel addr 0x98: 0x4b010000
megasas_mmio_invalid_writel addr 0x9c: 0x77010004
megasas_mmio_writel reg MFI_ODCR0: 0x1000000
megasas_mmio_invalid_writel addr 0xa4: 0x100044b
megasas_mmio_invalid_writel addr 0xa8: 0x7e
megasas_mmio_invalid_writel addr 0xac: 0x44b01
megasas_mmio_invalid_writel addr 0xb0: 0x8501
megasas_mmio_invalid_writel addr 0xb4: 0x44b0100
megasas_mmio_invalid_writel addr 0xb8: 0x8c0100
megasas_mmio_invalid_writel addr 0xbc: 0x4b010000
megasas_mmio_writel reg MFI_IQPL: 0x4
megasas_qf_new frame 0x1 addr 0x0
megasas_enqueue_frame fr: 0x7fffa1e00000
megasas_qf_enqueue frame 0x1 count 2 context 0x0 head 0x0 tail 0x0 busy 2
megasas_init_firmware pa 0x0
megasas_init_queue queue at 0x0 len 0 head 0x0 tail 0x0 flags 0x0
megasas_unmap_frame fr: 0x7fffa1e44b00
megasas_unmap_frame fr: 0x7fffa1e00000
megasas_qf_complete_noirq context 0x0
scsi_req_dequeue target 0 lun 0 tag 0
scsi_aio_complete
megasas_command_complete scmd 0: status 0x0, residual 0
megasas_scsi_complete scmd 0: status 0x0, len 0/0
The frame is unmapped when the complete callback occurs.
Then SIGSEGV in megasas_command_complete():
1856 static void megasas_command_complete(SCSIRequest *req, uint32_t status,
1857 size_t resid)
1858 {
1859 MegasasCmd *cmd = req->hba_private;
1860 uint8_t cmd_status = MFI_STAT_OK;
1861
1862 trace_megasas_command_complete(cmd->index, status, resid);
1863
1864 if (req->io_canceled) {
1865 return;
1866 }
1867
1868 if (cmd->dcmd_opcode != -1) {
1869 /*
1870 * Internal command complete
1871 */
1872 cmd_status = megasas_finish_internal_dcmd(cmd, req, resid);
1873 if (cmd_status == MFI_STAT_INVALID_STATUS) {
1874 return;
1875 }
1876 } else {
1877 req->status = status;
1878 trace_megasas_scsi_complete(cmd->index, req->status,
1879 cmd->iov_size, req->cmd.xfer);
1880 if (req->status != GOOD) {
1881 cmd_status = MFI_STAT_SCSI_DONE_WITH_ERROR;
1882 }
1883 if (req->status == CHECK_CONDITION) {
1884 megasas_copy_sense(cmd);
1885 }
1886
1887 cmd->frame->header.scsi_status = req->status;
^^^^^^^^^^ This is NULL.
1888 }
1889 cmd->frame->header.cmd_status = cmd_status;
1890 megasas_complete_command(cmd);
1891 }
Cc'ing Hannes who doesn't have a Launchpad account.
On 7/18/20 12:24 PM, Philippe Mathieu-Daudé wrote:
> Might be relevant:
>
> commit 6df5718bd3ec56225c44cf96440c723c1b611b87
> Author: Hannes Reinecke <email address hidden>
> Date: Wed Oct 29 13:00:15 2014 +0100
>
> megasas: Rework frame queueing algorithm
>
> Windows requires the frames to be unmapped, otherwise we run
> into a race condition where the updated frame data is not
> visible to the guest.
> With that we can simplify the queue algorithm and use a bitmap
> for tracking free frames.
>
> /*
> * This absolutely needs to be locked if
> * qemu ever goes multithreaded.
> */
> static MegasasCmd *megasas_enqueue_frame(MegasasState *s,
> hwaddr frame, uint64_t context, int count)
>
> Using -trace scsi\* -trace megasas\*:
>
> megasas_qf_enqueue frame 0x0 count 0 context 0x0 head 0x0 tail 0x0 busy 1
> megasas_handle_scsi LD SCSI dev 1/0/0 sdev 0x5555573f5560 xfer 0
> scsi_req_parsed target 0 lun 0 tag 0 command 53 dir 0 length 0
> scsi_req_parsed_lba target 0 lun 0 tag 0 command 53 lba 0
> scsi_req_alloc target 0 lun 0 tag 0
> scsi_disk_new_request Command: lun=0 tag=0x0 data= 0x35 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
> megasas_scsi_nodata scmd 0: no data to be transferred
> megasas_mmio_invalid_writel addr 0x44: 0x3101
> megasas_mmio_invalid_writel addr 0x48: 0x44b0100
> megasas_mmio_invalid_writel addr 0x4c: 0x380100
> megasas_mmio_invalid_writel addr 0x50: 0x4b010000
> megasas_mmio_invalid_writel addr 0x54: 0x3f010004
> megasas_mmio_invalid_writel addr 0x58: 0x1000000
> megasas_mmio_invalid_writel addr 0x5c: 0x100044b
> megasas_mmio_invalid_writel addr 0x60: 0x46
> megasas_mmio_invalid_writel addr 0x64: 0x44b01
> megasas_mmio_invalid_writel addr 0x68: 0x4d01
> megasas_mmio_invalid_writel addr 0x6c: 0x44b0100
> megasas_mmio_invalid_writel addr 0x70: 0x540100
> megasas_mmio_invalid_writel addr 0x74: 0x4b010000
> megasas_mmio_invalid_writel addr 0x78: 0x5b010004
> megasas_mmio_invalid_writel addr 0x7c: 0x1000000
> megasas_mmio_invalid_writel addr 0x80: 0x100044b
> megasas_mmio_invalid_writel addr 0x84: 0x62
> megasas_mmio_invalid_writel addr 0x88: 0x44b01
> megasas_mmio_invalid_writel addr 0x8c: 0x6901
> megasas_mmio_invalid_writel addr 0x90: 0x44b0100
> megasas_mmio_invalid_writel addr 0x94: 0x700100
> megasas_mmio_invalid_writel addr 0x98: 0x4b010000
> megasas_mmio_invalid_writel addr 0x9c: 0x77010004
> megasas_mmio_writel reg MFI_ODCR0: 0x1000000
> megasas_mmio_invalid_writel addr 0xa4: 0x100044b
> megasas_mmio_invalid_writel addr 0xa8: 0x7e
> megasas_mmio_invalid_writel addr 0xac: 0x44b01
> megasas_mmio_invalid_writel addr 0xb0: 0x8501
> megasas_mmio_invalid_writel addr 0xb4: 0x44b0100
> megasas_mmio_invalid_writel addr 0xb8: 0x8c0100
> megasas_mmio_invalid_writel addr 0xbc: 0x4b010000
> megasas_mmio_writel reg MFI_IQPL: 0x4
> megasas_qf_new frame 0x1 addr 0x0
> megasas_enqueue_frame fr: 0x7fffa1e00000
> megasas_qf_enqueue frame 0x1 count 2 context 0x0 head 0x0 tail 0x0 busy 2
> megasas_init_firmware pa 0x0
> megasas_init_queue queue at 0x0 len 0 head 0x0 tail 0x0 flags 0x0
> megasas_unmap_frame fr: 0x7fffa1e44b00
> megasas_unmap_frame fr: 0x7fffa1e00000
> megasas_qf_complete_noirq context 0x0
> scsi_req_dequeue target 0 lun 0 tag 0
> scsi_aio_complete
> megasas_command_complete scmd 0: status 0x0, residual 0
> megasas_scsi_complete scmd 0: status 0x0, len 0/0
>
> The frame is unmapped when the complete callback occurs.
> Then SIGSEGV in megasas_command_complete():
>
> 1856 static void megasas_command_complete(SCSIRequest *req, uint32_t status,
> 1857 size_t resid)
> 1858 {
> 1859 MegasasCmd *cmd = req->hba_private;
> 1860 uint8_t cmd_status = MFI_STAT_OK;
> 1861
> 1862 trace_megasas_command_complete(cmd->index, status, resid);
> 1863
> 1864 if (req->io_canceled) {
> 1865 return;
> 1866 }
> 1867
> 1868 if (cmd->dcmd_opcode != -1) {
> 1869 /*
> 1870 * Internal command complete
> 1871 */
> 1872 cmd_status = megasas_finish_internal_dcmd(cmd, req, resid);
> 1873 if (cmd_status == MFI_STAT_INVALID_STATUS) {
> 1874 return;
> 1875 }
> 1876 } else {
> 1877 req->status = status;
> 1878 trace_megasas_scsi_complete(cmd->index, req->status,
> 1879 cmd->iov_size, req->cmd.xfer);
> 1880 if (req->status != GOOD) {
> 1881 cmd_status = MFI_STAT_SCSI_DONE_WITH_ERROR;
> 1882 }
> 1883 if (req->status == CHECK_CONDITION) {
> 1884 megasas_copy_sense(cmd);
> 1885 }
> 1886
> 1887 cmd->frame->header.scsi_status = req->status;
>
> ^^^^^^^^^^ This is NULL.
>
> 1888 }
> 1889 cmd->frame->header.cmd_status = cmd_status;
> 1890 megasas_complete_command(cmd);
> 1891 }
>
> ** Changed in: qemu
> Status: New => Confirmed
>
I ran this through my minimization script to remove the extraneous qtest
commands:
cat << EOF | ./i386-softmmu/qemu-system-i386 \
-M pc-q35-5.0 -no-shutdown -M q35 -device megasas \
-device scsi-cd,drive=null0 \
-blockdev driver=null-co,read-zeroes=on,node-name=null0 \
-nographic -qtest stdio -monitor none -serial none
outl 0xcf8 0x80001814
outl 0xcfc 0xc021
outl 0xcf8 0x80001804
outw 0xcfc 0x7
outl 0xcf8 0x80001810
outl 0xcfc 0xe10c0000
write 0x44b20 0x1 0x35
write 0x44b00 0x1 0x03
write 0xc021e10c0040 0x4 0x014b0400
write 0xc021e10c00c0 0x1 0x04
EOF
On 200718 1024, Philippe Mathieu-Daudé wrote:
> Might be relevant:
>
> commit 6df5718bd3ec56225c44cf96440c723c1b611b87
> Author: Hannes Reinecke <email address hidden>
> Date: Wed Oct 29 13:00:15 2014 +0100
>
> megasas: Rework frame queueing algorithm
>
> Windows requires the frames to be unmapped, otherwise we run
> into a race condition where the updated frame data is not
> visible to the guest.
> With that we can simplify the queue algorithm and use a bitmap
> for tracking free frames.
>
> /*
> * This absolutely needs to be locked if
> * qemu ever goes multithreaded.
> */
> static MegasasCmd *megasas_enqueue_frame(MegasasState *s,
> hwaddr frame, uint64_t context, int count)
>
> Using -trace scsi\* -trace megasas\*:
>
> megasas_qf_enqueue frame 0x0 count 0 context 0x0 head 0x0 tail 0x0 busy 1
> megasas_handle_scsi LD SCSI dev 1/0/0 sdev 0x5555573f5560 xfer 0
> scsi_req_parsed target 0 lun 0 tag 0 command 53 dir 0 length 0
> scsi_req_parsed_lba target 0 lun 0 tag 0 command 53 lba 0
> scsi_req_alloc target 0 lun 0 tag 0
> scsi_disk_new_request Command: lun=0 tag=0x0 data= 0x35 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
> megasas_scsi_nodata scmd 0: no data to be transferred
> megasas_mmio_invalid_writel addr 0x44: 0x3101
> megasas_mmio_invalid_writel addr 0x48: 0x44b0100
> megasas_mmio_invalid_writel addr 0x4c: 0x380100
> megasas_mmio_invalid_writel addr 0x50: 0x4b010000
> megasas_mmio_invalid_writel addr 0x54: 0x3f010004
> megasas_mmio_invalid_writel addr 0x58: 0x1000000
> megasas_mmio_invalid_writel addr 0x5c: 0x100044b
> megasas_mmio_invalid_writel addr 0x60: 0x46
> megasas_mmio_invalid_writel addr 0x64: 0x44b01
> megasas_mmio_invalid_writel addr 0x68: 0x4d01
> megasas_mmio_invalid_writel addr 0x6c: 0x44b0100
> megasas_mmio_invalid_writel addr 0x70: 0x540100
> megasas_mmio_invalid_writel addr 0x74: 0x4b010000
> megasas_mmio_invalid_writel addr 0x78: 0x5b010004
> megasas_mmio_invalid_writel addr 0x7c: 0x1000000
> megasas_mmio_invalid_writel addr 0x80: 0x100044b
> megasas_mmio_invalid_writel addr 0x84: 0x62
> megasas_mmio_invalid_writel addr 0x88: 0x44b01
> megasas_mmio_invalid_writel addr 0x8c: 0x6901
> megasas_mmio_invalid_writel addr 0x90: 0x44b0100
> megasas_mmio_invalid_writel addr 0x94: 0x700100
> megasas_mmio_invalid_writel addr 0x98: 0x4b010000
> megasas_mmio_invalid_writel addr 0x9c: 0x77010004
> megasas_mmio_writel reg MFI_ODCR0: 0x1000000
> megasas_mmio_invalid_writel addr 0xa4: 0x100044b
> megasas_mmio_invalid_writel addr 0xa8: 0x7e
> megasas_mmio_invalid_writel addr 0xac: 0x44b01
> megasas_mmio_invalid_writel addr 0xb0: 0x8501
> megasas_mmio_invalid_writel addr 0xb4: 0x44b0100
> megasas_mmio_invalid_writel addr 0xb8: 0x8c0100
> megasas_mmio_invalid_writel addr 0xbc: 0x4b010000
> megasas_mmio_writel reg MFI_IQPL: 0x4
> megasas_qf_new frame 0x1 addr 0x0
> megasas_enqueue_frame fr: 0x7fffa1e00000
> megasas_qf_enqueue frame 0x1 count 2 context 0x0 head 0x0 tail 0x0 busy 2
> megasas_init_firmware pa 0x0
> megasas_init_queue queue at 0x0 len 0 head 0x0 tail 0x0 flags 0x0
> megasas_unmap_frame fr: 0x7fffa1e44b00
> megasas_unmap_frame fr: 0x7fffa1e00000
> megasas_qf_complete_noirq context 0x0
> scsi_req_dequeue target 0 lun 0 tag 0
> scsi_aio_complete
> megasas_command_complete scmd 0: status 0x0, residual 0
> megasas_scsi_complete scmd 0: status 0x0, len 0/0
>
> The frame is unmapped when the complete callback occurs.
> Then SIGSEGV in megasas_command_complete():
>
> 1856 static void megasas_command_complete(SCSIRequest *req, uint32_t status,
> 1857 size_t resid)
> 1858 {
> 1859 MegasasCmd *cmd = req->hba_private;
> 1860 uint8_t cmd_status = MFI_STAT_OK;
> 1861
> 1862 trace_megasas_command_complete(cmd->index, status, resid);
> 1863
> 1864 if (req->io_canceled) {
> 1865 return;
> 1866 }
> 1867
> 1868 if (cmd->dcmd_opcode != -1) {
> 1869 /*
> 1870 * Internal command complete
> 1871 */
> 1872 cmd_status = megasas_finish_internal_dcmd(cmd, req, resid);
> 1873 if (cmd_status == MFI_STAT_INVALID_STATUS) {
> 1874 return;
> 1875 }
> 1876 } else {
> 1877 req->status = status;
> 1878 trace_megasas_scsi_complete(cmd->index, req->status,
> 1879 cmd->iov_size, req->cmd.xfer);
> 1880 if (req->status != GOOD) {
> 1881 cmd_status = MFI_STAT_SCSI_DONE_WITH_ERROR;
> 1882 }
> 1883 if (req->status == CHECK_CONDITION) {
> 1884 megasas_copy_sense(cmd);
> 1885 }
> 1886
> 1887 cmd->frame->header.scsi_status = req->status;
>
> ^^^^^^^^^^ This is NULL.
>
> 1888 }
> 1889 cmd->frame->header.cmd_status = cmd_status;
> 1890 megasas_complete_command(cmd);
> 1891 }
>
> ** Changed in: qemu
> Status: New => Confirmed
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1878057
>
> Title:
> null-ptr dereference in megasas_command_complete
>
> Status in QEMU:
> Confirmed
>
> Bug description:
> Hello,
> While fuzzing, I found an input that triggers a null-pointer dereference in
> megasas_command_complete:
>
> ==14959==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000003 (pc 0x55b1d11b4df1 bp 0x7ffeb55ca450 sp 0x7ffeb55ca1e0 T0)
> ==14959==The signal is caused by a WRITE memory access.
> ==14959==Hint: address points to the zero page.
> #0 0x55b1d11b4df1 in megasas_command_complete /home/alxndr/Development/qemu/hw/scsi/megasas.c:1877:40
> #1 0x55b1d11759ec in scsi_req_complete /home/alxndr/Development/qemu/hw/scsi/scsi-bus.c:1430:5
> #2 0x55b1d115c98f in scsi_aio_complete /home/alxndr/Development/qemu/hw/scsi/scsi-disk.c:216:5
> #3 0x55b1d151c638 in blk_aio_complete /home/alxndr/Development/qemu/block/block-backend.c:1375:9
> #4 0x55b1d151c638 in blk_aio_complete_bh /home/alxndr/Development/qemu/block/block-backend.c:1385:5
> #5 0x55b1d16f3a5b in aio_bh_call /home/alxndr/Development/qemu/util/async.c:136:5
> #6 0x55b1d16f3a5b in aio_bh_poll /home/alxndr/Development/qemu/util/async.c:164:13
> #7 0x55b1d16fe43e in aio_dispatch /home/alxndr/Development/qemu/util/aio-posix.c:380:5
> #8 0x55b1d16f54fa in aio_ctx_dispatch /home/alxndr/Development/qemu/util/async.c:306:5
> #9 0x7f47937c89ed in g_main_context_dispatch (/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x4e9ed)
> #10 0x55b1d16fbef4 in glib_pollfds_poll /home/alxndr/Development/qemu/util/main-loop.c:219:9
> #11 0x55b1d16fbef4 in os_host_main_loop_wait /home/alxndr/Development/qemu/util/main-loop.c:242:5
> #12 0x55b1d16fbef4 in main_loop_wait /home/alxndr/Development/qemu/util/main-loop.c:518:11
> #13 0x55b1d0cd16a6 in qemu_main_loop /home/alxndr/Development/qemu/softmmu/vl.c:1664:9
> #14 0x55b1d1608dca in main /home/alxndr/Development/qemu/softmmu/main.c:49:5
> #15 0x7f4792378e0a in __libc_start_main /build/glibc-GwnBeO/glibc-2.30/csu/../csu/libc-start.c:308:16
> #16 0x55b1d091d7b9 in _start (/home/alxndr/Development/qemu/build/i386-softmmu/qemu-system-i386+0x8f47b9)
>
> I can reproduce it in qemu 5.0 built with using:
> cat << EOF | ~/Development/qemu/build/i386-softmmu/qemu-system-i386 -M pc-q35-5.0 -no-shutdown -M q35 -device megasas -device scsi-cd,drive=null0 -blockdev driver=null-co,read-zeroes=on,node-name=null0 -nographic -qtest stdio -monitor none -serial none
> outl 0xcf8 0x80001814
> outl 0xcfc 0xc021
> outl 0xcf8 0x80001818
> outl 0xcf8 0x80001804
> outw 0xcfc 0x7
> outl 0xcf8 0x80001810
> outl 0xcfc 0xe10c0000
> outl 0xcf8 0x8000f810
> write 0x44b20 0x1 0x35
> write 0x44b00 0x1 0x03
> write 0xc021e10c0040 0x81 0x014b04000131000000014b04000138000000014b0400013f000000014b04000146000000014b0400014d000000014b04000154000000014b0400015b000000014b04000162000000014b04000169000000014b04000170000000014b04000177000000014b0400017e000000014b04000185000000014b0400018c000000014b04
> EOF
>
> I also attached the trace to this launchpad report, in case the
> formatting is broken:
>
> qemu-system-i386 -qtest stdio -monitor none -serial none -M pc-q35-5.0
> -no-shutdown -M q35 -device megasas -device scsi-cd,drive=null0
> -blockdev driver=null-co,read-zeroes=on,node-name=null0 -nographic <
> attachment
>
> Please let me know if I can provide any further info.
> -Alex
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/qemu/+bug/1878057/+subscriptions
Can you still reproduce this issue with the current version of QEMU? For me, it does not crash anymore, so I assume this has been fixed already?
Looks like OSS-Fuzz has a reproducer that still works:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=29192#c3
I'll move this one over to gitlab
If I get https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=29192#c4 right, this has been fixed some days later in June? Or is it still reproducible?
I moved this report over to QEMU's new bug tracker on gitlab.com.
Please continue with the discussion here:
https://gitlab.com/qemu-project/qemu/-/issues/551
Thanks for moving it over! ... let's close this one here on Launchpad now.
|