Subject: CVE-2024-27066: virtio: packed: fix unmap leak for indirect desc table

From: Greg Kroah-Hartman <[email-masked]>

Description
===========

In the Linux kernel, the following vulnerability has been resolved:

virtio: packed: fix unmap leak for indirect desc table

When use_dma_api and premapped are true, then the do_unmap is false.

Because the do_unmap is false, vring_unmap_extra_packed is not called by
detach_buf_packed.

  if (unlikely(vq->do_unmap)) {
                curr = id;
                for (i = 0; i < state->num; i++) {
                        vring_unmap_extra_packed(vq,
                                                 &vq->packed.desc_extra[curr]);
                        curr = vq->packed.desc_extra[curr].next;
                }
  }

So the indirect desc table is not unmapped. This causes the unmap leak.

So here, we check vq->use_dma_api instead. Synchronously, dma info is
updated based on use_dma_api judgment

This bug does not occur, because no driver use the premapped with
indirect.

The Linux kernel CVE team has assigned CVE-2024-27066 to this issue.

Affected and fixed versions
===========================

	Issue introduced in 6.6 with commit b319940f83c2 and fixed in 6.6.23 with commit e142169aca55
	Issue introduced in 6.6 with commit b319940f83c2 and fixed in 6.7.11 with commit 75450ff8c6fe
	Issue introduced in 6.6 with commit b319940f83c2 and fixed in 6.8.2 with commit 51bacd9d29bf
	Issue introduced in 6.6 with commit b319940f83c2 and fixed in 6.9 with commit d5c0ed17fea6

Please see https://www.kernel.org for a full list of currently supported
kernel versions by the kernel community.

Unaffected versions might change over time as fixes are backported to
older supported kernel versions.  The official CVE entry at
	https://cve.org/CVERecord/?id=CVE-2024-27066
will be updated if fixes are backported, please check that for the most
up to date information about this issue.

Affected files
==============

The file(s) affected by this issue are:
	drivers/virtio/virtio_ring.c

Mitigation
==========

The Linux kernel CVE team recommends that you update to the latest
stable kernel version for this, and many other bugfixes.  Individual
changes are never tested alone, but rather are part of a larger kernel
release.  Cherry-picking individual commits is not recommended or
supported by the Linux kernel community at all.  If however, updating to
the latest release is impossible, the individual changes to resolve this
issue can be found at these commits:
	https://git.kernel.org/stable/c/e142169aca5546ae6619c39a575cda8105362100
	https://git.kernel.org/stable/c/75450ff8c6fe8755bf5b139b238eaf9739cfd64e
	https://git.kernel.org/stable/c/51bacd9d29bf98c3ebc65e4a0477bb86306b4140
	https://git.kernel.org/stable/c/d5c0ed17fea60cca9bc3bf1278b49ba79242bbcd