virtio: validate device-reported values across drivers
Subsystems (6)
cover virtio: validate device-reported values across drivers
These four patches harden virtio-mem, virtio_input, and virtio_console against untrusted values coming from the device/backend side of the virtio interface. The fourth fixes a use-after-free in virtio_console caused by a missing refcount.
Hari Mishal (4):
virtio-mem: validate device-reported block size
virtio_input: validate device-reported multitouch slot count
virtio_console: avoid NULL portdev dereference in in_intr()
virtio_console: take a kref in find_port_by_vq() to fix port UAF
drivers/char/virtio_console.c | 18 +++++++++++++++++- drivers/virtio/virtio_input.c | 4 ++++ drivers/virtio/virtio_mem.c | 7 +++++++ 3 files changed, 28 insertions(+), 1 deletion(-)
Signature · 1 line
2.43.0
PATCH 1/4 virtio-mem: validate device-reported block size
The device_block_size read from the virtio-mem config space is used as a divisor and also in ALIGN_DOWN() further down the code path in the driver without further validation. A zero value leads to a division by zero, and a non-power-of-two value corrupts the ALIGN_DOWN() bitmask arithmetic leading to a misreporting of guest usable guest ram, post crash. Reject both at init time instead of trusting the device.
--- drivers/virtio/virtio_mem.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/virtio/virtio_mem.c +7 -0
@@ -2847,6 +2847,13 @@ static int virtio_mem_init(struct virtio_mem *vm) &vm->plugged_size); virtio_cread_le(vm->vdev, struct virtio_mem_config, block_size, &vm->device_block_size); +if (!vm->device_block_size || + !is_power_of_2 (vm->device_block_size)) { +dev_err (&vm->vdev->dev, +"invalid device block size: 0x%llx\n" , + (unsigned long long )vm->device_block_size); +return -EINVAL ; + } virtio_cread_le(vm->vdev, struct virtio_mem_config, node_id, &node_id); vm->nid =virtio_mem_translate_node_id (vm, node_id);
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH 1/4] virtio-mem: validate device-reported block size
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing minimum threshold check for device_block_size leads to silent truncation of nb_vm_blocks to 16 bits, causing guest memory corruption. --
--- Patch [1]: [PATCH 1/4] virtio-mem: validate device-reported block size --- commit 1886b5144897e316d9afb5456f7874735bcb4c19
Author: Hari Mishal <[email protected]>
virtio-mem: validate device-reported block size
This commit adds validation to ensure the device-reported block size is non-zero and a power of two, preventing division by zero and miscalculated alignments.
Quoted 5 lines
drivers/virtio/virtio_mem.c +0
-0
drivers/virtio/virtio_mem.c static int virtio_mem_init(struct virtio_mem *vm) · line 2856
Quoted 10 lines
drivers/virtio/virtio_mem.c +7
-0@@ -2847,6 +2847,13 @@ static int virtio_mem_init(struct virtio_mem *vm) &vm->plugged_size); virtio_cread_le(vm->vdev, struct virtio_mem_config, block_size, &vm->device_block_size); +if (!vm->device_block_size || + !is_power_of_2 (vm->device_block_size)) { +dev_err (&vm->vdev->dev, +"invalid device block size: 0x%llx\n" , + (unsigned long long )vm->device_block_size); +return -EINVAL ; + }
[Severity: High]
This is a pre-existing issue, but does this validation also need to enforce a minimum threshold for device_block_size?
If a small power-of-two value like 16 or 32 is provided by the device, the calculated block count can easily exceed 65535.
For example, a minimum sub-block size of 2MB divided by 16 yields 131,072 blocks. When this is passed to virtio_mem_send_plug_request(), the value is silently truncated to 16 bits:
drivers/virtio/virtio_mem.c:virtio_mem_send_plug_request() {
...
.u.plug.nb_blocks = cpu_to_virtio16(vm->vdev, nb_vm_blocks),
...
}This truncation also happens in virtio_mem_send_unplug_request() and virtio_mem_send_state_request() via the .u.unplug.nb_blocks and .u.state.nb_blocks assignments.
Could this lead to the host processing a truncated request (e.g., plugging 0 blocks) while the guest kernel proceeds to add the full memory region, causing a crash when the unbacked memory is accessed?
Quoted 3 lines
drivers/virtio/virtio_mem.c +0
-0virtio_cread_le(vm->vdev, struct virtio_mem_config, node_id, &node_id); vm->nid =virtio_mem_translate_node_id (vm, node_id);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Michael S. Tsirkin
maintainerRe: [PATCH 1/4] virtio-mem: validate device-reported block size
In reply to Hari MishalQuoted 18 lines · Hari Mishal
The
device_block_sizeread from the virtio-mem config space is used as a divisor and also inALIGN_DOWN()further down the code path in the driver without further validation. A zero value leads to a division by zero, and a non-power-of-two value corrupts theALIGN_DOWN()bitmask arithmetic leading to a misreporting of guest usable guest ram, post crash. Reject both at init time instead of trusting the device.Assisted-by gkh_clanker:t1000Signed-off-by Hari Mishal <[email protected]>--- drivers/virtio/virtio_mem.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/virtio/virtio_mem.c +0
-0
drivers/virtio/virtio_mem.c static int virtio_mem_init(struct virtio_mem *vm) · line 2851
Quoted 5 lines
drivers/virtio/virtio_mem.c +2
-0@@ -2847,6 +2847,13 @@ static int virtio_mem_init(struct virtio_mem *vm) &vm->plugged_size); virtio_cread_le(vm->vdev, struct virtio_mem_config, block_size, &vm->device_block_size); +if (!vm->device_block_size || + !is_power_of_2 (vm->device_block_size)) {
0 is not a power of 2, why do we need to check twice?
Quoted 10 lines
drivers/virtio/virtio_mem.c +5
-0+dev_err (&vm->vdev->dev, +"invalid device block size: 0x%llx\n" , + (unsigned long long )vm->device_block_size); +return -EINVAL ; + } virtio_cread_le(vm->vdev, struct virtio_mem_config, node_id, &node_id); vm->nid =virtio_mem_translate_node_id (vm, node_id);Signature · 1 line
2.43.0
PATCH v2 1/4 virtio-mem: validate device-reported block size
In reply to Hari MishalThe device_block_size read from the virtio-mem config space is used as a divisor and also in ALIGN_DOWN() further down the code path in the driver without further validation. A zero value leads to a division by zero, and a non-power-of-two value corrupts the ALIGN_DOWN() bitmask arithmetic leading to a misreporting of guest-usable ram, post crash.
Reject both at init time instead of trusting the device.
---
v2: dropped the redundant explicit zero check, since
is_power_of_2(0) already returns false.
drivers/virtio/virtio_mem.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/virtio/virtio_mem.c +6 -0
@@ -2847,6 +2847,12 @@ static int virtio_mem_init(struct virtio_mem *vm) &vm->plugged_size); virtio_cread_le(vm->vdev, struct virtio_mem_config, block_size, &vm->device_block_size); +if (!is_power_of_2 (vm->device_block_size)) { +dev_err (&vm->vdev->dev, +"invalid device block size: 0x%llx\n" , + (unsigned long long )vm->device_block_size); +return -EINVAL ; + } virtio_cread_le(vm->vdev, struct virtio_mem_config, node_id, &node_id); vm->nid =virtio_mem_translate_node_id (vm, node_id);
Signature · 1 line
2.43.0
David Hildenbrand (Arm)
maintainerRe: [PATCH v2 1/4] virtio-mem: validate device-reported block size
Quoted 21 lines · Hari Mishal
The
device_block_sizeread from the virtio-mem config space is used as a divisor and also inALIGN_DOWN()further down the code path in the driver without further validation. A zero value leads to a division by zero, and a non-power-of-two value corrupts theALIGN_DOWN()bitmask arithmetic leading to a misreporting of guest-usable ram, post crash.Reject both at init time instead of trusting the device.
Signed-off-by Hari Mishal <[email protected]>---
v2: dropped the redundant explicit zero check, since
is_power_of_2(0)already returns false.drivers/virtio/virtio_mem.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/virtio/virtio_mem.c +0
-0
drivers/virtio/virtio_mem.c static int virtio_mem_init(struct virtio_mem *vm) · line 2855
Quoted 9 lines
drivers/virtio/virtio_mem.c +6
-0@@ -2847,6 +2847,12 @@ static int virtio_mem_init(struct virtio_mem *vm) &vm->plugged_size); virtio_cread_le(vm->vdev, struct virtio_mem_config, block_size, &vm->device_block_size); +if (!is_power_of_2 (vm->device_block_size)) { +dev_err (&vm->vdev->dev, +"invalid device block size: 0x%llx\n" , + (unsigned long long )vm->device_block_size); +return -EINVAL ; + }
The spec states "The device MUST set block_size to a power of two."
I'm missing the point here.
Signature · 3 lines
Cheers, David
Greg Kroah-Hartman
maintainerRe: [PATCH v2 1/4] virtio-mem: validate device-reported block size
Quoted 34 lines · David Hildenbrand (Arm)
Quoted 21 lines · Hari Mishal
The
device_block_sizeread from the virtio-mem config space is used as a divisor and also inALIGN_DOWN()further down the code path in the driver without further validation. A zero value leads to a division by zero, and a non-power-of-two value corrupts theALIGN_DOWN()bitmask arithmetic leading to a misreporting of guest-usable ram, post crash.Reject both at init time instead of trusting the device.
Signed-off-by Hari Mishal <[email protected]>---
v2: dropped the redundant explicit zero check, since
is_power_of_2(0)already returns false.drivers/virtio/virtio_mem.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/virtio/virtio_mem.c +0
-0drivers/virtio/virtio_mem.c static int virtio_mem_init(struct virtio_mem *vm) · line 2855
Quoted 9 lines
drivers/virtio/virtio_mem.c +6
-0@@ -2847,6 +2847,12 @@ static int virtio_mem_init(struct virtio_mem *vm) &vm->plugged_size); virtio_cread_le(vm->vdev, struct virtio_mem_config, block_size, &vm->device_block_size); +if (!is_power_of_2 (vm->device_block_size)) { +dev_err (&vm->vdev->dev, +"invalid device block size: 0x%llx\n" , + (unsigned long long )vm->device_block_size); +return -EINVAL ; + }The spec states "The device MUST set
block_sizeto a power of two."
Quoted 1 line
I'm missing the point here.
So what happens if we have a non-spec-compliant device? Shouldn't we be attempting to verify this before doing something with the data?
Or do we just always trust virtio mem devices explicitly?
thanks,
greg k-h
David Hildenbrand (Arm)
maintainerRe: [PATCH v2 1/4] virtio-mem: validate device-reported block size
Quoted 35 lines · Greg Kroah-Hartman
Quoted 34 lines · David Hildenbrand (Arm)
Quoted 21 lines · Hari Mishal
The
device_block_sizeread from the virtio-mem config space is used as a divisor and also inALIGN_DOWN()further down the code path in the driver without further validation. A zero value leads to a division by zero, and a non-power-of-two value corrupts theALIGN_DOWN()bitmask arithmetic leading to a misreporting of guest-usable ram, post crash.Reject both at init time instead of trusting the device.
Signed-off-by Hari Mishal <[email protected]>---
v2: dropped the redundant explicit zero check, since
is_power_of_2(0)already returns false.drivers/virtio/virtio_mem.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/virtio/virtio_mem.c +0
-0drivers/virtio/virtio_mem.c static int virtio_mem_init(struct virtio_mem *vm) · line 2855
Quoted 9 lines
drivers/virtio/virtio_mem.c +6
-0@@ -2847,6 +2847,12 @@ static int virtio_mem_init(struct virtio_mem *vm) &vm->plugged_size); virtio_cread_le(vm->vdev, struct virtio_mem_config, block_size, &vm->device_block_size); +if (!is_power_of_2 (vm->device_block_size)) { +dev_err (&vm->vdev->dev, +"invalid device block size: 0x%llx\n" , + (unsigned long long )vm->device_block_size); +return -EINVAL ; + }The spec states "The device MUST set
block_sizeto a power of two."
Quoted 4 lines
Quoted 1 line
I'm missing the point here.
So what happens if we have a non-spec-compliant device? Shouldn't we be attempting to verify this before doing something with the data?
The problem I see is that there are plenty of other devices where a non-compliant device might cause problems.
Like, we request to hotplug some memory block and our device ACKs it, but it simply didn't do that.
Or we request to hotunplug a memory block and instead it hotplugs some random other memory block.
Or we sense whether a memory block is plugged and the device lies to us.
Quoted 2 lines
Or do we just always trust virtio mem devices explicitly?
It's hard for me to understand where we draw the line, really.
But maybe MST can clarify what we care about in virtio world where the hypervisor is fully in charge of the device,
Signature · 3 lines
Cheers, David
Greg Kroah-Hartman
maintainerRe: [PATCH v2 1/4] virtio-mem: validate device-reported block size
Quoted 53 lines · David Hildenbrand (Arm)
Quoted 35 lines · Greg Kroah-Hartman
Quoted 34 lines · David Hildenbrand (Arm)
Quoted 21 lines · Hari Mishal
The
device_block_sizeread from the virtio-mem config space is used as a divisor and also inALIGN_DOWN()further down the code path in the driver without further validation. A zero value leads to a division by zero, and a non-power-of-two value corrupts theALIGN_DOWN()bitmask arithmetic leading to a misreporting of guest-usable ram, post crash.Reject both at init time instead of trusting the device.
Signed-off-by Hari Mishal <[email protected]>---
v2: dropped the redundant explicit zero check, since
is_power_of_2(0)already returns false.drivers/virtio/virtio_mem.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/virtio/virtio_mem.c +0
-0drivers/virtio/virtio_mem.c static int virtio_mem_init(struct virtio_mem *vm) · line 2855
Quoted 9 lines
drivers/virtio/virtio_mem.c +6
-0@@ -2847,6 +2847,12 @@ static int virtio_mem_init(struct virtio_mem *vm) &vm->plugged_size); virtio_cread_le(vm->vdev, struct virtio_mem_config, block_size, &vm->device_block_size); +if (!is_power_of_2 (vm->device_block_size)) { +dev_err (&vm->vdev->dev, +"invalid device block size: 0x%llx\n" , + (unsigned long long )vm->device_block_size); +return -EINVAL ; + }The spec states "The device MUST set
block_sizeto a power of two."Quoted 4 lines
Quoted 1 line
I'm missing the point here.
So what happens if we have a non-spec-compliant device? Shouldn't we be attempting to verify this before doing something with the data?
The problem I see is that there are plenty of other devices where a non-compliant device might cause problems.
Like, we request to hotplug some memory block and our device ACKs it, but it simply didn't do that.
Or we request to hotunplug a memory block and instead it hotplugs some random other memory block.
Or we sense whether a memory block is plugged and the device lies to us.
Quoted 1 line
Quoted 6 lines
Quoted 1 line
Or do we just always trust virtio mem devices explicitly?
It's hard for me to understand where we draw the line, really.
But maybe MST can clarify what we care about in virtio world where the hypervisor is fully in charge of the device,
That would be good to figure out, and write down somewhere, so we know what to worry about here.
Right now, for almost all subsystems, Linux trusts the hardware explicitly. But for some subsystems, it doesn't, or doesn't until "something" happens (example, USB devices are untrusted until we bind a driver to the device, and then they are trusted.)
But there are some people that want to never trust the hardware, or have it in different states, specifically for virtual machines like this driver operates in. The CoC model is just that, and patches from Dan are working toward clearing this up a lot for some types of devices (PCI and IOMMU), but I don't think they have thought about virtio devices yet...
thanks,
greg k-h
Michael S. Tsirkin
maintainerRe: [PATCH v2 1/4] virtio-mem: validate device-reported block size
In reply to David Hildenbrand (Arm)Quoted 6 lines · David Hildenbrand (Arm)
Quoted 1 line
Or do we just always trust virtio mem devices explicitly?
It's hard for me to understand where we draw the line, really.
But maybe MST can clarify what we care about in virtio world where the hypervisor is fully in charge of the device,
Generally:
- The guest is expected to whitelist drivers (most drivers have not been audited).
- Denial of service by the hypervisor is not considered a threat (this is how cloud vendors charge their clients, by denying service to whoever did not pay).
Signature · 1 line
MST
David Hildenbrand (Arm)
maintainerRe: [PATCH v2 1/4] virtio-mem: validate device-reported block size
Quoted 11 lines · Michael S. Tsirkin
Quoted 6 lines · David Hildenbrand (Arm)
Quoted 1 line
Or do we just always trust virtio mem devices explicitly?
It's hard for me to understand where we draw the line, really.
But maybe MST can clarify what we care about in virtio world where the hypervisor is fully in charge of the device,
Generally:
- The guest is expected to whitelist drivers (most drivers have not been audited).
But even if you audited your driver, who makes sure that we consider all ways where the device could mess with us?
Something feels off here.
Handling selected out-of-spec scenarios like this feels like a band-aid. Happy to be corrected.
Signature · 3 lines
Cheers, David
Michael S. Tsirkin
maintainerRe: [PATCH v2 1/4] virtio-mem: validate device-reported block size
Quoted 9 lines · David Hildenbrand (Arm)
Quoted 8 lines · Michael S. Tsirkin
Quoted 6 lines · David Hildenbrand (Arm)
Quoted 1 line
Or do we just always trust virtio mem devices explicitly?
It's hard for me to understand where we draw the line, really.
But maybe MST can clarify what we care about in virtio world where the hypervisor is fully in charge of the device,
Quoted 6 lines
Quoted 3 lines
Generally:
- The guest is expected to whitelist drivers (most drivers have not been audited).But even if you audited your driver, who makes sure that we consider all ways where the device could mess with us?
A lot of this is up to a correct setup. For example, make sure all filesystems are encrypted and refuse to mount unencrypted ones.
Quoted 4 lines
Something feels off here.
Handling selected out-of-spec scenarios like this feels like a band-aid. Happy to be corrected.
Well Documentation/security/snp-tdx-threat-model.rst puts it like this:
It is important to note
that this doesn’t imply that the host or VMM are intentionally malicious, but that there exists a security value in having a small CoCo VM TCB.
and
While traditionally the host has unlimited access to guest data and can leverage this access to attack the guest, the CoCo systems mitigate such attacks by adding security features like guest data confidentiality and integrity protection.
now, when we are talking about "mitigation" it is indeed becoming a bit murky.
For me, a rule of thumb I came up with is that if the validation happens to also be helful for users e.g. to work around buggy devices, or maybe because we feel failing gracefully is nice because this will allow to later make use of this config and old drivers will fail but at least not panic, then it is good to include.
Quoted 4 lines
Signature · 3 lines
Cheers, David
Greg Kroah-Hartman
maintainerRe: [PATCH v2 1/4] virtio-mem: validate device-reported block size
Quoted 43 lines · Michael S. Tsirkin
Quoted 9 lines · David Hildenbrand (Arm)
Quoted 8 lines · Michael S. Tsirkin
Quoted 6 lines · David Hildenbrand (Arm)
Quoted 1 line
Or do we just always trust virtio mem devices explicitly?
It's hard for me to understand where we draw the line, really.
But maybe MST can clarify what we care about in virtio world where the hypervisor is fully in charge of the device,
Quoted 6 lines
Quoted 3 lines
Generally:
- The guest is expected to whitelist drivers (most drivers have not been audited).But even if you audited your driver, who makes sure that we consider all ways where the device could mess with us?
A lot of this is up to a correct setup. For example, make sure all filesystems are encrypted and refuse to mount unencrypted ones.
Quoted 4 lines
Something feels off here.
Handling selected out-of-spec scenarios like this feels like a band-aid. Happy to be corrected.
Well
Documentation/security/snp-tdx-threat-model.rstputs it like this:
It is important to note
that this doesn’t imply that the host or VMM are intentionally malicious, but that there exists a security value in having a small CoCo VM TCB.and
While traditionally the host has unlimited access to guest data and can leverage this access to attack the guest, the CoCo systems mitigate such attacks by adding security features like guest data confidentiality and integrity protection.
now, when we are talking about "mitigation" it is indeed becoming a bit murky.
Quoted 5 lines
For me, a rule of thumb I came up with is that if the validation happens to also be helful for users e.g. to work around buggy devices, or maybe because we feel failing gracefully is nice because this will allow to later make use of this config and old drivers will fail but at least not panic, then it is good to include.
Why not do what USB does? Don't trust the device until AFTER probe() succeeds? All of the needed checking should happen before then, as that is a "slow path" so lots of validation and the like can happen at that point.
After that, during the normal data paths, after the driver is bound, trust it all you want as attempting to validate every single packet is just going to be impossible.
thanks,
greg k-h
Michael S. Tsirkin
maintainerRe: [PATCH v2 1/4] virtio-mem: validate device-reported block size
Quoted 55 lines · Greg Kroah-Hartman
Quoted 43 lines · Michael S. Tsirkin
Quoted 9 lines · David Hildenbrand (Arm)
Quoted 8 lines · Michael S. Tsirkin
Quoted 6 lines · David Hildenbrand (Arm)
Quoted 1 line
Or do we just always trust virtio mem devices explicitly?
It's hard for me to understand where we draw the line, really.
But maybe MST can clarify what we care about in virtio world where the hypervisor is fully in charge of the device,
Quoted 6 lines
Quoted 3 lines
Generally:
- The guest is expected to whitelist drivers (most drivers have not been audited).But even if you audited your driver, who makes sure that we consider all ways where the device could mess with us?
A lot of this is up to a correct setup. For example, make sure all filesystems are encrypted and refuse to mount unencrypted ones.
Quoted 4 lines
Something feels off here.
Handling selected out-of-spec scenarios like this feels like a band-aid. Happy to be corrected.
Well
Documentation/security/snp-tdx-threat-model.rstputs it like this:
It is important to note
that this doesn’t imply that the host or VMM are intentionally malicious, but that there exists a security value in having a small CoCo VM TCB.and
While traditionally the host has unlimited access to guest data and can leverage this access to attack the guest, the CoCo systems mitigate such attacks by adding security features like guest data confidentiality and integrity protection.
now, when we are talking about "mitigation" it is indeed becoming a bit murky.
Quoted 5 lines
For me, a rule of thumb I came up with is that if the validation happens to also be helful for users e.g. to work around buggy devices, or maybe because we feel failing gracefully is nice because this will allow to later make use of this config and old drivers will fail but at least not panic, then it is good to include.
Why not do what USB does? Don't trust the device until AFTER
probe()succeeds? All of the needed checking should happen before then, as that is a "slow path" so lots of validation and the like can happen at that point.
Quoted 7 lines
After that, during the normal data paths, after the driver is bound, trust it all you want as attempting to validate every single packet is just going to be impossible.
thanks,
greg k-h
People do expect that data path validation at this point.
Signature · 1 line
MST
Greg Kroah-Hartman
maintainerRe: [PATCH v2 1/4] virtio-mem: validate device-reported block size
Quoted 60 lines · Michael S. Tsirkin
Quoted 59 lines · Greg Kroah-Hartman
Quoted 43 lines · Michael S. Tsirkin
Quoted 9 lines · David Hildenbrand (Arm)
Quoted 8 lines · Michael S. Tsirkin
Quoted 6 lines · David Hildenbrand (Arm)
Quoted 1 line
Or do we just always trust virtio mem devices explicitly?
It's hard for me to understand where we draw the line, really.
But maybe MST can clarify what we care about in virtio world where the hypervisor is fully in charge of the device,
Quoted 6 lines
Quoted 3 lines
Generally:
- The guest is expected to whitelist drivers (most drivers have not been audited).But even if you audited your driver, who makes sure that we consider all ways where the device could mess with us?
A lot of this is up to a correct setup. For example, make sure all filesystems are encrypted and refuse to mount unencrypted ones.
Quoted 4 lines
Something feels off here.
Handling selected out-of-spec scenarios like this feels like a band-aid. Happy to be corrected.
Well
Documentation/security/snp-tdx-threat-model.rstputs it like this:
It is important to note
that this doesn’t imply that the host or VMM are intentionally malicious, but that there exists a security value in having a small CoCo VM TCB.and
While traditionally the host has unlimited access to guest data and can leverage this access to attack the guest, the CoCo systems mitigate such attacks by adding security features like guest data confidentiality and integrity protection.
now, when we are talking about "mitigation" it is indeed becoming a bit murky.
Quoted 5 lines
For me, a rule of thumb I came up with is that if the validation happens to also be helful for users e.g. to work around buggy devices, or maybe because we feel failing gracefully is nice because this will allow to later make use of this config and old drivers will fail but at least not panic, then it is good to include.
Why not do what USB does? Don't trust the device until AFTER
probe()succeeds? All of the needed checking should happen before then, as that is a "slow path" so lots of validation and the like can happen at that point.After that, during the normal data paths, after the driver is bound, trust it all you want as attempting to validate every single packet is just going to be impossible.
Quoted 5 lines
Quoted 3 lines
thanks,
greg k-h
People do expect that data path validation at this point.
Ok, so you want this patch :)
And more, as you need to treat everything from the host as "untrusted", and it must be "verified". Much like the proposed Rust patches we keep slowly working on, which would make this much more obvious as to exactly what needs to be verified, and where it happens.
thanks,
greg k-h
David Hildenbrand (Arm)
maintainerRe: [PATCH v2 1/4] virtio-mem: validate device-reported block size
Quoted 12 lines · Greg Kroah-Hartman
Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · Greg Kroah-Hartman
Why not do what USB does? Don't trust the device until AFTER
probe()succeeds? All of the needed checking should happen before then, as that is a "slow path" so lots of validation and the like can happen at that point.After that, during the normal data paths, after the driver is bound, trust it all you want as attempting to validate every single packet is just going to be impossible.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
thanks,
greg k-h
People do expect that data path validation at this point.
Ok, so you want this patch :)
I fail to see the value of this patch given that there are plenty of other cases the device can mess with us.
But sure, let's check for some conditions if it makes us feel warm and fluffy as we audited a driver and it's now super safe, fine with me.
Signature · 3 lines
Cheers, David
Michael S. Tsirkin
maintainerRe: [PATCH v2 1/4] virtio-mem: validate device-reported block size
Quoted 19 lines · David Hildenbrand (Arm)
Quoted 18 lines · Greg Kroah-Hartman
Quoted 16 lines · Michael S. Tsirkin
Quoted 6 lines · Greg Kroah-Hartman
Why not do what USB does? Don't trust the device until AFTER
probe()succeeds? All of the needed checking should happen before then, as that is a "slow path" so lots of validation and the like can happen at that point.Quoted 7 lines
After that, during the normal data paths, after the driver is bound, trust it all you want as attempting to validate every single packet is just going to be impossible.
thanks,
greg k-h
People do expect that data path validation at this point.
Quoted 12 lines
Quoted 1 line
Ok, so you want this patch :)
I fail to see the value of this patch given that there are plenty of other cases the device can mess with us.
But sure, let's check for some conditions if it makes us feel warm and fluffy as we audited a driver and it's now super safe, fine with me.
Signature · 3 lines
Cheers, David
I merely made some generic comments since I was asked to clarify how virtio interacts with coco. As for the specific patch, it does not make me feel fluffy. It lacks motivation.
A broken device confuses the kernel with no way to exploit that. Shrug. So? Nothing to do with coco, apparently.
It's maybe reasonable as a debugging aid but if this is intended as such let's make it clear in the commit log.
Signature · 1 line
MST
Greg Kroah-Hartman
maintainerRe: [PATCH v2 1/4] virtio-mem: validate device-reported block size
In reply to David Hildenbrand (Arm)Quoted 15 lines · David Hildenbrand (Arm)
Quoted 14 lines · Greg Kroah-Hartman
Quoted 13 lines · Michael S. Tsirkin
Quoted 12 lines · Greg Kroah-Hartman
Why not do what USB does? Don't trust the device until AFTER
probe()succeeds? All of the needed checking should happen before then, as that is a "slow path" so lots of validation and the like can happen at that point.After that, during the normal data paths, after the driver is bound, trust it all you want as attempting to validate every single packet is just going to be impossible.
thanks,
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
greg k-h
People do expect that data path validation at this point.
Ok, so you want this patch :)
I fail to see the value of this patch given that there are plenty of other cases the device can mess with us.
How can the device mess with us?
Quoted 2 lines
But sure, let's check for some conditions if it makes us feel warm and fluffy as we audited a driver and it's now super safe, fine with me.
I'm all for the folly of "it's an audited driver!" claims, but you all need to decide either you do or you do not trust the device. Either way is fine with me.
If you don't trust it, great, take patches that fix that. If you do trust it, great, reject those types of patches.
But pick one please.
thanks,
greg k-h
David Hildenbrand (Arm)
maintainerRe: [PATCH v2 1/4] virtio-mem: validate device-reported block size
Quoted 9 lines · Greg Kroah-Hartman
Quoted 6 lines · David Hildenbrand (Arm)
Quoted 2 lines · Greg Kroah-Hartman
Ok, so you want this patch :)
I fail to see the value of this patch given that there are plenty of other cases the device can mess with us.
How can the device mess with us?
I raised some examples already, like lying about which memory chunks it makes available.
I guess it could also throw a random "requested_size" at us. It could make up a wrong physical address region. I assume there is plenty more we'd have to check.
Again, I'm not saying that this couldn't/shouldn't be done, but it requires some *real thought* about all possible things a device could do.
Quoted 7 lines
Quoted 3 lines
But sure, let's check for some conditions if it makes us feel warm and fluffy as we audited a driver and it's now super safe, fine with me.
I'm all for the folly of "it's an audited driver!" claims, but you all need to decide either you do or you do not trust the device. Either way is fine with me.
Well, exactly, that is what I am saying. I don't know what we care about. This patch here feels incomplete and that's what grinds my gears. It doesn't magically make us deal with malicious devices.
And I don't buy the story about "buggy virtio-mem devices that set block_size==0", which doesn't make any sense in any possible reality.
Quoted 5 lines
If you don't trust it, great, take patches that fix that. If you do trust it, great, reject those types of patches.
But pick one please.
Yes, I'd expect that we have general virtio guifance. I only co-maintain some virtio bits and have no idea about the expected trust model and when we would consider a devices trusted.
And what it would take to get there.
Signature · 3 lines
Cheers, David
Michael S. Tsirkin
maintainerRe: [PATCH v2 1/4] virtio-mem: validate device-reported block size
In reply to Greg Kroah-HartmanQuoted 63 lines · Greg Kroah-Hartman
Quoted 62 lines · Michael S. Tsirkin
Quoted 61 lines · Greg Kroah-Hartman
Quoted 43 lines · Michael S. Tsirkin
Quoted 9 lines · David Hildenbrand (Arm)
Quoted 8 lines · Michael S. Tsirkin
Quoted 6 lines · David Hildenbrand (Arm)
Quoted 1 line
Or do we just always trust virtio mem devices explicitly?
It's hard for me to understand where we draw the line, really.
But maybe MST can clarify what we care about in virtio world where the hypervisor is fully in charge of the device,
Quoted 6 lines
Quoted 3 lines
Generally:
- The guest is expected to whitelist drivers (most drivers have not been audited).But even if you audited your driver, who makes sure that we consider all ways where the device could mess with us?
A lot of this is up to a correct setup. For example, make sure all filesystems are encrypted and refuse to mount unencrypted ones.
Quoted 4 lines
Something feels off here.
Handling selected out-of-spec scenarios like this feels like a band-aid. Happy to be corrected.
Well
Documentation/security/snp-tdx-threat-model.rstputs it like this:
It is important to note
that this doesn’t imply that the host or VMM are intentionally malicious, but that there exists a security value in having a small CoCo VM TCB.and
While traditionally the host has unlimited access to guest data and can leverage this access to attack the guest, the CoCo systems mitigate such attacks by adding security features like guest data confidentiality and integrity protection.
now, when we are talking about "mitigation" it is indeed becoming a bit murky.
Quoted 5 lines
For me, a rule of thumb I came up with is that if the validation happens to also be helful for users e.g. to work around buggy devices, or maybe because we feel failing gracefully is nice because this will allow to later make use of this config and old drivers will fail but at least not panic, then it is good to include.
Why not do what USB does? Don't trust the device until AFTER
probe()succeeds? All of the needed checking should happen before then, as that is a "slow path" so lots of validation and the like can happen at that point.After that, during the normal data paths, after the driver is bound, trust it all you want as attempting to validate every single packet is just going to be impossible.
thanks,
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
greg k-h
People do expect that data path validation at this point.
Ok, so you want this patch :)
And more, as you need to treat everything from the host as "untrusted", and it must be "verified".
Well. First it's not me) Second it's only specific configurations - for example there's no short term plan to validate filesystem code, people are expected to rely on encryption. The reasons have more to do with the available manpower than anything else.
Quoted 7 lines
Much like the proposed Rust patches we keep
slowly working on, which would make this much more obvious as to exactly what needs to be verified, and where it happens.thanks,
greg k-h
Or much like networking, except it's an old robust codebase.
Signature · 1 line
MST
Greg Kroah-Hartman
maintainerRe: [PATCH v2 1/4] virtio-mem: validate device-reported block size
Quoted 70 lines · Michael S. Tsirkin
Quoted 69 lines · Greg Kroah-Hartman
Quoted 60 lines · Michael S. Tsirkin
Quoted 59 lines · Greg Kroah-Hartman
Quoted 43 lines · Michael S. Tsirkin
Quoted 9 lines · David Hildenbrand (Arm)
Quoted 8 lines · Michael S. Tsirkin
Quoted 6 lines · David Hildenbrand (Arm)
Quoted 1 line
Or do we just always trust virtio mem devices explicitly?
It's hard for me to understand where we draw the line, really.
But maybe MST can clarify what we care about in virtio world where the hypervisor is fully in charge of the device,
Quoted 6 lines
Quoted 3 lines
Generally:
- The guest is expected to whitelist drivers (most drivers have not been audited).But even if you audited your driver, who makes sure that we consider all ways where the device could mess with us?
A lot of this is up to a correct setup. For example, make sure all filesystems are encrypted and refuse to mount unencrypted ones.
Quoted 4 lines
Something feels off here.
Handling selected out-of-spec scenarios like this feels like a band-aid. Happy to be corrected.
Well
Documentation/security/snp-tdx-threat-model.rstputs it like this:
It is important to note
that this doesn’t imply that the host or VMM are intentionally malicious, but that there exists a security value in having a small CoCo VM TCB.and
While traditionally the host has unlimited access to guest data and can leverage this access to attack the guest, the CoCo systems mitigate such attacks by adding security features like guest data confidentiality and integrity protection.
now, when we are talking about "mitigation" it is indeed becoming a bit murky.
Quoted 5 lines
For me, a rule of thumb I came up with is that if the validation happens to also be helful for users e.g. to work around buggy devices, or maybe because we feel failing gracefully is nice because this will allow to later make use of this config and old drivers will fail but at least not panic, then it is good to include.
Why not do what USB does? Don't trust the device until AFTER
probe()succeeds? All of the needed checking should happen before then, as that is a "slow path" so lots of validation and the like can happen at that point.After that, during the normal data paths, after the driver is bound, trust it all you want as attempting to validate every single packet is just going to be impossible.
Quoted 5 lines
Quoted 3 lines
thanks,
greg k-h
People do expect that data path validation at this point.
Ok, so you want this patch :)
Quoted 7 lines
Quoted 2 lines
And more, as you need to treat everything from the host as "untrusted", and it must be "verified".
Well. First it's not me) Second it's only specific configurations - for example there's no short term plan to validate filesystem code, people are expected to rely on encryption. The reasons have more to do with the available manpower than anything else.
Sure, but again, for subsystems, you have to define your threat model as the LLMs are churning against the code base and coming up with lots of crazy ideas if a device should or should not be trusted and spitting out patches and reports like the ones that are in the first few patches of this series.
So please, pick a model, let's document it, and go with that. I am getting directly conflicting responses here.
thanks,
greg k-h
Michael S. Tsirkin
maintainerRe: [PATCH v2 1/4] virtio-mem: validate device-reported block size
Quoted 85 lines · Greg Kroah-Hartman
Quoted 70 lines · Michael S. Tsirkin
Quoted 69 lines · Greg Kroah-Hartman
Quoted 60 lines · Michael S. Tsirkin
Quoted 59 lines · Greg Kroah-Hartman
Quoted 43 lines · Michael S. Tsirkin
Quoted 9 lines · David Hildenbrand (Arm)
Quoted 8 lines · Michael S. Tsirkin
Quoted 6 lines · David Hildenbrand (Arm)
Quoted 1 line
Or do we just always trust virtio mem devices explicitly?
It's hard for me to understand where we draw the line, really.
But maybe MST can clarify what we care about in virtio world where the hypervisor is fully in charge of the device,
Quoted 6 lines
Quoted 3 lines
Generally:
- The guest is expected to whitelist drivers (most drivers have not been audited).But even if you audited your driver, who makes sure that we consider all ways where the device could mess with us?
A lot of this is up to a correct setup. For example, make sure all filesystems are encrypted and refuse to mount unencrypted ones.
Quoted 4 lines
Something feels off here.
Handling selected out-of-spec scenarios like this feels like a band-aid. Happy to be corrected.
Well
Documentation/security/snp-tdx-threat-model.rstputs it like this:
It is important to note
that this doesn’t imply that the host or VMM are intentionally malicious, but that there exists a security value in having a small CoCo VM TCB.and
While traditionally the host has unlimited access to guest data and can leverage this access to attack the guest, the CoCo systems mitigate such attacks by adding security features like guest data confidentiality and integrity protection.
now, when we are talking about "mitigation" it is indeed becoming a bit murky.
Quoted 5 lines
For me, a rule of thumb I came up with is that if the validation happens to also be helful for users e.g. to work around buggy devices, or maybe because we feel failing gracefully is nice because this will allow to later make use of this config and old drivers will fail but at least not panic, then it is good to include.
Why not do what USB does? Don't trust the device until AFTER
probe()succeeds? All of the needed checking should happen before then, as that is a "slow path" so lots of validation and the like can happen at that point.After that, during the normal data paths, after the driver is bound, trust it all you want as attempting to validate every single packet is just going to be impossible.
Quoted 5 lines
Quoted 3 lines
thanks,
greg k-h
People do expect that data path validation at this point.
Ok, so you want this patch :)
Quoted 7 lines
Quoted 2 lines
And more, as you need to treat everything from the host as "untrusted", and it must be "verified".
Well. First it's not me) Second it's only specific configurations - for example there's no short term plan to validate filesystem code, people are expected to rely on encryption. The reasons have more to do with the available manpower than anything else.
Sure, but again, for subsystems, you have to define your threat model as the LLMs are churning against the code base and coming up with lots of crazy ideas if a device should or should not be trusted and spitting out patches and reports like the ones that are in the first few patches of this series.
Quoted 6 lines
So please, pick a model, let's document it, and go with that. I am getting directly conflicting responses here.
thanks,
greg k-h
Supposed to be this one:Documentation/security/snp-tdx-threat-model.rst
what is missing?
Signature · 1 line
MST
Greg Kroah-Hartman
maintainerRe: [PATCH v2 1/4] virtio-mem: validate device-reported block size
Quoted 89 lines · Michael S. Tsirkin
Quoted 88 lines · Greg Kroah-Hartman
Quoted 70 lines · Michael S. Tsirkin
Quoted 69 lines · Greg Kroah-Hartman
Quoted 60 lines · Michael S. Tsirkin
Quoted 59 lines · Greg Kroah-Hartman
Quoted 43 lines · Michael S. Tsirkin
Quoted 9 lines · David Hildenbrand (Arm)
Quoted 8 lines · Michael S. Tsirkin
Quoted 6 lines · David Hildenbrand (Arm)
Quoted 1 line
Or do we just always trust virtio mem devices explicitly?
It's hard for me to understand where we draw the line, really.
But maybe MST can clarify what we care about in virtio world where the hypervisor is fully in charge of the device,
Quoted 6 lines
Quoted 3 lines
Generally:
- The guest is expected to whitelist drivers (most drivers have not been audited).But even if you audited your driver, who makes sure that we consider all ways where the device could mess with us?
A lot of this is up to a correct setup. For example, make sure all filesystems are encrypted and refuse to mount unencrypted ones.
Quoted 4 lines
Something feels off here.
Handling selected out-of-spec scenarios like this feels like a band-aid. Happy to be corrected.
Well
Documentation/security/snp-tdx-threat-model.rstputs it like this:
It is important to note
that this doesn’t imply that the host or VMM are intentionally malicious, but that there exists a security value in having a small CoCo VM TCB.and
While traditionally the host has unlimited access to guest data and can leverage this access to attack the guest, the CoCo systems mitigate such attacks by adding security features like guest data confidentiality and integrity protection.
now, when we are talking about "mitigation" it is indeed becoming a bit murky.
Quoted 5 lines
For me, a rule of thumb I came up with is that if the validation happens to also be helful for users e.g. to work around buggy devices, or maybe because we feel failing gracefully is nice because this will allow to later make use of this config and old drivers will fail but at least not panic, then it is good to include.
Why not do what USB does? Don't trust the device until AFTER
probe()succeeds? All of the needed checking should happen before then, as that is a "slow path" so lots of validation and the like can happen at that point.After that, during the normal data paths, after the driver is bound, trust it all you want as attempting to validate every single packet is just going to be impossible.
Quoted 5 lines
Quoted 3 lines
thanks,
greg k-h
People do expect that data path validation at this point.
Ok, so you want this patch :)
Quoted 7 lines
Quoted 2 lines
And more, as you need to treat everything from the host as "untrusted", and it must be "verified".
Well. First it's not me) Second it's only specific configurations - for example there's no short term plan to validate filesystem code, people are expected to rely on encryption. The reasons have more to do with the available manpower than anything else.
Sure, but again, for subsystems, you have to define your threat model as the LLMs are churning against the code base and coming up with lots of crazy ideas if a device should or should not be trusted and spitting out patches and reports like the ones that are in the first few patches of this series.
So please, pick a model, let's document it, and go with that. I am getting directly conflicting responses here.
Quoted 8 lines
Quoted 3 lines
thanks,
greg k-h
Supposed to be this one:
Documentation/security/snp-tdx-threat-model.rstwhat is missing?
A policy decision that needs to be made. All that document does is describe a bunch of different "threats" yet does not decide what to do about them at all from what I can tell.
And that's just for one subset of the CoC world, right? Is that something that all virtio drivers need/want to care about?
So I don't see a real answer to the "does Linux trust the host to give you good data or not" question in that file, am I missing it?
thanks,
greg k-h
Michael S. Tsirkin
maintainerRe: [PATCH v2 1/4] virtio-mem: validate device-reported block size
Quoted 94 lines · Greg Kroah-Hartman
Quoted 93 lines · Michael S. Tsirkin
Quoted 91 lines · Greg Kroah-Hartman
Quoted 70 lines · Michael S. Tsirkin
Quoted 69 lines · Greg Kroah-Hartman
Quoted 60 lines · Michael S. Tsirkin
Quoted 59 lines · Greg Kroah-Hartman
Quoted 43 lines · Michael S. Tsirkin
Quoted 9 lines · David Hildenbrand (Arm)
Quoted 8 lines · Michael S. Tsirkin
Quoted 6 lines · David Hildenbrand (Arm)
Quoted 1 line
Or do we just always trust virtio mem devices explicitly?
It's hard for me to understand where we draw the line, really.
But maybe MST can clarify what we care about in virtio world where the hypervisor is fully in charge of the device,
Quoted 6 lines
Quoted 3 lines
Generally:
- The guest is expected to whitelist drivers (most drivers have not been audited).But even if you audited your driver, who makes sure that we consider all ways where the device could mess with us?
A lot of this is up to a correct setup. For example, make sure all filesystems are encrypted and refuse to mount unencrypted ones.
Quoted 4 lines
Something feels off here.
Handling selected out-of-spec scenarios like this feels like a band-aid. Happy to be corrected.
Well
Documentation/security/snp-tdx-threat-model.rstputs it like this:
It is important to note
that this doesn’t imply that the host or VMM are intentionally malicious, but that there exists a security value in having a small CoCo VM TCB.and
While traditionally the host has unlimited access to guest data and can leverage this access to attack the guest, the CoCo systems mitigate such attacks by adding security features like guest data confidentiality and integrity protection.
now, when we are talking about "mitigation" it is indeed becoming a bit murky.
Quoted 5 lines
For me, a rule of thumb I came up with is that if the validation happens to also be helful for users e.g. to work around buggy devices, or maybe because we feel failing gracefully is nice because this will allow to later make use of this config and old drivers will fail but at least not panic, then it is good to include.
Why not do what USB does? Don't trust the device until AFTER
probe()succeeds? All of the needed checking should happen before then, as that is a "slow path" so lots of validation and the like can happen at that point.After that, during the normal data paths, after the driver is bound, trust it all you want as attempting to validate every single packet is just going to be impossible.
Quoted 5 lines
Quoted 3 lines
thanks,
greg k-h
People do expect that data path validation at this point.
Ok, so you want this patch :)
Quoted 7 lines
Quoted 2 lines
And more, as you need to treat everything from the host as "untrusted", and it must be "verified".
Well. First it's not me) Second it's only specific configurations - for example there's no short term plan to validate filesystem code, people are expected to rely on encryption. The reasons have more to do with the available manpower than anything else.
Sure, but again, for subsystems, you have to define your threat model as the LLMs are churning against the code base and coming up with lots of crazy ideas if a device should or should not be trusted and spitting out patches and reports like the ones that are in the first few patches of this series.
So please, pick a model, let's document it, and go with that. I am getting directly conflicting responses here.
thanks,
greg k-h
Quoted 8 lines
Quoted 4 lines
Supposed to be this one:
Documentation/security/snp-tdx-threat-model.rstwhat is missing?
A policy decision that needs to be made. All that document does is describe a bunch of different "threats" yet does not decide what to do about them at all from what I can tell.
That would be this section I think:
The **Linux kernel CoCo VM security objectives** can be summarized as follows:
it does, indeed, not go into detail about how to interact, safely, with untrusted entities. Does it really need to be spelled out?
Quoted 2 lines
And that's just for one subset of the CoC world, right? Is that something that all virtio drivers need/want to care about?
What is missing, and what you seem to be asking for, is an opinionated stance on which drivers we care about in this world?
True.
coco guys tried to annotate drivers at some point to do exactly that. this was rejected upstream from the position that this is not different from handling buggy hardware, and just to fix all drivers. so it's up to users, and I guess for virtio the answer is yes with some exceptions because we don't have a better answer right now.
Quoted 6 lines
So I don't see a real answer to the "does Linux trust the host to give you good data or not" question in that file, am I missing it?
thanks,
greg k-h
This? Note the last sentence.
The **Linux CoCo VM attack surface** is any interface exposed from a CoCo guest Linux kernel towards an untrusted host that is not covered by the CoCo technology SW/HW protection. This includes any possible side-channels, as well as transient execution side channels. Examples of explicit (not side-channel) interfaces include accesses to port I/O, MMIO and DMA interfaces, access to PCI configuration space, VMM-specific hypercalls (towards Host-side VMM), access to shared memory pages, interrupts allowed to be injected into the guest kernel by the host, as well as CoCo technology-specific hypercalls, if present. Additionally, the host in a CoCo system typically controls the process of creating a CoCo
guest: it has a method to load into a guest the firmware and bootloader images, the kernel image together with the kernel command line. All of this data should also be considered untrusted until its integrity and authenticity is established via attestation.
Greg Kroah-Hartman
maintainerRe: [PATCH v2 1/4] virtio-mem: validate device-reported block size
Quoted 104 lines · Michael S. Tsirkin
Quoted 94 lines · Greg Kroah-Hartman
Quoted 93 lines · Michael S. Tsirkin
Quoted 91 lines · Greg Kroah-Hartman
Quoted 70 lines · Michael S. Tsirkin
Quoted 69 lines · Greg Kroah-Hartman
Quoted 60 lines · Michael S. Tsirkin
Quoted 59 lines · Greg Kroah-Hartman
Quoted 43 lines · Michael S. Tsirkin
Quoted 9 lines · David Hildenbrand (Arm)
Quoted 8 lines · Michael S. Tsirkin
Quoted 6 lines · David Hildenbrand (Arm)
Quoted 1 line
Or do we just always trust virtio mem devices explicitly?
It's hard for me to understand where we draw the line, really.
But maybe MST can clarify what we care about in virtio world where the hypervisor is fully in charge of the device,
Quoted 6 lines
Quoted 3 lines
Generally:
- The guest is expected to whitelist drivers (most drivers have not been audited).But even if you audited your driver, who makes sure that we consider all ways where the device could mess with us?
A lot of this is up to a correct setup. For example, make sure all filesystems are encrypted and refuse to mount unencrypted ones.
Quoted 4 lines
Something feels off here.
Handling selected out-of-spec scenarios like this feels like a band-aid. Happy to be corrected.
Well
Documentation/security/snp-tdx-threat-model.rstputs it like this:
It is important to note
that this doesn’t imply that the host or VMM are intentionally malicious, but that there exists a security value in having a small CoCo VM TCB.and
While traditionally the host has unlimited access to guest data and can leverage this access to attack the guest, the CoCo systems mitigate such attacks by adding security features like guest data confidentiality and integrity protection.
now, when we are talking about "mitigation" it is indeed becoming a bit murky.
Quoted 5 lines
For me, a rule of thumb I came up with is that if the validation happens to also be helful for users e.g. to work around buggy devices, or maybe because we feel failing gracefully is nice because this will allow to later make use of this config and old drivers will fail but at least not panic, then it is good to include.
Why not do what USB does? Don't trust the device until AFTER
probe()succeeds? All of the needed checking should happen before then, as that is a "slow path" so lots of validation and the like can happen at that point.After that, during the normal data paths, after the driver is bound, trust it all you want as attempting to validate every single packet is just going to be impossible.
Quoted 5 lines
Quoted 3 lines
thanks,
greg k-h
People do expect that data path validation at this point.
Ok, so you want this patch :)
Quoted 7 lines
Quoted 2 lines
And more, as you need to treat everything from the host as "untrusted", and it must be "verified".
Well. First it's not me) Second it's only specific configurations - for example there's no short term plan to validate filesystem code, people are expected to rely on encryption. The reasons have more to do with the available manpower than anything else.
Sure, but again, for subsystems, you have to define your threat model as the LLMs are churning against the code base and coming up with lots of crazy ideas if a device should or should not be trusted and spitting out patches and reports like the ones that are in the first few patches of this series.
So please, pick a model, let's document it, and go with that. I am getting directly conflicting responses here.
thanks,
greg k-h
Quoted 8 lines
Quoted 4 lines
Supposed to be this one:
Documentation/security/snp-tdx-threat-model.rstwhat is missing?
A policy decision that needs to be made. All that document does is describe a bunch of different "threats" yet does not decide what to do about them at all from what I can tell.
Quoted 6 lines
That would be this section I think:
The **Linux kernel CoCo VM security objectives** can be summarized as follows:
it does, indeed, not go into detail about how to interact, safely, with untrusted entities. Does it really need to be spelled out?
Seems like it as I didn't figure it out at all :)
Quoted 6 lines
Quoted 2 lines
And that's just for one subset of the CoC world, right? Is that something that all virtio drivers need/want to care about?
What is missing, and what you seem to be asking for, is an opinionated stance on which drivers we care about in this world?
True.
Yes.
Quoted 5 lines
coco guys tried to annotate drivers at some point to do exactly that. this was rejected upstream from the position that this is not different from handling buggy hardware, and just to fix all drivers. so it's up to users, and I guess for virtio the answer is yes with some exceptions because we don't have a better answer right now.
Ok, so back to the original question here:
Quoted 9 lines
Quoted 6 lines
So I don't see a real answer to the "does Linux trust the host to give you good data or not" question in that file, am I missing it?
thanks,
greg k-h
This? Note the last sentence.
Quoted 14 lines
The **Linux CoCo VM attack surface** is any interface exposed from a CoCo guest Linux kernel towards an untrusted host that is not covered by the CoCo technology SW/HW protection. This includes any possible side-channels, as well as transient execution side channels. Examples of explicit (not side-channel) interfaces include accesses to port I/O, MMIO and DMA interfaces, access to PCI configuration space, VMM-specific hypercalls (towards Host-side VMM), access to shared memory pages, interrupts allowed to be injected into the guest kernel by the host, as well as CoCo technology-specific hypercalls, if present. Additionally, the host in a CoCo system typically controls the process of creating a CoCo
guest: it has a method to load into a guest the firmware and bootloader images, the kernel image together with the kernel command line. All of this data should also be considered untrusted until its integrity and authenticity is established via attestation.
Great, so you are saying that we need to fix any bug found where a host could be sending "bad" data over the virtio path before, and after, the driver is bound to the device. That's a solid answer, and let's let the LLMs run with that!
Which also implies that the first 3 patches here are acceptable, right? :)
thanks,
greg k-h
RE: [PATCH v2 1/4] virtio-mem: validate device-reported block size
From: Greg Kroah-Hartman <[email protected]> Sent: Friday, July 17, 2026 7:31 AM
Quoted 155 lines · Michael S. Tsirkin
Quoted 104 lines · Greg Kroah-Hartman
Quoted 94 lines · Michael S. Tsirkin
Quoted 93 lines · Greg Kroah-Hartman
Quoted 91 lines · Michael S. Tsirkin
Quoted 70 lines · Greg Kroah-Hartman
Quoted 69 lines · Michael S. Tsirkin
Quoted 60 lines · Greg Kroah-Hartman
Quoted 59 lines · Michael S. Tsirkin
Quoted 43 lines · David Hildenbrand (Arm)
Quoted 9 lines · Michael S. Tsirkin
Quoted 8 lines · David Hildenbrand (Arm)
Quoted 6 lines
Or do we just always trust virtio mem devices explicitly?
It's hard for me to understand where we draw the line, really.
But maybe MST can clarify what we care about in virtio world where the
hypervisor is fully in charge of the device,Quoted 6 lines
Quoted 3 lines
Generally:
- The guest is expected to whitelist drivers (most drivers have not been audited).But even if you audited your driver, who makes sure that we consider all ways where the device could mess with us?
A lot of this is up to a correct setup. For example, make sure all filesystems are encrypted and refuse to mount unencrypted ones.
Quoted 4 lines
Something feels off here.
Handling selected out-of-spec scenarios like this feels like a band-aid. Happy to be corrected.
Well
Documentation/security/snp-tdx-threat-model.rstputs it like this:
It is important to note
that this doesn’t imply that the host or VMM are intentionally malicious, but that there exists a security value in having a small CoCo VM TCB.and
While traditionally the host has unlimited access to guest data and can leverage this access to attack the guest, the CoCo systems mitigate such attacks by adding security features like guest data confidentiality and integrity protection.
now, when we are talking about "mitigation" it is indeed becoming a bit murky.
Quoted 5 lines
For me, a rule of thumb I came up with is that if the validation happens to also be helful for users e.g. to work around buggy devices, or maybe because we feel failing gracefully is nice because this will allow to later make use of this config and old drivers will fail but at least not panic, then it is good to include.
Why not do what USB does? Don't trust the device until AFTER
probe()succeeds? All of the needed checking should happen before then, as that is a "slow path" so lots of validation and the like can happen at that point.After that, during the normal data paths, after the driver is bound, trust it all you want as attempting to validate every single packet is just going to be impossible.
Quoted 5 lines
Quoted 3 lines
thanks,
greg k-h
People do expect that data path validation at this point.
Ok, so you want this patch :)
Quoted 7 lines
Quoted 2 lines
And more, as you need to treat everything from the host as "untrusted", and it must be "verified".
Well. First it's not me) Second it's only specific configurations - for example there's no short term plan to validate filesystem code, people are expected to rely on encryption. The reasons have more to do with the available manpower than anything else.
Sure, but again, for subsystems, you have to define your threat model as the LLMs are churning against the code base and coming up with lots of crazy ideas if a device should or should not be trusted and spitting out patches and reports like the ones that are in the first few patches of this series.
So please, pick a model, let's document it, and go with that. I am getting directly conflicting responses here.
thanks,
greg k-h
Quoted 8 lines
Quoted 4 lines
Supposed to be this one:
Documentation/security/snp-tdx-threat-model.rstwhat is missing?
A policy decision that needs to be made. All that document does is describe a bunch of different "threats" yet does not decide what to do about them at all from what I can tell.
Quoted 6 lines
That would be this section I think:
The **Linux kernel CoCo VM security objectives** can be summarized as follows:
it does, indeed, not go into detail about how to interact, safely, with untrusted entities. Does it really need to be spelled out?
Seems like it as I didn't figure it out at all :)
Quoted 6 lines
Quoted 2 lines
And that's just for one subset of the CoC world, right? Is that something that all virtio drivers need/want to care about?
What is missing, and what you seem to be asking for, is an opinionated stance on which drivers we care about in this world?
True.Yes.
Quoted 5 lines
coco guys tried to annotate drivers at some point to do exactly that. this was rejected upstream from the position that this is not different from handling buggy hardware, and just to fix all drivers. so it's up to users, and I guess for virtio the answer is yes with some exceptions because we don't have a better answer right now.
Ok, so back to the original question here:
Quoted 9 lines
Quoted 6 lines
So I don't see a real answer to the "does Linux trust the host to give you good data or not" question in that file, am I missing it?
thanks,
greg k-h
This? Note the last sentence.
Quoted 14 lines
The **Linux CoCo VM attack surface** is any interface exposed from a CoCo guest Linux kernel towards an untrusted host that is not covered by the CoCo technology SW/HW protection. This includes any possible side-channels, as well as transient execution side channels. Examples of explicit (not side-channel) interfaces include accesses to port I/O, MMIO and DMA interfaces, access to PCI configuration space, VMM-specific hypercalls (towards Host-side VMM), access to shared memory pages, interrupts allowed to be injected into the guest kernel by the host, as well as CoCo technology-specific hypercalls, if present. Additionally, the host in a CoCo system typically controls the process of creating a CoCo
guest: it has a method to load into a guest the firmware and bootloader images, the kernel image together with the kernel command line. All of this data should also be considered untrusted until its integrity and authenticity is established via attestation.
Quoted 5 lines
Great, so you are saying that we need to fix any bug found where a host could be sending "bad" data over the virtio path before, and after, the driver is bound to the device. That's a solid answer, and let's let the LLMs run with that!
FWIW, Hyper-V VMBus drivers in Linux use this same threat model, with the same conclusions about data validation. The details are in Documentation/virt/hyperv/coco.rst. See the Section entitled " Guest communication with Hyper-V". Let me know if you've come across potential data leaks or corruption modalities in the virtio code that might also be applicable to the VMBus drivers, that aren't already mentioned in that documentation.
Michael
Michael S. Tsirkin
maintainerRe: [PATCH v2 1/4] virtio-mem: validate device-reported block size
In reply to Greg Kroah-HartmanQuoted 160 lines · Greg Kroah-Hartman
Quoted 104 lines · Michael S. Tsirkin
Quoted 94 lines · Greg Kroah-Hartman
Quoted 93 lines · Michael S. Tsirkin
Quoted 91 lines · Greg Kroah-Hartman
Quoted 70 lines · Michael S. Tsirkin
Quoted 69 lines · Greg Kroah-Hartman
Quoted 60 lines · Michael S. Tsirkin
Quoted 59 lines · Greg Kroah-Hartman
Quoted 43 lines · Michael S. Tsirkin
Quoted 9 lines · David Hildenbrand (Arm)
Quoted 8 lines · Michael S. Tsirkin
Quoted 6 lines · David Hildenbrand (Arm)
Or do we just always trust virtio mem devices explicitly?
It's hard for me to understand where we draw the line, really.
But maybe MST can clarify what we care about in virtio world where the
hypervisor is fully in charge of the device,Quoted 6 lines
Quoted 3 lines
Generally:
- The guest is expected to whitelist drivers (most drivers have not been audited).But even if you audited your driver, who makes sure that we consider all ways where the device could mess with us?
A lot of this is up to a correct setup. For example, make sure all filesystems are encrypted and refuse to mount unencrypted ones.
Quoted 4 lines
Something feels off here.
Handling selected out-of-spec scenarios like this feels like a band-aid. Happy to be corrected.
Well
Documentation/security/snp-tdx-threat-model.rstputs it like this:
It is important to note
that this doesn’t imply that the host or VMM are intentionally malicious, but that there exists a security value in having a small CoCo VM TCB.and
While traditionally the host has unlimited access to guest data and can leverage this access to attack the guest, the CoCo systems mitigate such attacks by adding security features like guest data confidentiality and integrity protection.
now, when we are talking about "mitigation" it is indeed becoming a bit murky.
Quoted 5 lines
For me, a rule of thumb I came up with is that if the validation happens to also be helful for users e.g. to work around buggy devices, or maybe because we feel failing gracefully is nice because this will allow to later make use of this config and old drivers will fail but at least not panic, then it is good to include.
Why not do what USB does? Don't trust the device until AFTER
probe()succeeds? All of the needed checking should happen before then, as that is a "slow path" so lots of validation and the like can happen at that point.After that, during the normal data paths, after the driver is bound, trust it all you want as attempting to validate every single packet is just going to be impossible.
Quoted 5 lines
Quoted 3 lines
thanks,
greg k-h
People do expect that data path validation at this point.
Ok, so you want this patch :)
Quoted 7 lines
Quoted 2 lines
And more, as you need to treat everything from the host as "untrusted", and it must be "verified".
Well. First it's not me) Second it's only specific configurations - for example there's no short term plan to validate filesystem code, people are expected to rely on encryption. The reasons have more to do with the available manpower than anything else.
Sure, but again, for subsystems, you have to define your threat model as the LLMs are churning against the code base and coming up with lots of crazy ideas if a device should or should not be trusted and spitting out patches and reports like the ones that are in the first few patches of this series.
So please, pick a model, let's document it, and go with that. I am getting directly conflicting responses here.
thanks,
greg k-h
Quoted 8 lines
Quoted 4 lines
Supposed to be this one:
Documentation/security/snp-tdx-threat-model.rstwhat is missing?
A policy decision that needs to be made. All that document does is describe a bunch of different "threats" yet does not decide what to do about them at all from what I can tell.
Quoted 6 lines
That would be this section I think:
The **Linux kernel CoCo VM security objectives** can be summarized as follows:
it does, indeed, not go into detail about how to interact, safely, with untrusted entities. Does it really need to be spelled out?
Seems like it as I didn't figure it out at all :)
Quoted 6 lines
Quoted 2 lines
And that's just for one subset of the CoC world, right? Is that something that all virtio drivers need/want to care about?
What is missing, and what you seem to be asking for, is an opinionated stance on which drivers we care about in this world?
True.Yes.
Quoted 5 lines
coco guys tried to annotate drivers at some point to do exactly that. this was rejected upstream from the position that this is not different from handling buggy hardware, and just to fix all drivers. so it's up to users, and I guess for virtio the answer is yes with some exceptions because we don't have a better answer right now.
Ok, so back to the original question here:
Quoted 9 lines
Quoted 6 lines
So I don't see a real answer to the "does Linux trust the host to give you good data or not" question in that file, am I missing it?
thanks,
greg k-h
This? Note the last sentence.
Quoted 14 lines
The **Linux CoCo VM attack surface** is any interface exposed from a CoCo guest Linux kernel towards an untrusted host that is not covered by the CoCo technology SW/HW protection. This includes any possible side-channels, as well as transient execution side channels. Examples of explicit (not side-channel) interfaces include accesses to port I/O, MMIO and DMA interfaces, access to PCI configuration space, VMM-specific hypercalls (towards Host-side VMM), access to shared memory pages, interrupts allowed to be injected into the guest kernel by the host, as well as CoCo technology-specific hypercalls, if present. Additionally, the host in a CoCo system typically controls the process of creating a CoCo
guest: it has a method to load into a guest the firmware and bootloader images, the kernel image together with the kernel command line. All of this data should also be considered untrusted until its integrity and authenticity is established via attestation.Great, so you are saying that we need to fix any bug found where a host could be sending "bad" data over the virtio path before, and after, the driver is bound to the device. That's a solid answer, and let's let the LLMs run with that!
Quoted 6 lines
Which also implies that the first 3 patches here are acceptable, right? :)
thanks,
greg k-h
The 1st patch has nothing to do with coco. Bad values it checks do not lead to any information leak. I'm fine with it as such but I would like the commit log to make that clearer.
Signature · 1 line
MST
Michael S. Tsirkin
maintainerRe: [PATCH v2 1/4] virtio-mem: validate device-reported block size
Quoted 164 lines · Michael S. Tsirkin
Quoted 163 lines · Greg Kroah-Hartman
Quoted 104 lines · Michael S. Tsirkin
Quoted 94 lines · Greg Kroah-Hartman
Quoted 93 lines · Michael S. Tsirkin
Quoted 91 lines · Greg Kroah-Hartman
Quoted 70 lines · Michael S. Tsirkin
Quoted 69 lines · Greg Kroah-Hartman
Quoted 60 lines · Michael S. Tsirkin
Quoted 59 lines · Greg Kroah-Hartman
Quoted 43 lines · Michael S. Tsirkin
Quoted 9 lines · David Hildenbrand (Arm)
Quoted 8 lines · Michael S. Tsirkin
On Thu, Jul 16, 2026 at 05:59:05PM +0200, David Hildenbrand (Arm) wrote:
Or do we just always trust virtio mem devices explicitly?It's hard for me to understand where we draw the line, really.
But maybe MST can clarify what we care about in virtio world where the
hypervisor is fully in charge of the device,Quoted 6 lines
Quoted 3 lines
Generally:
- The guest is expected to whitelist drivers (most drivers have not
been audited).But even if you audited your driver, who makes sure that we consider all ways where the device could mess with us?
A lot of this is up to a correct setup. For example, make sure all filesystems are encrypted and refuse to mount unencrypted ones.
Quoted 4 lines
Something feels off here.
Handling selected out-of-spec scenarios like this feels like a band-aid. Happy to be corrected.
Well
Documentation/security/snp-tdx-threat-model.rstputs it like this:
It is important to note
that this doesn’t imply that the host or VMM are intentionally malicious, but that there exists a security value in having a small CoCo VM TCB.and
While traditionally the host has unlimited access to guest data and can leverage this access to attack the guest, the CoCo systems mitigate such attacks by adding security features like guest data confidentiality and integrity protection.
now, when we are talking about "mitigation" it is indeed becoming a bit murky.
Quoted 5 lines
For me, a rule of thumb I came up with is that if the validation happens to also be helful for users e.g. to work around buggy devices, or maybe because we feel failing gracefully is nice because this will allow to later make use of this config and old drivers will fail but at least not panic, then it is good to include.
Why not do what USB does? Don't trust the device until AFTER
probe()succeeds? All of the needed checking should happen before then, as that is a "slow path" so lots of validation and the like can happen at that point.After that, during the normal data paths, after the driver is bound, trust it all you want as attempting to validate every single packet is just going to be impossible.
Quoted 5 lines
Quoted 3 lines
thanks,
greg k-h
People do expect that data path validation at this point.
Ok, so you want this patch :)
Quoted 7 lines
Quoted 2 lines
And more, as you need to treat everything from the host as "untrusted", and it must be "verified".
Well. First it's not me) Second it's only specific configurations - for example there's no short term plan to validate filesystem code, people are expected to rely on encryption. The reasons have more to do with the available manpower than anything else.
Sure, but again, for subsystems, you have to define your threat model as the LLMs are churning against the code base and coming up with lots of crazy ideas if a device should or should not be trusted and spitting out patches and reports like the ones that are in the first few patches of this series.
So please, pick a model, let's document it, and go with that. I am getting directly conflicting responses here.
thanks,
greg k-h
Quoted 8 lines
Quoted 4 lines
Supposed to be this one:
Documentation/security/snp-tdx-threat-model.rstwhat is missing?
A policy decision that needs to be made. All that document does is describe a bunch of different "threats" yet does not decide what to do about them at all from what I can tell.
Quoted 6 lines
That would be this section I think:
The **Linux kernel CoCo VM security objectives** can be summarized as follows:
it does, indeed, not go into detail about how to interact, safely, with untrusted entities. Does it really need to be spelled out?
Seems like it as I didn't figure it out at all :)
Quoted 6 lines
Quoted 2 lines
And that's just for one subset of the CoC world, right? Is that something that all virtio drivers need/want to care about?
What is missing, and what you seem to be asking for, is an opinionated stance on which drivers we care about in this world?
True.Yes.
Quoted 5 lines
coco guys tried to annotate drivers at some point to do exactly that. this was rejected upstream from the position that this is not different from handling buggy hardware, and just to fix all drivers. so it's up to users, and I guess for virtio the answer is yes with some exceptions because we don't have a better answer right now.
Ok, so back to the original question here:
Quoted 9 lines
Quoted 6 lines
So I don't see a real answer to the "does Linux trust the host to give you good data or not" question in that file, am I missing it?
thanks,
greg k-h
This? Note the last sentence.
Quoted 14 lines
The **Linux CoCo VM attack surface** is any interface exposed from a CoCo guest Linux kernel towards an untrusted host that is not covered by the CoCo technology SW/HW protection. This includes any possible side-channels, as well as transient execution side channels. Examples of explicit (not side-channel) interfaces include accesses to port I/O, MMIO and DMA interfaces, access to PCI configuration space, VMM-specific hypercalls (towards Host-side VMM), access to shared memory pages, interrupts allowed to be injected into the guest kernel by the host, as well as CoCo technology-specific hypercalls, if present. Additionally, the host in a CoCo system typically controls the process of creating a CoCo
guest: it has a method to load into a guest the firmware and bootloader images, the kernel image together with the kernel command line. All of this data should also be considered untrusted until its integrity and authenticity is established via attestation.Great, so you are saying that we need to fix any bug found where a host could be sending "bad" data over the virtio path before, and after, the driver is bound to the device. That's a solid answer, and let's let the LLMs run with that!
Which also implies that the first 3 patches here are acceptable, right? :)
Quoted 8 lines
Quoted 3 lines
thanks,
greg k-h
The 1st patch has nothing to do with coco. Bad values it checks do not lead to any information leak. I'm fine with it as such
but I
would like the commit log to make that clearer.
Or to be more precise, I'd like the motivation to be documented, given it is not coco, and then I can judge the merits.
Quoted 3 lines
Signature · 2 lines
-- MST
Re: [PATCH v2 1/4] virtio-mem: validate device-reported block size
In reply to Michael S. TsirkinHey there,
Quoted 117 lines · Michael S. Tsirkin
Quoted 82 lines · Greg Kroah-Hartman
Quoted 81 lines · Michael S. Tsirkin
Quoted 80 lines · Greg Kroah-Hartman
Quoted 60 lines · Michael S. Tsirkin
Quoted 59 lines · Greg Kroah-Hartman
Quoted 58 lines · Michael S. Tsirkin
Quoted 49 lines · Greg Kroah-Hartman
Quoted 38 lines · Michael S. Tsirkin
Quoted 5 lines · David Hildenbrand (Arm)
Quoted 4 lines · Michael S. Tsirkin
Quoted 3 lines · David Hildenbrand (Arm)
Quoted 1 line
Or do we just always trust virtio mem devices explicitly?
It's hard for me to understand where we draw the line, really.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
But maybe MST can clarify what we care about in virtio world where the hypervisor is fully in charge of the device,
Generally:
- The guest is expected to whitelist drivers (most drivers have not been audited).But even if you audited your driver, who makes sure that we consider all ways where the device could mess with us?
A lot of this is up to a correct setup. For example, make sure all filesystems are encrypted and refuse to mount unencrypted ones.
Quoted 4 lines
Something feels off here.
Handling selected out-of-spec scenarios like this feels like a band-aid. Happy to be corrected.
Well
Documentation/security/snp-tdx-threat-model.rstputs it like this:
It is important to note
that this doesn’t imply that the host or VMM are intentionally malicious, but that there exists a security value in having a small CoCo VM TCB.and
While traditionally the host has unlimited access to guest data and can leverage this access to attack the guest, the CoCo systems mitigate such attacks by adding security features like guest data confidentiality and integrity protection.
now, when we are talking about "mitigation" it is indeed becoming a bit murky.
Quoted 5 lines
For me, a rule of thumb I came up with is that if the validation happens to also be helful for users e.g. to work around buggy devices, or maybe because we feel failing gracefully is nice because this will allow to later make use of this config and old drivers will fail but at least not panic, then it is good to include.
Why not do what USB does? Don't trust the device until AFTER
probe()succeeds? All of the needed checking should happen before then, as that is a "slow path" so lots of validation and the like can happen at that point.Quoted 7 lines
After that, during the normal data paths, after the driver is bound, trust it all you want as attempting to validate every single packet is just going to be impossible.
thanks,
greg k-h
People do expect that data path validation at this point.
Quoted 8 lines
Quoted 4 lines
Ok, so you want this patch :)
And more, as you need to treat everything from the host as "untrusted", and it must be "verified".
Well. First it's not me) Second it's only specific configurations - for example there's no short term plan to validate filesystem code, people are expected to rely on encryption. The reasons have more to do with the available manpower than anything else.
Sure, but again, for subsystems, you have to define your threat model as the LLMs are churning against the code base and coming up with lots of crazy ideas if a device should or should not be trusted and spitting out patches and reports like the ones that are in the first few patches of this series.
So please, pick a model, let's document it, and go with that. I am getting directly conflicting responses here.
thanks,
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
greg k-h
Supposed to be this one:
Documentation/security/snp-tdx-threat-model.rstwhat is missing?
A policy decision that needs to be made. All that document does is describe a bunch of different "threats" yet does not decide what to do about them at all from what I can tell.
That would be this section I think:
The **Linux kernel CoCo VM security objectives** can be summarized as follows:
it does, indeed, not go into detail about how to interact, safely, with untrusted entities. Does it really need to be spelled out?
Quoted 2 lines
And that's just for one subset of the CoC world, right? Is that something that all virtio drivers need/want to care about?
What is missing, and what you seem to be asking for, is an opinionated stance on which drivers we care about in this world?
True.
coco guys tried to annotate drivers at some point to do exactly that. this was rejected upstream from the position that this is not different from handling buggy hardware, and just to fix all drivers. so it's up to users, and I guess for virtio the answer is yes with some exceptions because we don't have a better answer right now.Quoted 6 lines
So I don't see a real answer to the "does Linux trust the host to give you good data or not" question in that file, am I missing it?
thanks,
greg k-h
This? Note the last sentence.
Quoted 14 lines
The **Linux CoCo VM attack surface** is any interface exposed from a CoCo guest Linux kernel towards an untrusted host that is not covered by the CoCo technology SW/HW protection. This includes any possible side-channels, as well as transient execution side channels. Examples of explicit (not side-channel) interfaces include accesses to port I/O, MMIO and DMA interfaces, access to PCI configuration space, VMM-specific hypercalls (towards Host-side VMM), access to shared memory pages, interrupts allowed to be injected into the guest kernel by the host, as well as CoCo technology-specific hypercalls, if present. Additionally, the host in a CoCo system typically controls the process of creating a CoCo
guest: it has a method to load into a guest the firmware and bootloader images, the kernel image together with the kernel command line. All of this data should also be considered untrusted until its integrity and authenticity is established via attestation.
I'm glad you're finding this document helpful, it took us massive back-and-forth to get somewhere everyone was happy.
Here's my 2 cents on this debate, if I may. I think defensive programming is always a positive, and we don't just say, "the spec disallows it".
Historically, one of the biggest criticisms of coco, especially around device hardening, was that there were too many values that a malicious/buggy device could misreport, making it a losing battle. That is no longer the case with LLMs, and we have the advantage (and challenge) of open-source dev, which allows us to receive many of these fixes "for free". If others want to burn their tokens, let them :)
Thanks,
Carlos
Quoted 3 lines
Greg Kroah-Hartman
maintainerRe: [PATCH v2 1/4] virtio-mem: validate device-reported block size
Quoted 6 lines · Carlos Bilbao
Historically, one of the biggest criticisms of coco, especially around device hardening, was that there were too many values that a malicious/buggy device could misreport, making it a losing battle. That is no longer the case with LLMs, and we have the advantage (and challenge) of open-source dev, which allows us to receive many of these fixes "for free". If others want to burn their tokens, let them :)
I have lots of tokens to burn :)
So along those lines, any suggestions on how best to fuzz these code paths? Any workloads you all use for testing that I can take advantage of?
thanks,
greg k-h
Re: [PATCH v2 1/4] virtio-mem: validate device-reported block size
Quoted 7 lines · Greg Kroah-Hartman
Quoted 6 lines · Carlos Bilbao
Historically, one of the biggest criticisms of coco, especially around device hardening, was that there were too many values that a malicious/buggy device could misreport, making it a losing battle. That is no longer the case with LLMs, and we have the advantage (and challenge) of open-source dev, which allows us to receive many of these fixes "for free". If others want to burn their tokens, let them :)
Quoted 5 lines
I have lots of tokens to burn :)
So along those lines, any suggestions on how best to fuzz these code paths? Any workloads you all use for testing that I can take advantage of?
We've the virtio-mem config struct layout and the kernel source, so for obvious fixes like a NULL check, static analysis is better than fuzzing. Claude took a few mins to find me two examples:
Patch 1: virtio-mem: reject non-power-of-two device_block_size This one is for virtio_mem_init() to check if !is_power_of_2(vm->device_block_size)
Patch 2: virto-mem: validate region_size and usable_region_size THis one checks region_size != 0 and vm->usable_reion_size > vm->region_size.
An endless factory of "silly" checks like these are low hanging fruit.
Now, for harder bugs, looking around for fuzz options, VirtFuzz [1] looks like a great candidate for those interested in pursuing this direction.
Their PoC fuzzes wireless/Bluetooth stack, but nothing our AI overlords can't quickly adapt for virtio-mem and other virtio drivers; the JSON definition to describe device behavior is easily extensible. Their threat model [2] describes an external attacker, but in the context of coco, the virtio device itself is the attacker. Here's a vibe coded PR of what I mean:
https://github.com/seemoo-lab/VirtFuzz/pull/7
CCed the creators/authors, thanks for open sourcing this!
Thanks,
Carlos
[1] https://github.com/seemoo-lab/VirtFuzz
Quoted 7 lines · Greg Kroah-Hartman
Quoted 6 lines · Carlos Bilbao
Historically, one of the biggest criticisms of coco, especially around device hardening, was that there were too many values that a malicious/buggy device could misreport, making it a losing battle. That is no longer the case with LLMs, and we have the advantage (and challenge) of open-source dev, which allows us to receive many of these fixes "for free". If others want to burn their tokens, let them :)
Quoted 5 lines
I have lots of tokens to burn :)
So along those lines, any suggestions on how best to fuzz these code paths? Any workloads you all use for testing that I can take advantage of?
We've the virto-mem config struct layout and the kernel source, so for obvious fixes like a NULL check, static analysis is better than fuzzing. Claude took a few mins to find me two examples:
Patch 1: virtio-mem: reject non-power-of-two device_block_size This one is for virtio_mem_init() to check if !is_power_of_2(vm->device_block_size)
Patch 2: virto-mem: validate region_size and usable_region_size THis one checks region_size != 0 and vm->usable_reion_size > vm->region_size.
An endless factory of "silly" checks like these are low hanging fruit.
Now, for harder bugs, looking around for fuzz options, VirtFuzz [1] looks like a great candidate for those interested in pursuing this direction.
Their PoC fuzzes wireless/Bluetooth stack, but nothing our AI overlords can't quickly adapt for virtio-mem and other virtio drivers; the JSON definition to describe device behavior is easily extensible. Their threat model [2] describes an external attacker, but in the context of coco, the virtio device itself is the attacker. Here's a vibe coded PR of what I mean:
https://github.com/seemoo-lab/VirtFuzz/pull/7
CCed the creators/authors, thanks for open sourcing this!
Thanks,
Carlos
[1] https://github.com/seemoo-lab/VirtFuzz
[2] https://www.computer.org/csdl/proceedings-article/sp/2024/313000a024/1RjEa0y9RMQ
Quoted 3 lines
thanks,
greg k-h
[2] https://www.computer.org/csdl/proceedings-article/sp/2024/313000a024/1RjEa0y9RMQ
Quoted 4 lines
thanks,
greg k-h
Michael S. Tsirkin
maintainerRe: [PATCH v2 1/4] virtio-mem: validate device-reported block size
Quoted 24 lines · Carlos Bilbao
Quoted 7 lines · Greg Kroah-Hartman
Quoted 6 lines · Carlos Bilbao
Historically, one of the biggest criticisms of coco, especially around device hardening, was that there were too many values that a malicious/buggy device could misreport, making it a losing battle. That is no longer the case with LLMs, and we have the advantage (and challenge) of open-source dev, which allows us to receive many of these fixes "for free". If others want to burn their tokens, let them :)
Quoted 5 lines
I have lots of tokens to burn :)
So along those lines, any suggestions on how best to fuzz these code paths? Any workloads you all use for testing that I can take advantage of?
We've the virtio-mem config struct layout and the kernel source, so for obvious fixes like a NULL check, static analysis is better than fuzzing. Claude took a few mins to find me two examples:
Patch 1: virtio-mem: reject non-power-of-two
device_block_sizeThis one is forvirtio_mem_init()to check if !is_power_of_2(vm->device_block_size)
Quoted 5 lines
Patch 2: virto-mem: validate
region_sizeandusable_region_sizeTHis one checksregion_size!= 0 andvm->usable_reion_size>vm->region_size.An endless factory of "silly" checks like these are low hanging fruit.
At the same time, these checks don't actually help within the coco threat model, do they?
Quoted 9 lines
Now, for harder bugs, looking around for fuzz options, VirtFuzz [1] looks like a great candidate for those interested in pursuing this direction.
Their PoC fuzzes wireless/Bluetooth stack, but nothing our AI overlords can't quickly adapt for virtio-mem and other virtio drivers; the JSON definition to describe device behavior is easily extensible. Their threat model [2] describes an external attacker, but in the context of coco, the virtio device itself is the attacker.
What we need, however, is to exclude DoS attacks - these are outside the threat model. If people try to address all DoS attacks uncritically we just get a churn of changes which just might introduce issues of their own.
Example:
BUG_ON(!is_power_of_2(....));
panics, non exploitable.
if(!is_power_of_2(....)) goto error;
can become exploitable if the cleanup is done wrong.
Quoted 73 lines
Here's a vibe coded PR of what I mean:
https://github.com/seemoo-lab/VirtFuzz/pull/7
CCed the creators/authors, thanks for open sourcing this!
Thanks,
Carlos[1] https://github.com/seemoo-lab/VirtFuzz
Quoted 7 lines · Greg Kroah-Hartman
Quoted 6 lines · Carlos Bilbao
Historically, one of the biggest criticisms of coco, especially around device hardening, was that there were too many values that a malicious/buggy device could misreport, making it a losing battle. That is no longer the case with LLMs, and we have the advantage (and challenge) of open-source dev, which allows us to receive many of these fixes "for free". If others want to burn their tokens, let them :)
Quoted 5 lines
I have lots of tokens to burn :)
So along those lines, any suggestions on how best to fuzz these code paths? Any workloads you all use for testing that I can take advantage of?
We've the virto-mem config struct layout and the kernel source, so for obvious fixes like a NULL check, static analysis is better than fuzzing. Claude took a few mins to find me two examples:
Patch 1: virtio-mem: reject non-power-of-two
device_block_sizeThis one is forvirtio_mem_init()to check if !is_power_of_2(vm->device_block_size)Patch 2: virto-mem: validate
region_sizeandusable_region_sizeTHis one checksregion_size!= 0 andvm->usable_reion_size>vm->region_size.An endless factory of "silly" checks like these are low hanging fruit.
Now, for harder bugs, looking around for fuzz options, VirtFuzz [1] looks like a great candidate for those interested in pursuing this direction.
Their PoC fuzzes wireless/Bluetooth stack, but nothing our AI overlords can't quickly adapt for virtio-mem and other virtio drivers; the JSON definition to describe device behavior is easily extensible. Their threat model [2] describes an external attacker, but in the context of coco, the virtio device itself is the attacker. Here's a vibe coded PR of what I mean:
https://github.com/seemoo-lab/VirtFuzz/pull/7
CCed the creators/authors, thanks for open sourcing this!
Thanks,
Carlos[1] https://github.com/seemoo-lab/VirtFuzz
[2] https://www.computer.org/csdl/proceedings-article/sp/2024/313000a024/1RjEa0y9RMQQuoted 3 lines
thanks,
greg k-h
[2] https://www.computer.org/csdl/proceedings-article/sp/2024/313000a024/1RjEa0y9RMQ
Quoted 4 lines
thanks,
greg k-h
Re: [PATCH v2 1/4] virtio-mem: validate device-reported block size
Hello Michael,
Quoted 48 lines · Michael S. Tsirkin
Quoted 23 lines · Carlos Bilbao
Quoted 7 lines · Greg Kroah-Hartman
Quoted 6 lines · Carlos Bilbao
Historically, one of the biggest criticisms of coco, especially around device hardening, was that there were too many values that a malicious/buggy device could misreport, making it a losing battle. That is no longer the case with LLMs, and we have the advantage (and challenge) of open-source dev, which allows us to receive many of these fixes "for free". If others want to burn their tokens, let them :)
Quoted 5 lines
I have lots of tokens to burn :)
So along those lines, any suggestions on how best to fuzz these code paths? Any workloads you all use for testing that I can take advantage of?
We've the virtio-mem config struct layout and the kernel source, so for obvious fixes like a NULL check, static analysis is better than fuzzing. Claude took a few mins to find me two examples:
Patch 1: virtio-mem: reject non-power-of-two
device_block_sizeThis one is forvirtio_mem_init()to check if !is_power_of_2(vm->device_block_size)Quoted 5 lines
Patch 2: virto-mem: validate
region_sizeandusable_region_sizeTHis one checksregion_size!= 0 andvm->usable_reion_size>vm->region_size.An endless factory of "silly" checks like these are low hanging fruit.
At the same time, these checks don't actually help within the coco threat model, do they?
Quoted 9 lines
Now, for harder bugs, looking around for fuzz options, VirtFuzz [1] looks like a great candidate for those interested in pursuing this direction.
Their PoC fuzzes wireless/Bluetooth stack, but nothing our AI overlords can't quickly adapt for virtio-mem and other virtio drivers; the JSON definition to describe device behavior is easily extensible. Their threat model [2] describes an external attacker, but in the context of coco, the virtio device itself is the attacker.
What we need, however, is to exclude DoS attacks - these are outside the threat model. If people try to address all DoS attacks uncritically we just get a churn of changes which just might introduce issues of their own.
Example:
Quoted 7 lines
BUG_ON(!is_power_of_2(....));panics, non exploitable.
if(!is_power_of_2(....)) goto error;can become exploitable if the cleanup is done wrong.
Yes, you are 100% technically right about the scope of the threat model. DoS is out of scope because it is a fundamentally unreachable goal; the cloud provider can always just "pull the plug". The dangers of "vibe-coding" you point out are real, over-eager LLMs fixing up and down will create new vulnerabilities in complex cleanup paths. Also, TBH, I sympathize with a maintainer's disinterest in reviewing a million stupid checks.
But, to play devil's advocate: this assumes a missing check like is_power_of_2 only ever leads to a benign crash, rather than already cascading into an unknown, exploitable state down the line.
So these checks are not _just_ to prevent DoS!
Anyhow, this is the exact justification for VirtFuzz. If your main concern is that adding validation checks might introduce subtle exploit paths in the error-cleanup code, VirtFuzz and tools like that, can fuzz those new paths exhaustively. It gives the automated safety net needed to scale coco device with as little regressions as possible.
Quoted 66 lines
Quoted 66 lines
Here's a vibe coded PR of what I mean:
https://github.com/seemoo-lab/VirtFuzz/pull/7
CCed the creators/authors, thanks for open sourcing this!
Thanks,
Carlos[1] https://github.com/seemoo-lab/VirtFuzz
Quoted 7 lines · Greg Kroah-Hartman
Quoted 6 lines · Carlos Bilbao
Historically, one of the biggest criticisms of coco, especially around device hardening, was that there were too many values that a malicious/buggy device could misreport, making it a losing battle. That is no longer the case with LLMs, and we have the advantage (and challenge) of open-source dev, which allows us to receive many of these fixes "for free". If others want to burn their tokens, let them :)
Quoted 5 lines
I have lots of tokens to burn :)
So along those lines, any suggestions on how best to fuzz these code paths? Any workloads you all use for testing that I can take advantage of?
We've the virto-mem config struct layout and the kernel source, so for obvious fixes like a NULL check, static analysis is better than fuzzing. Claude took a few mins to find me two examples:
Patch 1: virtio-mem: reject non-power-of-two
device_block_sizeThis one is forvirtio_mem_init()to check if !is_power_of_2(vm->device_block_size)Patch 2: virto-mem: validate
region_sizeandusable_region_sizeTHis one checksregion_size!= 0 andvm->usable_reion_size>vm->region_size.An endless factory of "silly" checks like these are low hanging fruit.
Now, for harder bugs, looking around for fuzz options, VirtFuzz [1] looks like a great candidate for those interested in pursuing this direction.
Their PoC fuzzes wireless/Bluetooth stack, but nothing our AI overlords can't quickly adapt for virtio-mem and other virtio drivers; the JSON definition to describe device behavior is easily extensible. Their threat model [2] describes an external attacker, but in the context of coco, the virtio device itself is the attacker. Here's a vibe coded PR of what I mean:
https://github.com/seemoo-lab/VirtFuzz/pull/7
CCed the creators/authors, thanks for open sourcing this!
Thanks,
Carlos[1] https://github.com/seemoo-lab/VirtFuzz
[2] https://www.computer.org/csdl/proceedings-article/sp/2024/313000a024/1RjEa0y9RMQQuoted 2 lines
thanks,
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
greg k-h
[2] https://www.computer.org/csdl/proceedings-article/sp/2024/313000a024/1RjEa0y9RMQ
Quoted 3 lines
thanks,
greg k-h
Thanks,
Carlos
Michael S. Tsirkin
maintainerRe: [PATCH v2 1/4] virtio-mem: validate device-reported block size
Quoted 68 lines · Carlos Bilbao
Hello Michael,
Quoted 48 lines · Michael S. Tsirkin
Quoted 23 lines · Carlos Bilbao
Quoted 7 lines · Greg Kroah-Hartman
Quoted 6 lines · Carlos Bilbao
Historically, one of the biggest criticisms of coco, especially around device hardening, was that there were too many values that a malicious/buggy device could misreport, making it a losing battle. That is no longer the case with LLMs, and we have the advantage (and challenge) of open-source dev, which allows us to receive many of these fixes "for free". If others want to burn their tokens, let them :)
Quoted 5 lines
I have lots of tokens to burn :)
So along those lines, any suggestions on how best to fuzz these code paths? Any workloads you all use for testing that I can take advantage of?
We've the virtio-mem config struct layout and the kernel source, so for obvious fixes like a NULL check, static analysis is better than fuzzing. Claude took a few mins to find me two examples:
Patch 1: virtio-mem: reject non-power-of-two
device_block_sizeThis one is forvirtio_mem_init()to check if !is_power_of_2(vm->device_block_size)Quoted 5 lines
Patch 2: virto-mem: validate
region_sizeandusable_region_sizeTHis one checksregion_size!= 0 andvm->usable_reion_size>vm->region_size.An endless factory of "silly" checks like these are low hanging fruit.
At the same time, these checks don't actually help within the coco threat model, do they?
Quoted 9 lines
Now, for harder bugs, looking around for fuzz options, VirtFuzz [1] looks like a great candidate for those interested in pursuing this direction.
Their PoC fuzzes wireless/Bluetooth stack, but nothing our AI overlords can't quickly adapt for virtio-mem and other virtio drivers; the JSON definition to describe device behavior is easily extensible. Their threat model [2] describes an external attacker, but in the context of coco, the virtio device itself is the attacker.
What we need, however, is to exclude DoS attacks - these are outside the threat model. If people try to address all DoS attacks uncritically we just get a churn of changes which just might introduce issues of their own.
Example:
Quoted 7 lines
BUG_ON(!is_power_of_2(....));panics, non exploitable.
if(!is_power_of_2(....)) goto error;can become exploitable if the cleanup is done wrong.
Yes, you are 100% technically right about the scope of the threat model. DoS is out of scope because it is a fundamentally unreachable goal; the cloud provider can always just "pull the plug". The dangers of "vibe-coding" you point out are real, over-eager LLMs fixing up and down will create new vulnerabilities in complex cleanup paths. Also, TBH, I sympathize with a maintainer's disinterest in reviewing a million stupid checks.
Quoted 5 lines
But, to play devil's advocate: this assumes a missing check like
is_power_of_2only ever leads to a benign crash, rather than already cascading into an unknown, exploitable state down the line.So these checks are not _just_ to prevent DoS!
I don't get it. It's normally for bug reporters to show the problem is real. How about analysing what's going on eh?
The situation where a misbehaving hypervisor crashes guest and this is reported as a "security problem" is unsustainable.
Quoted 6 lines
Anyhow, this is the exact justification for VirtFuzz. If your main concern is that adding validation checks might introduce subtle exploit paths in the error-cleanup code, VirtFuzz and tools like that, can fuzz those new paths exhaustively. It gives the automated safety net needed to scale coco device with as little regressions as possible.
Sorry I'm pretty sceptic how far this will get us, supposedly all virtio drivers have been fuzzed by now.
Are we gonnu be inserting specilation barriers around all these "security checks", as one example?
If there's something that never happens, I'm okay with just BUG_ON instead of carefully propagating errors all around the place.
Quoted 79 lines
Quoted 67 lines
Quoted 67 lines
Here's a vibe coded PR of what I mean:
https://github.com/seemoo-lab/VirtFuzz/pull/7
CCed the creators/authors, thanks for open sourcing this!
Thanks,
Carlos[1] https://github.com/seemoo-lab/VirtFuzz
Quoted 7 lines · Greg Kroah-Hartman
Quoted 6 lines · Carlos Bilbao
Historically, one of the biggest criticisms of coco, especially around device hardening, was that there were too many values that a malicious/buggy device could misreport, making it a losing battle. That is no longer the case with LLMs, and we have the advantage (and challenge) of open-source dev, which allows us to receive many of these fixes "for free". If others want to burn their tokens, let them :)
Quoted 5 lines
I have lots of tokens to burn :)
So along those lines, any suggestions on how best to fuzz these code paths? Any workloads you all use for testing that I can take advantage of?
We've the virto-mem config struct layout and the kernel source, so for obvious fixes like a NULL check, static analysis is better than fuzzing. Claude took a few mins to find me two examples:
Patch 1: virtio-mem: reject non-power-of-two
device_block_sizeThis one is forvirtio_mem_init()to check if !is_power_of_2(vm->device_block_size)Patch 2: virto-mem: validate
region_sizeandusable_region_sizeTHis one checksregion_size!= 0 andvm->usable_reion_size>vm->region_size.An endless factory of "silly" checks like these are low hanging fruit.
Now, for harder bugs, looking around for fuzz options, VirtFuzz [1] looks like a great candidate for those interested in pursuing this direction.
Their PoC fuzzes wireless/Bluetooth stack, but nothing our AI overlords can't quickly adapt for virtio-mem and other virtio drivers; the JSON definition to describe device behavior is easily extensible. Their threat model [2] describes an external attacker, but in the context of coco, the virtio device itself is the attacker. Here's a vibe coded PR of what I mean:
https://github.com/seemoo-lab/VirtFuzz/pull/7
CCed the creators/authors, thanks for open sourcing this!
Thanks,
Carlos[1] https://github.com/seemoo-lab/VirtFuzz
[2] https://www.computer.org/csdl/proceedings-article/sp/2024/313000a024/1RjEa0y9RMQQuoted 2 lines
thanks,
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
greg k-h
[2] https://www.computer.org/csdl/proceedings-article/sp/2024/313000a024/1RjEa0y9RMQ
Quoted 3 lines
thanks,
greg k-h
Thanks,
Carlos
Re: [PATCH v2 1/4] virtio-mem: validate device-reported block size
Quoted 82 lines · Michael S. Tsirkin
Quoted 66 lines · Carlos Bilbao
Hello Michael,
Quoted 47 lines · Michael S. Tsirkin
Quoted 22 lines · Carlos Bilbao
Quoted 7 lines · Greg Kroah-Hartman
Quoted 6 lines · Carlos Bilbao
Historically, one of the biggest criticisms of coco, especially around device hardening, was that there were too many values that a malicious/buggy device could misreport, making it a losing battle. That is no longer the case with LLMs, and we have the advantage (and challenge) of open-source dev, which allows us to receive many of these fixes "for free". If others want to burn their tokens, let them :)
Quoted 5 lines
I have lots of tokens to burn :)
So along those lines, any suggestions on how best to fuzz these code paths? Any workloads you all use for testing that I can take advantage of?
We've the virtio-mem config struct layout and the kernel source, so for obvious fixes like a NULL check, static analysis is better than fuzzing. Claude took a few mins to find me two examples:
Patch 1: virtio-mem: reject non-power-of-two
device_block_sizeThis one is forvirtio_mem_init()to check if !is_power_of_2(vm->device_block_size)Quoted 5 lines
Patch 2: virto-mem: validate
region_sizeandusable_region_sizeTHis one checksregion_size!= 0 andvm->usable_reion_size>vm->region_size.An endless factory of "silly" checks like these are low hanging fruit.
At the same time, these checks don't actually help within the coco threat model, do they?
Quoted 9 lines
Now, for harder bugs, looking around for fuzz options, VirtFuzz [1] looks like a great candidate for those interested in pursuing this direction.
Their PoC fuzzes wireless/Bluetooth stack, but nothing our AI overlords can't quickly adapt for virtio-mem and other virtio drivers; the JSON definition to describe device behavior is easily extensible. Their threat model [2] describes an external attacker, but in the context of coco, the virtio device itself is the attacker.
What we need, however, is to exclude DoS attacks - these are outside the threat model. If people try to address all DoS attacks uncritically we just get a churn of changes which just might introduce issues of their own.
Example:
Quoted 7 lines
BUG_ON(!is_power_of_2(....));panics, non exploitable.
if(!is_power_of_2(....)) goto error;can become exploitable if the cleanup is done wrong.
Yes, you are 100% technically right about the scope of the threat model. DoS is out of scope because it is a fundamentally unreachable goal; the cloud provider can always just "pull the plug". The dangers of "vibe-coding" you point out are real, over-eager LLMs fixing up and down will create new vulnerabilities in complex cleanup paths. Also, TBH, I sympathize with a maintainer's disinterest in reviewing a million stupid checks.
Quoted 5 lines
But, to play devil's advocate: this assumes a missing check like
is_power_of_2only ever leads to a benign crash, rather than already cascading into an unknown, exploitable state down the line.So these checks are not _just_ to prevent DoS!
I don't get it. It's normally for bug reporters to show the problem is real. How about analysing what's going on eh?
The situation where a misbehaving hypervisor crashes guest and this is reported as a "security problem" is unsustainable.Quoted 5 lines
Anyhow, this is the exact justification for VirtFuzz. If your main concern is that adding validation checks might introduce subtle exploit paths in the error-cleanup code, VirtFuzz and tools like that, can fuzz those new paths exhaustively. It gives the automated safety net needed to scale coco device with as little regressions as possible.
Quoted 8 lines
Sorry I'm pretty sceptic how far this will get us, supposedly all virtio drivers have been fuzzed by now.
Are we gonnu be inserting specilation barriers around all these "security checks", as one example?
If there's something that never happens, I'm okay with just
BUG_ONinstead of carefully propagating errors all around the place.
The cleanest solution is to stop conflating the two threat models at the driver level entirely. coco guests already select per-arch configs, so the kernel already knows at build time whether the device is untrusted. We can gate the hardening checks behind CONFIG_CONFIDENTIAL_COMPUTING and let that config carry the threat model and its consequences, i.e., stricter validation requirements, without burdening mainline virtio or maintainers with DoS stuff that may not belong here.
Under this scheme, yes, BUG_ON for invariants that can't trigger outside of coco either. The config wrapper would be reserved for checks that are only meaningful for coco; so the DoS-vs-exploit distinction is structurally clear instead of something y'all need to wage every time a patch needs review.
Quoted 70 lines
Quoted 70 lines
Quoted 70 lines
Quoted 70 lines
Here's a vibe coded PR of what I mean:
https://github.com/seemoo-lab/VirtFuzz/pull/7
CCed the creators/authors, thanks for open sourcing this!
Thanks,
Carlos[1] https://github.com/seemoo-lab/VirtFuzz
Quoted 7 lines · Greg Kroah-Hartman
Quoted 6 lines · Carlos Bilbao
Historically, one of the biggest criticisms of coco, especially around device hardening, was that there were too many values that a malicious/buggy device could misreport, making it a losing battle. That is no longer the case with LLMs, and we have the advantage (and challenge) of open-source dev, which allows us to receive many of these fixes "for free". If others want to burn their tokens, let them :)
Quoted 5 lines
I have lots of tokens to burn :)
So along those lines, any suggestions on how best to fuzz these code paths? Any workloads you all use for testing that I can take advantage of?
We've the virto-mem config struct layout and the kernel source, so for obvious fixes like a NULL check, static analysis is better than fuzzing. Claude took a few mins to find me two examples:
Patch 1: virtio-mem: reject non-power-of-two
device_block_sizeThis one is forvirtio_mem_init()to check if !is_power_of_2(vm->device_block_size)Patch 2: virto-mem: validate
region_sizeandusable_region_sizeTHis one checksregion_size!= 0 andvm->usable_reion_size>vm->region_size.An endless factory of "silly" checks like these are low hanging fruit.
Now, for harder bugs, looking around for fuzz options, VirtFuzz [1] looks like a great candidate for those interested in pursuing this direction.
Their PoC fuzzes wireless/Bluetooth stack, but nothing our AI overlords can't quickly adapt for virtio-mem and other virtio drivers; the JSON definition to describe device behavior is easily extensible. Their threat model [2] describes an external attacker, but in the context of coco, the virtio device itself is the attacker. Here's a vibe coded PR of what I mean:
https://github.com/seemoo-lab/VirtFuzz/pull/7
CCed the creators/authors, thanks for open sourcing this!
Thanks,
Carlos[1] https://github.com/seemoo-lab/VirtFuzz
[2] https://www.computer.org/csdl/proceedings-article/sp/2024/313000a024/1RjEa0y9RMQQuoted 3 lines
thanks,
greg k-h
[2] https://www.computer.org/csdl/proceedings-article/sp/2024/313000a024/1RjEa0y9RMQ
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
thanks,
greg k-h
Thanks,
Carlos
Thanks,
Carlos
David Hildenbrand (Arm)
maintainerRe: [PATCH v2 1/4] virtio-mem: validate device-reported block size
In reply to Carlos BilbaoQuoted 73 lines · Carlos Bilbao
Quoted 7 lines · Greg Kroah-Hartman
Quoted 6 lines · Carlos Bilbao
Historically, one of the biggest criticisms of coco, especially around device hardening, was that there were too many values that a malicious/buggy device could misreport, making it a losing battle. That is no longer the case with LLMs, and we have the advantage (and challenge) of open-source dev, which allows us to receive many of these fixes "for free". If others want to burn their tokens, let them :)
Quoted 5 lines
I have lots of tokens to burn :)
So along those lines, any suggestions on how best to fuzz these code paths? Any workloads you all use for testing that I can take advantage of?
We've the virtio-mem config struct layout and the kernel source, so for obvious fixes like a NULL check, static analysis is better than fuzzing. Claude took a few mins to find me two examples:
Patch 1: virtio-mem: reject non-power-of-two
device_block_sizeThis one is forvirtio_mem_init()to check if !is_power_of_2(vm->device_block_size)Patch 2: virto-mem: validate
region_sizeandusable_region_sizeTHis one checksregion_size!= 0 andvm->usable_reion_size>vm->region_size.An endless factory of "silly" checks like these are low hanging fruit.
Now, for harder bugs, looking around for fuzz options, VirtFuzz [1] looks like a great candidate for those interested in pursuing this direction.
Their PoC fuzzes wireless/Bluetooth stack, but nothing our AI overlords can't quickly adapt for virtio-mem and other virtio drivers; the JSON definition to describe device behavior is easily extensible. Their threat model [2] describes an external attacker, but in the context of coco, the virtio device itself is the attacker. Here's a vibe coded PR of what I mean:
https://github.com/seemoo-lab/VirtFuzz/pull/7
CCed the creators/authors, thanks for open sourcing this!
Thanks,
Carlos[1] https://github.com/seemoo-lab/VirtFuzz
Quoted 7 lines · Greg Kroah-Hartman
Quoted 6 lines · Carlos Bilbao
Historically, one of the biggest criticisms of coco, especially around device hardening, was that there were too many values that a malicious/buggy device could misreport, making it a losing battle. That is no longer the case with LLMs, and we have the advantage (and challenge) of open-source dev, which allows us to receive many of these fixes "for free". If others want to burn their tokens, let them :)
Quoted 5 lines
I have lots of tokens to burn :)
So along those lines, any suggestions on how best to fuzz these code paths? Any workloads you all use for testing that I can take advantage of?
We've the virto-mem config struct layout and the kernel source, so for obvious fixes like a NULL check, static analysis is better than fuzzing. Claude took a few mins to find me two examples:
Patch 1: virtio-mem: reject non-power-of-two
device_block_sizeThis one is forvirtio_mem_init()to check if !is_power_of_2(vm->device_block_size)
Quoted 5 lines
Patch 2: virto-mem: validate
region_sizeandusable_region_sizeTHis one checksregion_size!= 0 andvm->usable_reion_size>vm->region_size.An endless factory of "silly" checks like these are low hanging fruit.
"silly" is the right word.
Signature · 3 lines
Cheers, David
Greg Kroah-Hartman
maintainerRe: [PATCH v2 1/4] virtio-mem: validate device-reported block size
Quoted 74 lines · David Hildenbrand (Arm)
Quoted 73 lines · Carlos Bilbao
Quoted 7 lines · Greg Kroah-Hartman
Quoted 6 lines · Carlos Bilbao
Historically, one of the biggest criticisms of coco, especially around device hardening, was that there were too many values that a malicious/buggy device could misreport, making it a losing battle. That is no longer the case with LLMs, and we have the advantage (and challenge) of open-source dev, which allows us to receive many of these fixes "for free". If others want to burn their tokens, let them :)
Quoted 5 lines
I have lots of tokens to burn :)
So along those lines, any suggestions on how best to fuzz these code paths? Any workloads you all use for testing that I can take advantage of?
We've the virtio-mem config struct layout and the kernel source, so for obvious fixes like a NULL check, static analysis is better than fuzzing. Claude took a few mins to find me two examples:
Patch 1: virtio-mem: reject non-power-of-two
device_block_sizeThis one is forvirtio_mem_init()to check if !is_power_of_2(vm->device_block_size)Patch 2: virto-mem: validate
region_sizeandusable_region_sizeTHis one checksregion_size!= 0 andvm->usable_reion_size>vm->region_size.An endless factory of "silly" checks like these are low hanging fruit.
Now, for harder bugs, looking around for fuzz options, VirtFuzz [1] looks like a great candidate for those interested in pursuing this direction.
Their PoC fuzzes wireless/Bluetooth stack, but nothing our AI overlords can't quickly adapt for virtio-mem and other virtio drivers; the JSON definition to describe device behavior is easily extensible. Their threat model [2] describes an external attacker, but in the context of coco, the virtio device itself is the attacker. Here's a vibe coded PR of what I mean:
https://github.com/seemoo-lab/VirtFuzz/pull/7
CCed the creators/authors, thanks for open sourcing this!
Thanks,
Carlos[1] https://github.com/seemoo-lab/VirtFuzz
Quoted 7 lines · Greg Kroah-Hartman
Quoted 6 lines · Carlos Bilbao
Historically, one of the biggest criticisms of coco, especially around device hardening, was that there were too many values that a malicious/buggy device could misreport, making it a losing battle. That is no longer the case with LLMs, and we have the advantage (and challenge) of open-source dev, which allows us to receive many of these fixes "for free". If others want to burn their tokens, let them :)
Quoted 5 lines
I have lots of tokens to burn :)
So along those lines, any suggestions on how best to fuzz these code paths? Any workloads you all use for testing that I can take advantage of?
We've the virto-mem config struct layout and the kernel source, so for obvious fixes like a NULL check, static analysis is better than fuzzing. Claude took a few mins to find me two examples:
Patch 1: virtio-mem: reject non-power-of-two
device_block_sizeThis one is forvirtio_mem_init()to check if !is_power_of_2(vm->device_block_size)
Quoted 7 lines
Quoted 5 lines
Patch 2: virto-mem: validate
region_sizeandusable_region_sizeTHis one checksregion_size!= 0 andvm->usable_reion_size>vm->region_size.An endless factory of "silly" checks like these are low hanging fruit.
"silly" is the right word.
"silly" in what way?
Seriously, I'm trying to figure out what you all care about here and what exactly the threat model you want this driver to work in, and I'm getting conflicting answers.
Either you all do worry about the "device" sending bad data and want to protect from that, or you don't and you trust it. Pick one please so that we know how to deal with these bug reports we are getting.
For example, for USB we have said our threat model is:
- we do NOT trust the device before a driver is bound to the device, so if a malicious device can do something to the kernel, the kernel needs to be fixed.
- During the probe() call for a USB driver, the driver does NOT trust the device, and again, anything a malicious device can do to the kernel, the kernel should fix.
- After probe() for a USB driver succeeds, it's up to the driver if it wants to validate all data coming from the device or not. Right now, in general, the kernel trusts the device at that point in time so additional checks are discretionary and at the whim of the maintainer.
For that last point, I will note that some BIG users of Linux (i.e. billions of Android devices) still explicitly do NOT want to trust the USB device at this point in time, and are relying on the kernel to protect the system from bad devices. In that case, various patches have been taken to different drivers and subsystems to play whack-a-mole on while Android gets their act together to finally come up with a solid defensive plan (like ChromeOS has had for a decade.) It will be seen which happens first, all drivers are properly fuzzed and fixed up, or Android gets their act together and finally fixes their b0rked system trust model. I think Android management is relying on the kernel community to do the kernel work as they keep refusing to staff the userspace work that they need to do here...
And yes, I really need to write this up in a more solid document for USB and get it into the tree, but at least this email thread has forced me to write down the above :)
So, again, for virtio drivers, what exactly do you all want to say is your threat model that the drivers need to handle? Can you all agree on something please? Otherwise, for new developers like Hari, this is totaly confusion as to what they should be doing.
thanks,
greg k-h
David Hildenbrand (Arm)
maintainerRe: [PATCH v2 1/4] virtio-mem: validate device-reported block size
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
We've the virto-mem config struct layout and the kernel source, so for obvious fixes like a NULL check, static analysis is better than fuzzing. Claude took a few mins to find me two examples:
Patch 1: virtio-mem: reject non-power-of-two
device_block_sizeThis one is forvirtio_mem_init()to check if !is_power_of_2(vm->device_block_size)Patch 2: virto-mem: validate
region_sizeandusable_region_sizeTHis one checksregion_size!= 0 andvm->usable_reion_size>vm->region_size.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
An endless factory of "silly" checks like these are low hanging fruit.
"silly" is the right word.
"silly" in what way?
As in producing "silly" low-hanging fruit patches that don't move the needle when it comes to security.
Quoted 22 lines
Seriously, I'm trying to figure out what you all care about here and what exactly the threat model you want this driver to work in, and I'm getting conflicting answers.
Either you all do worry about the "device" sending bad data and want to protect from that, or you don't and you trust it. Pick one please so that we know how to deal with these bug reports we are getting.
For example, for USB we have said our threat model is:
- we do NOT trust the device before a driver is bound to the device, so if a malicious device can do something to the kernel, the kernel needs to be fixed.
- During theprobe()call for a USB driver, the driver does NOT trust the device, and again, anything a malicious device can do to the kernel, the kernel should fix.
- Afterprobe()for a USB driver succeeds, it's up to the driver if it wants to validate all data coming from the device or not. Right now, in general, the kernel trusts the device at that point in time so additional checks are discretionary and at the whim of the maintainer.
Quoted 12 lines
For that last point, I will note that some BIG users of Linux (i.e. billions of Android devices) still explicitly do NOT want to trust the USB device at this point in time, and are relying on the kernel to protect the system from bad devices. In that case, various patches have been taken to different drivers and subsystems to play whack-a-mole on while Android gets their act together to finally come up with a solid defensive plan (like ChromeOS has had for a decade.) It will be seen which happens first, all drivers are properly fuzzed and fixed up, or Android gets their act together and finally fixes their b0rked system trust model. I think Android management is relying on the kernel community to do the kernel work as they keep refusing to staff the userspace work that they need to do here...
Right, and for virtio devices trusting the device after probe is just extremely questionable.
What changes during probe that the device suddenly sends us good data?
Why would a hypervisor that tried to break us before probe not try to break us after probe?
Quoted 10 lines
And yes, I really need to write this up in a more solid document for USB and get it into the tree, but at least this email thread has forced me to write down the above :)
So, again, for virtio drivers, what exactly do you all want to say is your threat model that the drivers need to handle? Can you all agree on something please? Otherwise, for new developers like Hari, this is totaly confusion as to what they should be doing.
Well, I am also totally confused why we end up checking against some MUST clauses in the spec, but not against others.
I am very much in favor of making virtio-mem completely safe to use even in coco, where it is currently not used at all.
If it's really about "don't let a device trigger any unexpected kernel code execution by sanitizing all input data", fine with me. We should do exactly that. Try checking all MUST clauses etc.
But I don't think doing the "low hanging fruit" adds any security. It should be done properly or not at all.
Signature · 3 lines
Cheers, David
Re: [PATCH v2 1/4] virtio-mem: validate device-reported block size
Quoted 76 lines · David Hildenbrand (Arm)
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
We've the virto-mem config struct layout and the kernel source, so for obvious fixes like a NULL check, static analysis is better than fuzzing. Claude took a few mins to find me two examples:
Patch 1: virtio-mem: reject non-power-of-two
device_block_sizeThis one is forvirtio_mem_init()to check if !is_power_of_2(vm->device_block_size)Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Patch 2: virto-mem: validate
region_sizeandusable_region_sizeTHis one checksregion_size!= 0 andvm->usable_reion_size>vm->region_size.An endless factory of "silly" checks like these are low hanging fruit.
"silly" is the right word.
"silly" in what way?
As in producing "silly" low-hanging fruit patches that don't move the needle when it comes to security.
Quoted 22 lines
Seriously, I'm trying to figure out what you all care about here and what exactly the threat model you want this driver to work in, and I'm getting conflicting answers.
Either you all do worry about the "device" sending bad data and want to protect from that, or you don't and you trust it. Pick one please so that we know how to deal with these bug reports we are getting.
For example, for USB we have said our threat model is:
- we do NOT trust the device before a driver is bound to the device, so if a malicious device can do something to the kernel, the kernel needs to be fixed.
- During theprobe()call for a USB driver, the driver does NOT trust the device, and again, anything a malicious device can do to the kernel, the kernel should fix.
- Afterprobe()for a USB driver succeeds, it's up to the driver if it wants to validate all data coming from the device or not. Right now, in general, the kernel trusts the device at that point in time so additional checks are discretionary and at the whim of the maintainer.Quoted 12 lines
For that last point, I will note that some BIG users of Linux (i.e. billions of Android devices) still explicitly do NOT want to trust the USB device at this point in time, and are relying on the kernel to protect the system from bad devices. In that case, various patches have been taken to different drivers and subsystems to play whack-a-mole on while Android gets their act together to finally come up with a solid defensive plan (like ChromeOS has had for a decade.) It will be seen which happens first, all drivers are properly fuzzed and fixed up, or Android gets their act together and finally fixes their b0rked system trust model. I think Android management is relying on the kernel community to do the kernel work as they keep refusing to staff the userspace work that they need to do here...
Right, and for virtio devices trusting the device after probe is just extremely questionable.
What changes during probe that the device suddenly sends us good data?
Why would a hypervisor that tried to break us before probe not try to break us after probe?
Quoted 9 lines
And yes, I really need to write this up in a more solid document for USB and get it into the tree, but at least this email thread has forced me to write down the above :)
So, again, for virtio drivers, what exactly do you all want to say is your threat model that the drivers need to handle? Can you all agree on something please? Otherwise, for new developers like Hari, this is totaly confusion as to what they should be doing.
Well, I am also totally confused why we end up checking against some MUST clauses in the spec, but not against others.
I am very much in favor of making virtio-mem completely safe to use even in coco, where it is currently not used at all.
Quoted 6 lines
If it's really about "don't let a device trigger any unexpected kernel code execution by sanitizing all input data", fine with me. We should do exactly that. Try checking all MUST clauses etc.
But I don't think doing the "low hanging fruit" adds any security. It should be done properly or not at all.
I think you're mistaken in assuming that these "silly" fixes don't move the needle at all when it comes to security. We can't really quantify these things, and one extra NULL check by itself is probably not going to make a meaningful difference. But, IMHO, this should be treated as the opposite of "death by a thousand cuts", many small hardening improvements, each individually insignificant, can collectively make the kernel substantially more robust over long periods of time.
Thanks,
Carlos
Michael S. Tsirkin
maintainerRe: [PATCH v2 1/4] virtio-mem: validate device-reported block size
Quoted 95 lines · Carlos Bilbao
Quoted 76 lines · David Hildenbrand (Arm)
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
We've the virto-mem config struct layout and the kernel source, so for obvious fixes like a NULL check, static analysis is better than fuzzing. Claude took a few mins to find me two examples:
Patch 1: virtio-mem: reject non-power-of-two
device_block_sizeThis one is forvirtio_mem_init()to check if !is_power_of_2(vm->device_block_size)Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Patch 2: virto-mem: validate
region_sizeandusable_region_sizeTHis one checksregion_size!= 0 andvm->usable_reion_size>vm->region_size.An endless factory of "silly" checks like these are low hanging fruit.
"silly" is the right word.
"silly" in what way?
As in producing "silly" low-hanging fruit patches that don't move the needle when it comes to security.
Quoted 22 lines
Seriously, I'm trying to figure out what you all care about here and what exactly the threat model you want this driver to work in, and I'm getting conflicting answers.
Either you all do worry about the "device" sending bad data and want to protect from that, or you don't and you trust it. Pick one please so that we know how to deal with these bug reports we are getting.
For example, for USB we have said our threat model is:
- we do NOT trust the device before a driver is bound to the device, so if a malicious device can do something to the kernel, the kernel needs to be fixed.
- During theprobe()call for a USB driver, the driver does NOT trust the device, and again, anything a malicious device can do to the kernel, the kernel should fix.
- Afterprobe()for a USB driver succeeds, it's up to the driver if it wants to validate all data coming from the device or not. Right now, in general, the kernel trusts the device at that point in time so additional checks are discretionary and at the whim of the maintainer.Quoted 12 lines
For that last point, I will note that some BIG users of Linux (i.e. billions of Android devices) still explicitly do NOT want to trust the USB device at this point in time, and are relying on the kernel to protect the system from bad devices. In that case, various patches have been taken to different drivers and subsystems to play whack-a-mole on while Android gets their act together to finally come up with a solid defensive plan (like ChromeOS has had for a decade.) It will be seen which happens first, all drivers are properly fuzzed and fixed up, or Android gets their act together and finally fixes their b0rked system trust model. I think Android management is relying on the kernel community to do the kernel work as they keep refusing to staff the userspace work that they need to do here...
Right, and for virtio devices trusting the device after probe is just extremely questionable.
What changes during probe that the device suddenly sends us good data?
Why would a hypervisor that tried to break us before probe not try to break us after probe?
Quoted 9 lines
And yes, I really need to write this up in a more solid document for USB and get it into the tree, but at least this email thread has forced me to write down the above :)
So, again, for virtio drivers, what exactly do you all want to say is your threat model that the drivers need to handle? Can you all agree on something please? Otherwise, for new developers like Hari, this is totaly confusion as to what they should be doing.
Well, I am also totally confused why we end up checking against some MUST clauses in the spec, but not against others.
I am very much in favor of making virtio-mem completely safe to use even in coco, where it is currently not used at all.
Quoted 6 lines
If it's really about "don't let a device trigger any unexpected kernel code execution by sanitizing all input data", fine with me. We should do exactly that. Try checking all MUST clauses etc.
But I don't think doing the "low hanging fruit" adds any security. It should be done properly or not at all.
I think you're mistaken in assuming that these "silly" fixes don't move the needle at all when it comes to security. We can't really quantify these things, and one extra NULL check by itself is probably not going to make a meaningful difference. But, IMHO, this should be treated as the opposite of "death by a thousand cuts", many small hardening improvements, each individually insignificant, can collectively make the kernel substantially more robust over long periods of time.
Quoted 3 lines
Thanks,
Carlos
Simply put - no.
DoS attacks, including NULL ptr accesses, are outside the confidential computing security boundary. They have to be - denying service to whoever is not paying them is exactly how cloud vendors get paid.
My preference is to ignore such non-issues - we need to focus on handling real ones.
Besides, adding random changes all over the code for non issues can easily introduce new security bugs. That's the classic death by a thousand cuts.
Thanks,
Signature · 1 line
MST
Michael S. Tsirkin
maintainerRe: [PATCH v2 1/4] virtio-mem: validate device-reported block size
In reply to Greg Kroah-HartmanQuoted 3 lines · Greg Kroah-Hartman
Seriously, I'm trying to figure out what you all care about here and what exactly the threat model you want this driver to work in, and I'm getting conflicting answers.
And yet it's documented in the kernel tree.
The threat model for confidential includes everything that can lead to information disclosure but excludes DoS attacks.
It's probably confusing because it's different from USB, where you really do not want a usb device to crash kernel.
Signature · 1 line
MST
PATCH 2/4 virtio_input: validate device-reported multitouch slot count
In reply to Hari Mishalnslots is derived from the ABS_MT_SLOT maximum reported by the virtio device. A device could report a bogus maximum (e.g. -1) making nslots = 0, which input_mt_init_slots() does not reject; it returns success without allocating any slot storage, silently leaving the device registered as multitouch capable with no backing state. Reject non-positive slot counts before calling input_mt_init_slots().
--- drivers/virtio/virtio_input.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/virtio/virtio_input.c +4 -0
@@ -312,6 +312,10 @@ static int virtinput_probe(struct virtio_device *vdev)if (test_bit (ABS_MT_SLOT , vi->idev->absbit)) { nslots =input_abs_get_max (vi->idev,ABS_MT_SLOT ) +1 ; +if (nslots <=0 ) { + err = -EINVAL ; + goto err_mt_init_slots; + } err =input_mt_init_slots (vi->idev, nslots,0 );if (err) goto err_mt_init_slots;
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH 2/4] virtio_input: validate device-reported multitouch slot count
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
Pre-existing issues:
- [High] Concurrent execution of virtqueue interrupts during device teardown causes a use-after-free of the input device.
- [High] If input_register_device() fails, the driver deletes virtqueues without first resetting the virtio device, violating the virtio specification.
- [Medium] The driver fails to detach unused buffers from the vi->evt queue before deleting the virtqueues, leading to leaked DMA mappings.
- [Medium] Missing null-termination for vi->name and vi->serial strings copied from the host.
--
--- Patch [2]: [PATCH 2/4] virtio_input: validate device-reported multitouch slot count --- commit 2551acf6fb14e59620dd29579313834ccc291ba0
Author: Hari Mishal <[email protected]>
virtio_input: validate device-reported multitouch slot count
The commit adds validation for the nslots value derived from the device-reported ABS_MT_SLOT maximum. It prevents registering a multitouch device with zero backing slots by rejecting non-positive slot counts before calling input_mt_init_slots().
Quoted 5 lines
drivers/virtio/virtio_input.c +0
-0
drivers/virtio/virtio_input.c static int virtinput_probe(struct virtio_device *vdev) · line 321
Quoted 10 lines
drivers/virtio/virtio_input.c +4
-0@@ -312,6 +312,10 @@ static int virtinput_probe(struct virtio_device *vdev)if (test_bit (ABS_MT_SLOT , vi->idev->absbit)) { nslots =input_abs_get_max (vi->idev,ABS_MT_SLOT ) +1 ; +if (nslots <=0 ) { + err = -EINVAL ; + goto err_mt_init_slots; + } err =input_mt_init_slots (vi->idev, nslots,0 );if (err) goto err_mt_init_slots;
[Severity: High]
This is a pre-existing issue, but can concurrent execution of virtqueue interrupts during device teardown cause a use-after-free of the input device?
Looking at virtinput_remove(), the teardown unregisters the input device before stopping the hardware and synchronizing interrupts:
drivers/virtio/virtio_input.c:virtinput_remove() {
...
input_unregister_device(vi->idev);
virtio_reset_device(vdev);
...
}If virtinput_recv_events() runs concurrently with virtinput_remove(), the interrupt handler temporarily drops vi->lock and calls input_event(vi->idev).
Meanwhile, virtinput_remove() can free vi->idev if there are no active users, since it doesn't call virtio_reset_device() or del_vqs() until after unregistering the input device.
[Severity: High]
This is a pre-existing issue, but does the error path in virtinput_probe() violate the virtio specification by deleting virtqueues without resetting an active device?
During virtinput_probe(), the device is marked ready and activated:
drivers/virtio/virtio_input.c:virtinput_probe() {
...
virtio_device_ready(vdev);
vi->ready = true;
err = input_register_device(vi->idev);
if (err)
goto err_input_register;
...
}If input_register_device() fails, the code jumps to the error path and deletes the virtqueues without first calling virtio_reset_device():
drivers/virtio/virtio_input.c:virtinput_probe() {
...
err_input_register:
spin_lock_irqsave(&vi->lock, flags);
vi->ready = false;
spin_unlock_irqrestore(&vi->lock, flags);
err_mt_init_slots:
input_free_device(vi->idev);
err_input_alloc:
vdev->config->del_vqs(vdev);
...
}Could this lead to memory corruption or host crashes due to DMA into freed queues?
[Severity: Medium]
This is a pre-existing issue, but does the driver leak DMA mappings for the vi->evt queue during teardown?
In virtinput_remove() and virtinput_freeze(), the driver detaches and frees buffers from the vi->sts queue, but ignores the vi->evt queue:
drivers/virtio/virtio_input.c:virtinput_remove() {
...
while ((buf = virtqueue_detach_unused_buf(vi->sts)) != NULL)
kfree(buf);
vdev->config->del_vqs(vdev);
...
}The buffers in vi->evt were mapped for DMA when queued in virtinput_fill_evt().
Could deleting the virtqueues without detaching these unused buffers leave their DMA mappings active indefinitely?
[Severity: Medium]
This is a pre-existing issue, but does the device name copy lack null-termination if the host provides a full-length string?
In virtinput_probe(), the host-provided string is copied into the fixed-size vi->name array:
drivers/virtio/virtio_input.c:virtinput_probe() {
...
size = virtinput_cfg_select(vi, VIRTIO_INPUT_CFG_ID_NAME, 0);
virtio_cread_bytes(vi->vdev, offsetof(struct virtio_input_config,
u.string),
vi->name, min(size, sizeof(vi->name)));
...
}If the host provides exactly 64 bytes of non-null characters, vi->name will not be null-terminated.
Since this string is passed to vi->idev->name, could a subsequent sysfs read of the device name read past the array boundary?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Michael S. Tsirkin
maintainerRe: [PATCH 2/4] virtio_input: validate device-reported multitouch slot count
In reply to Hari MishalQuoted 6 lines · Hari Mishal
nslots is derived from the
ABS_MT_SLOTmaximum reported by the virtio device. A device could report a bogus maximum (e.g. -1) making nslots = 0, whichinput_mt_init_slots()does not reject; it returns success without allocating any slot storage, silently leaving the device registered as multitouch capable with no backing state.
So let's disable multitouch instead?
Quoted 26 lines
Reject non-positive slot counts before calling
input_mt_init_slots().Assisted-by gkh_clanker:t1000Signed-off-by Hari Mishal <[email protected]>--- drivers/virtio/virtio_input.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/virtio/virtio_input.c +4
-0@@ -312,6 +312,10 @@ static int virtinput_probe(struct virtio_device *vdev)if (test_bit (ABS_MT_SLOT , vi->idev->absbit)) { nslots =input_abs_get_max (vi->idev,ABS_MT_SLOT ) +1 ; +if (nslots <=0 ) { + err = -EINVAL ; + goto err_mt_init_slots; + } err =input_mt_init_slots (vi->idev, nslots,0 );if (err) goto err_mt_init_slots;Signature · 1 line
2.43.0
Re: [PATCH 2/4] virtio_input: validate device-reported multitouch slot count
Quoted 11 lines · Michael S. Tsirkin
Quoted 6 lines · Hari Mishal
nslots is derived from the
ABS_MT_SLOTmaximum reported by the virtio device. A device could report a bogus maximum (e.g. -1) making nslots = 0, whichinput_mt_init_slots()does not reject; it returns success without allocating any slot storage, silently leaving the device registered as multitouch capable with no backing state.So let's disable multitouch instead?
So rather than failing the whole probe, just warn and clear ABS_MT_SLOT from absbit in that case, so the rest of the device still registers? I took my lead from input_mt_init_slots(), which has its own internal cap and returns -EINVAL when the device reports more than 1024 slots.
Shall I modify that case to get the same "warn and disable multitouch" for consistency, or is a hard failure better there since it's a different type of bad device data?
Happy to fix it either way! Just want to confirm before sending V2.
Cheers,
Hari
Michael S. Tsirkin
maintainerRe: [PATCH 2/4] virtio_input: validate device-reported multitouch slot count
Quoted 13 lines · Hari Mishal
Quoted 11 lines · Michael S. Tsirkin
Quoted 6 lines · Hari Mishal
nslots is derived from the
ABS_MT_SLOTmaximum reported by the virtio device. A device could report a bogus maximum (e.g. -1) making nslots = 0, whichinput_mt_init_slots()does not reject; it returns success without allocating any slot storage, silently leaving the device registered as multitouch capable with no backing state.So let's disable multitouch instead?
Quoted 8 lines
So rather than failing the whole probe, just warn and clear
ABS_MT_SLOTfrom absbit in that case, so the rest of the device still registers? I took my lead frominput_mt_init_slots(), which has its own internal cap and returns-EINVALwhen the device reports more than 1024 slots.
Shall I modify that case to get the same "warn and disable multitouch" for consistency, or is a hard failure better there since it's a different type of bad device data?
I don't really know enough for sure but generally if the device can kinda work it's better than not working, and adding
a capability to a device that driver can't use should generally just ignore the capability, not fail probe.
Quoted 4 lines
Happy to fix it either way! Just want to confirm before sending V2.
Cheers,
Hari
Re: [PATCH 2/4] virtio_input: validate device-reported multitouch slot count
Quoted 23 lines · Michael S. Tsirkin
Quoted 13 lines · Hari Mishal
Quoted 11 lines · Michael S. Tsirkin
Quoted 6 lines · Hari Mishal
nslots is derived from the
ABS_MT_SLOTmaximum reported by the virtio device. A device could report a bogus maximum (e.g. -1) making nslots = 0, whichinput_mt_init_slots()does not reject; it returns success without allocating any slot storage, silently leaving the device registered as multitouch capable with no backing state.So let's disable multitouch instead?
Quoted 8 lines
So rather than failing the whole probe, just warn and clear
ABS_MT_SLOTfrom absbit in that case, so the rest of the device still registers? I took my lead frominput_mt_init_slots(), which has its own internal cap and returns-EINVALwhen the device reports more than 1024 slots.
Shall I modify that case to get the same "warn and disable multitouch" for consistency, or is a hard failure better there since it's a different type of bad device data?
Quoted 4 lines
I don't really know enough for sure but generally if the device can kinda work it's better than not working, and adding
a capability to a device that driver can't use should generally just ignore the capability, not fail probe.
What is the failure mode if we keep the ABS_MT_SLOT capability? Does the kernel crash? And if this can cause crash then we should fix input_mt_init_slots() to reject requests for 0 slots with -EINVAL.
Thanks.
Signature · 1 line
Dmitry
A message that is not in the archive (sent off-list or not yet received): CAMmC+=DXS=xs0CZyf+N-71NT8D51xQYatBv=dfVQC1aBohDdmA@mail.gmail.com
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 2/4] virtio_input: validate device-reported multitouch slot count
[ Just realized that CC was dropped in the email I was replying to, so
restoring and resending... ]
Quoted 27 lines · Dmitry Torokhov
Quoted 5 lines · Hari Mishal
Quoted 4 lines
What is the failure mode if we keep the
ABS_MT_SLOTcapability? Does the kernel crash? And if this can cause crash then we should fixinput_mt_init_slots()to reject requests for 0 slots with-EINVAL.Quoted 7 lines
No, it doesn't crash. I think every place in the input core that touches
dev->mtguards against it being NULL:input_handle_abs_event()and themt_slotscheck ininput.c, and evdev's EVIOCGMTSLOTS ioctl handler all explicitly check for NULL and degrade cleanly instead of dereferencing. From my understanding, the worst case is what the original commit message already covers: the device advertises multitouch support it can't back.So what? I still do not see the problem. Let's say I have a device that properly supports multitouch and has slots, but then never sends any events because firmware is buggy. How would that affect anything?
If there is no crash that I would leave the driver alone.
And we need to remember that we are dealing with a hypervisor here that normally had higher level of trust than the VM. If it messes up we do not have to clean up after it. This scenario is different from user attaching a malicious USB device to their system and getting owned.
Thanks.
Signature · 1 line
Dmitry
Michael S. Tsirkin
maintainerRe: [PATCH 2/4] virtio_input: validate device-reported multitouch slot count
Quoted 28 lines · Dmitry Torokhov
[ Just realized that CC was dropped in the email I was replying to, so
restoring and resending... ]Quoted 24 lines · Dmitry Torokhov
Quoted 5 lines · Hari Mishal
Quoted 4 lines
What is the failure mode if we keep the
ABS_MT_SLOTcapability? Does the kernel crash? And if this can cause crash then we should fixinput_mt_init_slots()to reject requests for 0 slots with-EINVAL.Quoted 7 lines
No, it doesn't crash. I think every place in the input core that touches
dev->mtguards against it being NULL:input_handle_abs_event()and themt_slotscheck ininput.c, and evdev's EVIOCGMTSLOTS ioctl handler all explicitly check for NULL and degrade cleanly instead of dereferencing. From my understanding, the worst case is what the original commit message already covers: the device advertises multitouch support it can't back.So what? I still do not see the problem. Let's say I have a device that properly supports multitouch and has slots, but then never sends any events because firmware is buggy. How would that affect anything?
If there is no crash that I would leave the driver alone.
And we need to remember that we are dealing with a hypervisor here that normally had higher level of trust than the VM. If it messes up we do not have to clean up after it. This scenario is different from user attaching a malicious USB device to their system and getting owned.
This last part isn't always true, while hypervisors are generally more trusted than a random usb device, the level of trust isn't always higher level than the VM.
Still if it's a theoretical misconfiguration that leads to nothing bad, not worth special casing it.
Quoted 5 lines
Quoted 2 lines
Thanks.
Signature · 1 line
Dmitry
PATCH v2 2/4 virtio_input: validate device-reported multitouch slot count
In reply to Hari Mishalnslots is derived from the ABS_MT_SLOT maximum reported by the virtio device. A device could report a bogus maximum (e.g. -1) making nslots <= 0, and input_mt_init_slots() can independently fail too (e.g. it rejects slot counts over 1024). Neither case was handled here, and input_mt_init_slots() failing took down the whole probe, losing the rest of the input device over a problem isolated to multitouch.
Instead of failing the probe, warn and disable the ABS_MT_SLOT capability in either case, and let the rest of the device register normally. This recovery assumes input_mt_init_slots() is called with flags == 0: with nonzero flags it can fail after already mutating the input_dev (e.g. via input_set_abs_params()), which this recovery does not account for.
---
v2: per review, disable multitouch instead of failing the whole
probe when the reported slot count is invalid or input_mt_init_slots() otherwise fails.
drivers/virtio/virtio_input.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)
drivers/virtio/virtio_input.c +19 -4
@@ -312,9 +312,25 @@ static int virtinput_probe(struct virtio_device *vdev)if (test_bit (ABS_MT_SLOT , vi->idev->absbit)) { nslots =input_abs_get_max (vi->idev,ABS_MT_SLOT ) +1 ; - err =input_mt_init_slots (vi->idev, nslots,0 ); -if (err) - goto err_mt_init_slots; +if (nslots <=0 ) { +dev_warn (&vdev->dev, +"invalid multitouch slot count %d, disabling multitouch\n" , + nslots); +__clear_bit (ABS_MT_SLOT , vi->idev->absbit); + }else { +/* +* flags is 0: input_mt_init_slots() can only fail +* before touching *idev, so the recovery below is +* a full rollback. +*/ + err =input_mt_init_slots (vi->idev, nslots,0 ); +if (err) { +dev_warn (&vdev->dev, +"failed to init %d multitouch slots (%d), disabling multitouch\n" , + nslots, err); +__clear_bit (ABS_MT_SLOT , vi->idev->absbit); + } + } } }
@@ -331,7 +347,6 @@ static int virtinput_probe(struct virtio_device *vdev)spin_lock_irqsave (&vi->lock, flags); vi->ready = false;spin_unlock_irqrestore (&vi->lock, flags); -err_mt_init_slots:input_free_device (vi->idev); err_input_alloc: vdev->config->del_vqs (vdev);
Signature · 1 line
2.43.0
PATCH 3/4 virtio_console: avoid NULL portdev dereference in in_intr()
In reply to Hari MishalA port's virtqueue is not torn down immediately if the port itself is hot-unplugged (unplug_port() only nulls port->portdev; the vq callback stays registered until the whole device is removed). If in_intr() fires for a port in that window it dereferences port->portdev->vdev via is_rproc_serial(), crashing on the NULL portdev.
Bail out early when portdev has already been cleared.
--- drivers/char/virtio_console.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/char/virtio_console.c +5 -0
@@ -1720,6 +1720,11 @@ static void in_intr(struct virtqueue *vq) }spin_lock_irqsave (&port->inbuf_lock, flags); +if (!port->portdev) { +/* Port is being unplugged, ignore further data. */ +spin_unlock_irqrestore (&port->inbuf_lock, flags); +return ; + } port->inbuf =get_inbuf (port);/*
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH 3/4] virtio_console: avoid NULL portdev dereference in in_intr()
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
New issues:
- [High] The newly introduced !port->portdev check in in_intr() suffers from a Time-Of-Check to Time-Of-Use (TOCTOU) race condition and fails to robustly prevent the NULL pointer dereference.
- [Medium] Bailing out early from in_intr() without consuming the used virtqueue buffers leaves stale data in the queue, contaminating future port instances that reuse the same ID.
Pre-existing issues:
- [High] The patch fails to address a fundamental Use-After-Free (UAF) vulnerability in in_intr() and out_intr(). The helper find_port_by_vq() returns a port without taking a reference count, allowing concurrent hot-unplug to free the port while interrupt handlers are executing. --
--- Patch [3]: [PATCH 3/4] virtio_console: avoid NULL portdev dereference in in_intr() --- commit 53028db078d1834cd8a61fa35f5ddb4495c447b8
Author: Hari Mishal <[email protected]>
virtio_console: avoid NULL portdev dereference in in_intr()
This commit attempts to fix a null pointer dereference in in_intr() caused when a port is hot-unplugged. It adds an early exit check for portdev being null under the inbuf_lock to ignore further data during the unplug window.
Quoted 4 lines
drivers/char/virtio_console.c +0
-0
[ ... ]
drivers/char/virtio_console.c static void in_intr(struct virtqueue *vq) · line 1722
Quoted 4 lines
drivers/char/virtio_console.c +0
-0@@ -1720,6 +1720,11 @@ static void in_intr(struct virtqueue *vq) }spin_lock_irqsave (&port->inbuf_lock, flags);
[Severity: High]
This is a pre-existing issue, but does find_port_by_vq() return the port pointer without acquiring a reference via kref_get()?
If unplug_port() runs concurrently, can it drop the final reference and free the port structure right before we try to take the lock here?
CPU0 CPU1in_intr() unplug_port()
port = find_port_by_vq(...)
kref_put(&port->kref, remove_port);
spin_lock_irqsave(...)
Would this result in a use-after-free on the port structure?
drivers/char/virtio_console.c static void in_intr(struct virtqueue *vq) · line 1723
Quoted 1 line
drivers/char/virtio_console.c +1
-0+if (!port->portdev) {
[Severity: High]
Does this check reliably prevent a null pointer dereference?
Since unplug_port() sets port->portdev = NULL locklessly outside of inbuf_lock, could a concurrent unplug set it to null immediately after this check passes?
Because get_inbuf() is called next, might the compiler reload port->portdev from memory for the later is_rproc_serial(port->portdev->vdev) check, crashing on the newly null pointer?
drivers/char/virtio_console.c static void in_intr(struct virtqueue *vq) · line 1726
Quoted 3 lines
drivers/char/virtio_console.c +3
-0+/* Port is being unplugged, ignore further data. */ +spin_unlock_irqrestore (&port->inbuf_lock, flags); +return ;
[Severity: Medium]
Does returning here without consuming the virtqueue buffers leave stale data in the queue?
Since virtqueues persist across hot-unplugs for the same port ID, could a newly hot-plugged port reuse this virtqueue and read leaked data from the previous session?
Should this path consume the buffers, perhaps by calling flush_bufs(vq, false), before returning?
Quoted 4 lines
drivers/char/virtio_console.c +1
-0+ } port->inbuf =get_inbuf (port);/*
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
PATCH 4/4 virtio_console: take a kref in find_port_by_vq() to fix port UAF
In reply to Hari Mishalfind_port_by_vq() returns a raw struct port pointer without taking a reference on it, unlike find_port_by_devt_in_portdev() which does. find_port_by_vq()'s only two callers, in_intr() and out_intr(), run as virtqueue interrupt callbacks, entirely independent of and possibly concurrently with unplug_port(), which itself runs from a workqueue when the host sends a VIRTIO_CONSOLE_PORT_REMOVE control message.
unplug_port() removes the port from portdev->ports under ports_lock, then later drops its last reference with kref_put(), freeing it via remove_port(). find_port_by_vq() also walks portdev->ports under ports_lock, so if it finds the port still on the list, the list removal, and therefore the eventual kref_put(), has not happened yet, and taking a reference at that point is always safe. Without doing so, in_intr()/out_intr() can be left holding a pointer to a port that unplug_port() frees on another core before they are done using it.
Both triggers are host-controlled as the host decides when to send the PORT_REMOVE control message and when to kick the port's data vq. So a malicious backend could race the two on purpose, without any guest side cooperation. The freed object is a generic kmalloc allocation containing a wait_queue_head_t, which in_intr()/out_intr() pass to wake_up_interruptible() after touching the stale pointer. wake_up_interruptible() invokes a function pointer read out of the wait queue's entries. If the freed slab slot is reclaimed with attacker influenced content before that call, then this is an arbitrary function call primitive rather than just undefined behaviour.
Take a reference in find_port_by_vq() while still holding ports_lock, matching find_port_by_devt_in_portdev(), and release it in in_intr() and out_intr() once they are done with the port.
--- drivers/char/virtio_console.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/char/virtio_console.c +12 -1
@@ -304,6 +304,11 @@ static struct port *find_port_by_id(struct ports_device *portdev, u32 id)return port; } +/* +* The port object's reference is incremented now and +* it is the caller's responsibility to decrement it +*/ +static struct port *find_port_by_vq (struct ports_device *portdev,struct virtqueue *vq) {
@@ -312,8 +317,10 @@ static struct port *find_port_by_vq(struct ports_device *portdev,spin_lock_irqsave (&portdev->ports_lock, flags);list_for_each_entry (port, &portdev->ports, list) -if (port->in_vq == vq || port->out_vq == vq) +if (port->in_vq == vq || port->out_vq == vq) { +kref_get (&port->kref); goto out; + } port =NULL ; out:spin_unlock_irqrestore (&portdev->ports_lock, flags);
@@ -1706,6 +1713,7 @@ static void out_intr(struct virtqueue *vq) }wake_up_interruptible (&port->waitqueue); +kref_put (&port->kref, remove_port); }static void in_intr (struct virtqueue *vq)
@@ -1723,6 +1731,7 @@ static void in_intr(struct virtqueue *vq)if (!port->portdev) {/* Port is being unplugged, ignore further data. */ spin_unlock_irqrestore (&port->inbuf_lock, flags); +kref_put (&port->kref, remove_port);return ; } port->inbuf =get_inbuf (port);
@@ -1756,6 +1765,8 @@ static void in_intr(struct virtqueue *vq)if (is_console_port (port) &&hvc_poll (port->cons.hvc))hvc_kick (); + +kref_put (&port->kref, remove_port); }static void control_intr (struct virtqueue *vq)
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH 4/4] virtio_console: take a kref in find_port_by_vq() to fix port UAF
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] Incomplete fix: in_intr() can still dereference a freed hvc_struct (port->cons.hvc) due to a race with unplug_port().
- [High] A TOCTOU data race on port->portdev between in_intr() and unplug_port() can lead to a NULL pointer dereference.
- [High] File operations (e.g., port_fops_read, port_fops_write) can access freed virtqueue and portdev memory if device removal occurs concurrently. --
--- Patch [4]: [PATCH 4/4] virtio_console: take a kref in find_port_by_vq() to fix port UAF --- commit 135dcd5e5260baeaa35a46f85c302542d073ddaf
Author: Hari Mishal <[email protected]>
virtio_console: take a kref in find_port_by_vq() to fix port UAF
This commit fixes a use-after-free of the port structure by taking a kref in find_port_by_vq() under the ports_lock. It matches the behavior of find_port_by_devt_in_portdev() and safely drops the reference at the end of the interrupt handlers.
Quoted 4 lines
drivers/char/virtio_console.c +0
-0
[ ... ]
drivers/char/virtio_console.c static void in_intr(struct virtqueue *vq) · line 1736
Quoted 7 lines
drivers/char/virtio_console.c +1
-0@@ -1723,6 +1731,7 @@ static void in_intr(struct virtqueue *vq)if (!port->portdev) {/* Port is being unplugged, ignore further data. */ spin_unlock_irqrestore (&port->inbuf_lock, flags); +kref_put (&port->kref, remove_port);return ; }
[Severity: High]
This is a pre-existing issue, but is there a time-of-check to time-of-use (TOCTOU) data race on port->portdev here?
In unplug_port(), port->portdev is locklessly set to NULL at the end of the function. Concurrently, in_intr() checks if (!port->portdev) while holding inbuf_lock. If the check passes before unplug_port() sets it to NULL, in_intr() will proceed and later execute this check:
if (!port->guest_connected && !is_rproc_serial(port->portdev->vdev))
Could this force a reload of port->portdev, read NULL, and cause a kernel panic when accessing ->vdev?
[ ... ]
drivers/char/virtio_console.c static void in_intr(struct virtqueue *vq) · line 1770
Quoted 7 lines
drivers/char/virtio_console.c +2
-0@@ -1756,6 +1765,8 @@ static void in_intr(struct virtqueue *vq)if (is_console_port (port) &&hvc_poll (port->cons.hvc))hvc_kick (); + +kref_put (&port->kref, remove_port); }
[Severity: High]
This is a pre-existing issue, but could in_intr() still dereference a freed hvc_struct due to a race with unplug_port()?
When the host sends a VIRTIO_CONSOLE_PORT_REMOVE control message, unplug_port() calls hvc_remove(port->cons.hvc), freeing the hvc_struct. Concurrently, if the host kicks the data virtqueue, in_intr() passes the portdev check, drops inbuf_lock, and evaluates:
if (is_console_port(port) && hvc_poll(port->cons.hvc))
Since port->cons.hvc is never cleared and this check is lockless, can this dereference the freed memory and lead to memory corruption?
[Severity: High]
This is also a pre-existing issue, but can file operations like port_fops_write() access freed virtqueue and portdev memory if device removal occurs concurrently?
If a user-space process initiates port_fops_write(), it eventually executes:
buf = alloc_buf(port->portdev->vdev, count, 0);
Concurrently, if the host removes the virtio device, virtcons_remove() is called. It unplugs the ports, calls remove_vqs(portdev), and frees portdev via kfree(portdev) without waiting for existing open file descriptors to be closed.
Even with the kref protecting struct port, could the file operation resume, pass checks, and access port->portdev->vdev or call functions on freed memory like virtqueue_add_outbuf() on port->out_vq?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
PATCH v2 4/4 virtio_console: take a kref in find_port_by_vq() to fix port UAF
In reply to Hari Mishalfind_port_by_vq() returns a raw struct port pointer without taking a reference on it, unlike find_port_by_devt_in_portdev() which does. find_port_by_vq()'s only two callers, in_intr() and out_intr(), run as virtqueue interrupt callbacks, entirely independent of and possibly concurrently with unplug_port(), which itself runs from a workqueue when the host sends a VIRTIO_CONSOLE_PORT_REMOVE control message.
unplug_port() removes the port from portdev->ports under ports_lock, then later drops its last reference with kref_put(), freeing it via remove_port(). find_port_by_vq() also walks portdev->ports under ports_lock, so if it finds the port still on the list, the list removal, and therefore the eventual kref_put(), has not happened yet, and taking a reference at that point is always safe. Without doing so, in_intr()/out_intr() can be left holding a pointer to a port that unplug_port() frees on another core before they are done using it.
Both triggers are host-controlled as the host decides when to send the PORT_REMOVE control message and when to kick the port's data vq. So a malicious backend could race the two on purpose, without any guest side cooperation. The freed object is a generic kmalloc allocation containing a wait_queue_head_t, which in_intr()/out_intr() pass to wake_up_interruptible() after touching the stale pointer. wake_up_interruptible() invokes a function pointer read out of the wait queue's entries. If the freed slab slot is reclaimed with attacker influenced content before that call, then this is an arbitrary function call primitive rather than just undefined behaviour.
Take a reference in find_port_by_vq() while still holding ports_lock, matching find_port_by_devt_in_portdev(), and release it in in_intr() and out_intr() once they are done with the port.
---
v2: reworded the comment above find_port_by_vq() for clarity, no
functional change since v1.
drivers/char/virtio_console.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/char/virtio_console.c +13 -1
@@ -304,6 +304,12 @@ static struct port *find_port_by_id(struct ports_device *portdev, u32 id)return port; } +/* +* Finds a port by the virtqueue and returns a pointer to struct port +* with the reference count incremented. +* +* Callers MUST decrement it when finished. +*/ static struct port *find_port_by_vq (struct ports_device *portdev,struct virtqueue *vq) {
@@ -312,8 +318,10 @@ static struct port *find_port_by_vq(struct ports_device *portdev,spin_lock_irqsave (&portdev->ports_lock, flags);list_for_each_entry (port, &portdev->ports, list) -if (port->in_vq == vq || port->out_vq == vq) +if (port->in_vq == vq || port->out_vq == vq) { +kref_get (&port->kref); goto out; + } port =NULL ; out:spin_unlock_irqrestore (&portdev->ports_lock, flags);
@@ -1706,6 +1714,7 @@ static void out_intr(struct virtqueue *vq) }wake_up_interruptible (&port->waitqueue); +kref_put (&port->kref, remove_port); }static void in_intr (struct virtqueue *vq)
@@ -1723,6 +1732,7 @@ static void in_intr(struct virtqueue *vq)if (!port->portdev) {/* Port is being unplugged, ignore further data. */ spin_unlock_irqrestore (&port->inbuf_lock, flags); +kref_put (&port->kref, remove_port);return ; } port->inbuf =get_inbuf (port);
@@ -1756,6 +1766,8 @@ static void in_intr(struct virtqueue *vq)if (is_console_port (port) &&hvc_poll (port->cons.hvc))hvc_kick (); + +kref_put (&port->kref, remove_port); }static void control_intr (struct virtqueue *vq)
Signature · 1 line
2.43.0