Skip to content

Commit 7eba653

Browse files
jasowanggregkh
authored andcommitted
vhost_net: validate sock before trying to put its fd
[ Upstream commit b8f1f65 ] Sock will be NULL if we pass -1 to vhost_net_set_backend(), but when we meet errors during ubuf allocation, the code does not check for NULL before calling sockfd_put(), this will lead NULL dereferencing. Fixing by checking sock pointer before. Fixes: bab632d ("vhost: vhost TX zero-copy support") Reported-by: Dan Carpenter <[email protected]> Signed-off-by: Jason Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 2dc4696 commit 7eba653

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/vhost/net.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,8 @@ static long vhost_net_set_backend(struct vhost_net *n, unsigned index, int fd)
11861186
if (ubufs)
11871187
vhost_net_ubuf_put_wait_and_free(ubufs);
11881188
err_ubufs:
1189-
sockfd_put(sock);
1189+
if (sock)
1190+
sockfd_put(sock);
11901191
err_vq:
11911192
mutex_unlock(&vq->mutex);
11921193
err:

0 commit comments

Comments
 (0)