Skip to contentSkip to conversation

virtio: reject shm region if length is zero

PATCH In review Sami Uddin [email protected] 4 participants 7 messages May 11, 2025 – Aug 16, 2025

Subsystems (2)
lore
Share & tools
lore

Sami Uddin [email protected]

author
#0 lore raw

PATCH v3 1/1 virtio: reject shm region if length is zero

From: Sami Uddin <[email protected]>

Prevent usage of shared memory regions where the length is zero, as such configurations are not valid and may lead to unexpected behavior.

---
v3:
- Use idiomatic 'if (!region->len)' as suggested by reviewer v2:
- Fixed coding style issue: added space after 'if' statement

 include/linux/virtio_config.h | 2 ++
 1 file changed, 2 insertions(+)
include/linux/virtio_config.h +2 -0
index 169c7d367fac..b3e1d30c765b 100644
@@ -329,6 +329,8 @@ static inline
 bool virtio_get_shm_region(struct virtio_device *vdev,
 			   struct virtio_shm_region *region, u8 id)
 {
+	if (!region->len)
+		return false;
 	if (!vdev->config->get_shm_region)
 		return false;
 	return vdev->config->get_shm_region(vdev, region, id);
Signature · 1 line
2.34.1
Acked-by on v3 1/1
#1 lore raw
Quoted 30 lines · Sami Uddin

From: Sami Uddin <[email protected]>

Prevent usage of shared memory regions where the length is zero, as such configurations are not valid and may lead to unexpected behavior.

---
v3:
- Use idiomatic 'if (!region->len)' as suggested by reviewer v2:
- Fixed coding style issue: added space after 'if' statement

 include/linux/virtio_config.h | 2 ++
 1 file changed, 2 insertions(+)
include/linux/virtio_config.h +2 -1
index 169c7d367fac..b3e1d30c765b 100644
@@ -329,6 +329,8 @@ static inline
 bool virtio_get_shm_region(struct virtio_device *vdev,
                           struct virtio_shm_region *region, u8 id)
 {
+       if (!region->len)
+               return false;
        if (!vdev->config->get_shm_region)
                return false;
        return vdev->config->get_shm_region(vdev, region, id);
--
Quoted 2 lines

2.34.1

Thanks

#2 lore raw
In reply to Sami Uddin [email protected]
Quoted 6 lines · On Mon, May 12, 2025 at 07:51:53AM +0930, [email protected] wrote:

From: Sami Uddin <[email protected]>

Prevent usage of shared memory regions where the length is zero, as such configurations are not valid and may lead to unexpected behavior.

Quoted 8 lines

---
v3:
- Use idiomatic 'if (!region->len)' as suggested by reviewer v2:
- Fixed coding style issue: added space after 'if' statement

 include/linux/virtio_config.h | 2 ++
 1 file changed, 2 insertions(+)

Hi, I'm sorry to be the bearer of bad news, but since this patch my VM no longer works. The system is running wayland-proxy-virtwl[1] inside a crosvm[2] VM, using crosvm's virtio-gpu device to do cross-domain Wayland forwarding.

Since this change, wayland-proxy-virtwl crashes with the following log message:

wl-proxy [WARNING]: Error handling client: Unix.Unix_error(Unix.EINVAL, "DRM_IOCTL_VIRTGPU_RESOURCE_CREATE_BLOB", "")

I'm pretty confused by what this change was supposed to do in the first place… Looking at how virtio_get_shm_region() is used in virtio_gpu_init(), it's called with a pointer to zeroed memory, and then the get_shm_region() implementation is supposed to write to the region, without ever reading from it as far as I can tell. Why is the initial value of an out parameter being checked at all? How does this prevent using zero-length shared memory regions?

[1]: https://crosvm.dev/
[2]: https://github.com/talex5/wayland-proxy-virtwl

#regzbot introduced: 206cc44588f72b49ad4d7e21a7472ab2a72a83df

Quoted 16 lines
include/linux/virtio_config.h +2 -1
index 169c7d367fac..b3e1d30c765b 100644
@@ -329,6 +329,8 @@ static inline
 bool virtio_get_shm_region(struct virtio_device *vdev,
 			   struct virtio_shm_region *region, u8 id)
 {
+	if (!region->len)
+		return false;
 	if (!vdev->config->get_shm_region)
 		return false;
 	return vdev->config->get_shm_region(vdev, region, id);
--

2.34.1

#3 lore raw
Quoted 34 lines · Alyssa Ross
Quoted 6 lines · On Mon, May 12, 2025 at 07:51:53AM +0930, [email protected] wrote:

From: Sami Uddin <[email protected]>

Prevent usage of shared memory regions where the length is zero, as such configurations are not valid and may lead to unexpected behavior.

Quoted 8 lines

---
v3:
- Use idiomatic 'if (!region->len)' as suggested by reviewer v2:
- Fixed coding style issue: added space after 'if' statement

 include/linux/virtio_config.h | 2 ++
 1 file changed, 2 insertions(+)

Hi, I'm sorry to be the bearer of bad news, but since this patch my VM no longer works. The system is running wayland-proxy-virtwl[1] inside a crosvm[2] VM, using crosvm's virtio-gpu device to do cross-domain Wayland forwarding.

Since this change, wayland-proxy-virtwl crashes with the following log message:

wl-proxy [WARNING]: Error handling client: Unix.Unix_error(Unix.EINVAL, "DRM_IOCTL_VIRTGPU_RESOURCE_CREATE_BLOB", "")

I'm pretty confused by what this change was supposed to do in the first place… Looking at how virtio_get_shm_region() is used in virtio_gpu_init(), it's called with a pointer to zeroed memory, and then the get_shm_region() implementation is supposed to write to the region, without ever reading from it as far as I can tell. Why is the initial value of an out parameter being checked at all? How does this prevent using zero-length shared memory regions?

Quoted 4 lines

[1]: https://crosvm.dev/
[2]: https://github.com/talex5/wayland-proxy-virtwl

#regzbot introduced: 206cc44588f72b49ad4d7e21a7472ab2a72a83df

Okay, just found that it's already been reverted:
https://lore.kernel.org/all/[email protected]/

Still, I'm confused how this was supposed to fix anything…

#regzbot fix: Revert "virtio: reject shm region if length is zero"

#4 lore raw
Quoted 39 lines · Alyssa Ross
Quoted 37 lines · Alyssa Ross
Quoted 6 lines · On Mon, May 12, 2025 at 07:51:53AM +0930, [email protected] wrote:

From: Sami Uddin <[email protected]>

Prevent usage of shared memory regions where the length is zero, as such configurations are not valid and may lead to unexpected behavior.

Quoted 8 lines

---
v3:
- Use idiomatic 'if (!region->len)' as suggested by reviewer v2:
- Fixed coding style issue: added space after 'if' statement

 include/linux/virtio_config.h | 2 ++
 1 file changed, 2 insertions(+)

Hi, I'm sorry to be the bearer of bad news, but since this patch my VM no longer works. The system is running wayland-proxy-virtwl[1] inside a crosvm[2] VM, using crosvm's virtio-gpu device to do cross-domain Wayland forwarding.

Since this change, wayland-proxy-virtwl crashes with the following log message:

wl-proxy [WARNING]: Error handling client: Unix.Unix_error(Unix.EINVAL, "DRM_IOCTL_VIRTGPU_RESOURCE_CREATE_BLOB", "")

I'm pretty confused by what this change was supposed to do in the first place… Looking at how virtio_get_shm_region() is used in virtio_gpu_init(), it's called with a pointer to zeroed memory, and then the get_shm_region() implementation is supposed to write to the region, without ever reading from it as far as I can tell. Why is the initial value of an out parameter being checked at all? How does this prevent using zero-length shared memory regions?

[1]: https://crosvm.dev/
[2]: https://github.com/talex5/wayland-proxy-virtwl

Quoted 8 lines
Quoted 1 line

#regzbot introduced: 206cc44588f72b49ad4d7e21a7472ab2a72a83df

Okay, just found that it's already been reverted:
https://lore.kernel.org/all/[email protected]/

Still, I'm confused how this was supposed to fix anything…

#regzbot fix: Revert "virtio: reject shm region if length is zero"

Are you asking why was the patch applied in the 1st place? It seemed like an invalid behaviour to me, and I thought it's not too late to block it so we don't need to support it down the road.

Signature · 1 line
MST
#5 lore raw
Quoted 47 lines · Michael S. Tsirkin
Quoted 46 lines · Alyssa Ross
Quoted 34 lines · Alyssa Ross
Quoted 6 lines · On Mon, May 12, 2025 at 07:51:53AM +0930, [email protected] wrote:

From: Sami Uddin <[email protected]>

Prevent usage of shared memory regions where the length is zero, as such configurations are not valid and may lead to unexpected behavior.

Quoted 8 lines

---
v3:
- Use idiomatic 'if (!region->len)' as suggested by reviewer v2:
- Fixed coding style issue: added space after 'if' statement

 include/linux/virtio_config.h | 2 ++
 1 file changed, 2 insertions(+)

Hi, I'm sorry to be the bearer of bad news, but since this patch my VM no longer works. The system is running wayland-proxy-virtwl[1] inside a crosvm[2] VM, using crosvm's virtio-gpu device to do cross-domain Wayland forwarding.

Since this change, wayland-proxy-virtwl crashes with the following log message:

wl-proxy [WARNING]: Error handling client: Unix.Unix_error(Unix.EINVAL, "DRM_IOCTL_VIRTGPU_RESOURCE_CREATE_BLOB", "")

I'm pretty confused by what this change was supposed to do in the first place… Looking at how virtio_get_shm_region() is used in virtio_gpu_init(), it's called with a pointer to zeroed memory, and then the get_shm_region() implementation is supposed to write to the region, without ever reading from it as far as I can tell. Why is the initial value of an out parameter being checked at all? How does this prevent using zero-length shared memory regions?

Quoted 4 lines

[1]: https://crosvm.dev/
[2]: https://github.com/talex5/wayland-proxy-virtwl

#regzbot introduced: 206cc44588f72b49ad4d7e21a7472ab2a72a83df

Okay, just found that it's already been reverted:
https://lore.kernel.org/all/[email protected]/

Still, I'm confused how this was supposed to fix anything…

Quoted 8 lines
Quoted 1 line

#regzbot fix: Revert "virtio: reject shm region if length is zero"

Are you asking why was the patch applied in the 1st place? It seemed like an invalid behaviour to me, and I thought it's not too late to block it so we don't need to support it down the road.

So you just weren't aware during the review that it's an output parameter rather than an input? Should the parameter maybe be renamed or something to make that more obvious?

#6 lore raw
Quoted 53 lines · Alyssa Ross
Quoted 51 lines · Michael S. Tsirkin
Quoted 47 lines · Alyssa Ross
Quoted 34 lines · Alyssa Ross
Quoted 6 lines · On Mon, May 12, 2025 at 07:51:53AM +0930, [email protected] wrote:

From: Sami Uddin <[email protected]>

Prevent usage of shared memory regions where the length is zero, as such configurations are not valid and may lead to unexpected behavior.

Quoted 8 lines

---
v3:
- Use idiomatic 'if (!region->len)' as suggested by reviewer v2:
- Fixed coding style issue: added space after 'if' statement

 include/linux/virtio_config.h | 2 ++
 1 file changed, 2 insertions(+)

Hi, I'm sorry to be the bearer of bad news, but since this patch my VM no longer works. The system is running wayland-proxy-virtwl[1] inside a crosvm[2] VM, using crosvm's virtio-gpu device to do cross-domain Wayland forwarding.

Since this change, wayland-proxy-virtwl crashes with the following log message:

wl-proxy [WARNING]: Error handling client: Unix.Unix_error(Unix.EINVAL, "DRM_IOCTL_VIRTGPU_RESOURCE_CREATE_BLOB", "")

I'm pretty confused by what this change was supposed to do in the first place… Looking at how virtio_get_shm_region() is used in virtio_gpu_init(), it's called with a pointer to zeroed memory, and then the get_shm_region() implementation is supposed to write to the region, without ever reading from it as far as I can tell. Why is the initial value of an out parameter being checked at all? How does this prevent using zero-length shared memory regions?

Quoted 4 lines

[1]: https://crosvm.dev/
[2]: https://github.com/talex5/wayland-proxy-virtwl

#regzbot introduced: 206cc44588f72b49ad4d7e21a7472ab2a72a83df

Okay, just found that it's already been reverted:
https://lore.kernel.org/all/[email protected]/

Still, I'm confused how this was supposed to fix anything…

#regzbot fix: Revert "virtio: reject shm region if length is zero"

Quoted 8 lines
Quoted 4 lines

Are you asking why was the patch applied in the 1st place? It seemed like an invalid behaviour to me, and I thought it's not too late to block it so we don't need to support it down the road.

So you just weren't aware during the review that it's an output parameter rather than an input? Should the parameter maybe be renamed or something to make that more obvious?

Sounds like a good idea.

Signature · 1 line
MST