Commit c5ac056
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 1603209 commit c5ac056
2 files changed
Lines changed: 22 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
341 | 341 | | |
342 | 342 | | |
343 | 343 | | |
344 | | - | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
345 | 349 | | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
346 | 355 | | |
347 | | - | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
348 | 361 | | |
349 | 362 | | |
350 | 363 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
257 | 257 | | |
258 | 258 | | |
259 | 259 | | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
260 | 267 | | |
261 | 268 | | |
262 | 269 | | |
| |||
0 commit comments