]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
virtio_net: Add hash_key_length check
authorPhilo Lu <lulie@linux.alibaba.com>
Mon, 4 Nov 2024 08:57:04 +0000 (16:57 +0800)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 7 Nov 2024 11:40:10 +0000 (12:40 +0100)
Add hash_key_length check in virtnet_probe() to avoid possible out of
bound errors when setting/reading the hash key.

Fixes: c7114b1249fa ("drivers/net/virtio_net: Added basic RSS support.")
Signed-off-by: Philo Lu <lulie@linux.alibaba.com>
Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Acked-by: Joe Damato <jdamato@fastly.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/virtio_net.c

index 4b507007d242b82ad79bc3dce7955350c8e79b6e..545dda8ec07754145f895ec44a9b942d6e24ef20 100644 (file)
@@ -6451,6 +6451,12 @@ static int virtnet_probe(struct virtio_device *vdev)
        if (vi->has_rss || vi->has_rss_hash_report) {
                vi->rss_key_size =
                        virtio_cread8(vdev, offsetof(struct virtio_net_config, rss_max_key_size));
+               if (vi->rss_key_size > VIRTIO_NET_RSS_MAX_KEY_SIZE) {
+                       dev_err(&vdev->dev, "rss_max_key_size=%u exceeds the limit %u.\n",
+                               vi->rss_key_size, VIRTIO_NET_RSS_MAX_KEY_SIZE);
+                       err = -EINVAL;
+                       goto free;
+               }
 
                vi->rss_hash_types_supported =
                    virtio_cread32(vdev, offsetof(struct virtio_net_config, supported_hash_types));