Skip to content

Commit fac6b82

Browse files
willdeaconmstsirkin
authored andcommitted
vsock/virtio: Move SKB allocation lower-bound check to callers
virtio_vsock_alloc_linear_skb() checks that the requested size is at least big enough for the packet header (VIRTIO_VSOCK_SKB_HEADROOM). Of the three callers of virtio_vsock_alloc_linear_skb(), only vhost_vsock_alloc_skb() can potentially pass a packet smaller than the header size and, as it already has a check against the maximum packet size, extend its bounds checking to consider the minimum packet size and remove the check from virtio_vsock_alloc_linear_skb(). Reviewed-by: Stefano Garzarella <[email protected]> Signed-off-by: Will Deacon <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent 2304c64 commit fac6b82

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

drivers/vhost/vsock.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ vhost_vsock_alloc_skb(struct vhost_virtqueue *vq,
344344

345345
len = iov_length(vq->iov, out);
346346

347-
if (len > VIRTIO_VSOCK_MAX_PKT_BUF_SIZE + VIRTIO_VSOCK_SKB_HEADROOM)
347+
if (len < VIRTIO_VSOCK_SKB_HEADROOM ||
348+
len > VIRTIO_VSOCK_MAX_PKT_BUF_SIZE + VIRTIO_VSOCK_SKB_HEADROOM)
348349
return NULL;
349350

350351
/* len contains both payload and hdr */

include/linux/virtio_vsock.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ virtio_vsock_alloc_linear_skb(unsigned int size, gfp_t mask)
5757
{
5858
struct sk_buff *skb;
5959

60-
if (size < VIRTIO_VSOCK_SKB_HEADROOM)
61-
return NULL;
62-
6360
skb = alloc_skb(size, mask);
6461
if (!skb)
6562
return NULL;

0 commit comments

Comments
 (0)