Skip to content

Commit fbd3039

Browse files
halil-pasicmstsirkin
authored andcommitted
virtio_console: fix missing byte order handling for cols and rows
As per virtio spec the fields cols and rows are specified as little endian. Although there is no legacy interface requirement that would state that cols and rows need to be handled as native endian when legacy interface is used, unlike for the fields of the adjacent struct virtio_console_control, I decided to err on the side of caution based on some non-conclusive virtio spec repo archaeology and opt for using virtio16_to_cpu() much like for virtio_console_control.event. Strictly by the letter of the spec virtio_le_to_cpu() would have been sufficient. But when the legacy interface is not used, it boils down to the same. And when using the legacy interface, the device formatting these as little endian when the guest is big endian would surprise me more than it using guest native byte order (which would make it compatible with the current implementation). Nevertheless somebody trying to implement the spec following it to the letter could end up forcing little endian byte order when the legacy interface is in use. So IMHO this ultimately needs a judgement call by the maintainers. Fixes: 8345adb ("virtio: console: Accept console size along with resize control message") Signed-off-by: Halil Pasic <pasic@linux.ibm.com> Cc: stable@vger.kernel.org # v2.6.35+ Message-Id: <20250322002954.3129282-1-pasic@linux.ibm.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent 183a087 commit fbd3039

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

drivers/char/virtio_console.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,16 +1576,17 @@ static void handle_control_message(struct virtio_device *vdev,
15761576
break;
15771577
case VIRTIO_CONSOLE_RESIZE: {
15781578
struct {
1579-
__u16 rows;
1580-
__u16 cols;
1579+
__virtio16 rows;
1580+
__virtio16 cols;
15811581
} size;
15821582

15831583
if (!is_console_port(port))
15841584
break;
15851585

15861586
memcpy(&size, buf->buf + buf->offset + sizeof(*cpkt),
15871587
sizeof(size));
1588-
set_console_size(port, size.rows, size.cols);
1588+
set_console_size(port, virtio16_to_cpu(vdev, size.rows),
1589+
virtio16_to_cpu(vdev, size.cols));
15891590

15901591
port->cons.hvc->irq_requested = 1;
15911592
resize_console(port);

0 commit comments

Comments
 (0)