Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] virtio_ring: DMA mapping leak in virtqueue_add_split() at total_sg == 65536 --
commit f02f3f32e75945fa59c0806b58f447abf08594d4 Author: Seojin An <[email protected]> virtio_ring: reject unrepresentable split indirect tables This commit rejects split indirect descriptor tables in virtqueue_add_split() when total_sg exceeds 65,536, preventing 16-bit descriptor index wrapping. > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c > index f683a2d6a2002..ad9e52584fb52 100644 > --- a/drivers/virtio/virtio_ring.c > +++ b/drivers/virtio/virtio_ring.c > @@ -686,9 +686,19 @@ static inline int virtqueue_add_split(struct > vring_virtqueue *vq, > > head = vq->free_head; > > - if (virtqueue_use_indirect(vq, total_sg)) > + if (virtqueue_use_indirect(vq, total_sg)) { > + /* > + * The core historically permits an indirect chain to exceed the > + * queue size. Preserve that policy, but do not let its 16-bit > + * split descriptor links wrap within the allocated table. > + */ > + if (unlikely(total_sg > (1U << 16))) { > + END_USE(vq); > + return -E2BIG; > + } > + > desc = alloc_indirect_split(vq, total_sg, gfp); > - else { > + } else { > desc = NULL; > WARN_ON_ONCE(total_sg > vq->split.vring.num && !vq->indirect); > } [Severity: Medium] Can total_sg == (1U << 16) still wrap i to 0 after the final descriptor and leak all 65,536 DMA mappings on the unmap_release path? alloc_indirect_split() sets extra[i].next = i + 1 (where next is u16), so for total_sg == 65536, extra[65535].next wraps to 0. After mapping all 65,536 SG entries, virtqueue_add_desc_split() returns that 0 into i. If vring_map_single() then fails when mapping the 1 MiB indirect descriptor table, unmap_release sees err_idx == 0 and i == 0 and breaks out of the cleanup loop on the first iteration without unmapping any of the SG entries: drivers/virtio/virtio_ring.c:virtqueue_add_split() { ... unmap_release: err_idx = i; if (indirect) i = 0; else i = head; for (n = 0; n < total_sg; n++) { if (i == err_idx) break; i = vring_unmap_one_split(vq, &extra[i]); } ... } -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=1
