Commit 6fb5280
committed
drivers: validate device-supplied completion ids (virtio used-ring, NVMe cid)
Two OOB accesses driven by a malicious or buggy device backend (relevant for
untrusted/soft hypervisor backends; kernel memory corruption in a unikernel):
1. virtio used-ring (drivers/virtio-vring.cc): the used-element _id is written
by the device and was used directly to index _cookie[] (allocated with _num
entries): 'cookie = _cookie[elem._id]; _cookie[elem._id] = nullptr;'. A
backend returning _id >= _num causes an OOB read of a bogus cookie pointer
(later dereferenced/freed) plus an OOB NULL write past the array. Reject
elem._id >= _num.
2. NVMe completion (drivers/nvme-queue.cc): the completion-queue-entry cid is
device-supplied and indexed _pending_bios[cid/_qsize][cid%_qsize] where the
row dimension is only max_pending_levels (4). A controller returning a cid
with cid/_qsize >= 4 indexes _pending_bios[] out of bounds; the following
assert(pending_bio) is compiled out in release builds, so it was not a real
guard. Validate cid_to_row(cid) < max_pending_levels and that the slot is
non-null (skip duplicate/spurious completions) before use.
Verified: boot + virtio-blk I/O (tst-vblk) still pass.1 parent 97463b2 commit 6fb5280
2 files changed
Lines changed: 22 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
342 | 342 | | |
343 | 343 | | |
344 | 344 | | |
345 | | - | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
346 | 350 | | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
347 | 356 | | |
348 | | - | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
349 | 362 | | |
350 | 363 | | |
351 | 364 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
271 | 271 | | |
272 | 272 | | |
273 | 273 | | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
274 | 281 | | |
275 | 282 | | |
276 | 283 | | |
| |||
0 commit comments