Skip to contentSkip to conversation

virtio: reject shm region if length is zero

PATCH Superseded Sami Uddin [email protected] 2 participants 2 messages May 11, 2025 virtio core

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Sami Uddin [email protected]

author
#0 lore raw

PATCH v2 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.

---
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..b641b16d42ef 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 == 0)
+		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
#1 lore raw
Quoted 18 lines · On Sun, May 11, 2025 at 09:14:28PM +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.

---
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 +0 -0
index 169c7d367fac..b641b16d42ef 100644

include/linux/virtio_config.h static inline · line 333

Quoted 5 lines
include/linux/virtio_config.h +2 -0
@@ -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 == 0)
+		return false;

if (!region->len)

is more idiomatic

Quoted 5 lines
include/linux/virtio_config.h +0 -0
 	if (!vdev->config->get_shm_region)
 		return false;
 	return vdev->config->get_shm_region(vdev, region, id);
Signature · 1 line
2.34.1