From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B275440DFBF for ; Fri, 8 May 2026 16:44:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778258672; cv=none; b=FXGFrC7PClWahuFkdpXw8F/XNcSaNW2ZmoYYCHOFgGGqRLa9txepxNpG5+PHtusra8EBSoUpAeoeb719WfrKGtcEBDRI3h9HvAWBgI2mN2ygHj/iD2J681uoqJNI+TuoABx6499Jvc+a3qjqY8jRtCWlte8h/gv4RbG1EFFFDg8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778258672; c=relaxed/simple; bh=nI6jWfcws3jDGKtVHmRZ+UhUUSG86pLokLto4S1xK2Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HNWdMf+Zz03yy+G+7BQIHr2kpx8VW8B6W5z+HBQQL2DZfNQ2DsxBcLmDnVIeIL6Y3j09lTxR+mjIQCY0mjGWdgHswCUQE0gdT9p8CpYOBJ0njlT8sRKl/7F1K0pdKHomFeERYdEIGzz0McWSuEa90vPUS3XQWvTHorW0AmyCZHE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Lbd3ttdP; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=dDjXC8Xv; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Lbd3ttdP"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="dDjXC8Xv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778258669; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1SGD4ybYlVxcQvNSSgCT46FZDKdy4y6czHmnn+pucYo=; b=Lbd3ttdPX3Q4gHllhXwvL0HUZaC2EqzoyDRn456GtsS5uEO4K0teCc+zyR3BPM0M+58sv7 82Jnik7YvQ4vp/Bhi9SM72lS7Xi0WVVy4KKjPutK6t25ekhlb7jU6Iyaz77TWVe7FkTVNg WRTriHsGECILlnj4ZdO1BkzlqOl4HR8= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-315-euZOhAo7NFeH1_yzhEKhCg-1; Fri, 08 May 2026 12:44:28 -0400 X-MC-Unique: euZOhAo7NFeH1_yzhEKhCg-1 X-Mimecast-MFC-AGG-ID: euZOhAo7NFeH1_yzhEKhCg_1778258667 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-4497a0e3acaso1961435f8f.0 for ; Fri, 08 May 2026 09:44:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778258667; x=1778863467; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1SGD4ybYlVxcQvNSSgCT46FZDKdy4y6czHmnn+pucYo=; b=dDjXC8XvBEQGULjH6G0MmkOHxxPvLx+3PBfZt2Sk56dvFsJLb8v9GCgEmLK/1JrkCz F56nVsyU9+FZ+L1WcUyZz9VksSZ1itXkXo56DrcBnKNxDQUtTZJzAAo6RJb7f+iaq0Kj bWT9/J852PhyXVkL4jqFYlltcU4fCMGGRb2qfxxm73iOTHhGRNlKTZ2pogFIV7tIUsXB NKZxHh3qxUQar9DCIKPc8HC2k4Gb/69fb8MvNx96FNp5c8J0O5aNramQgtqBko4iaOJG lWJ1LtuB7IXW+jnBfXCZssmZ01NZXn1nVNzRQWN/8x4sf2y1D1sshzwNXno60a/nIMVG c7gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778258667; x=1778863467; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=1SGD4ybYlVxcQvNSSgCT46FZDKdy4y6czHmnn+pucYo=; b=bKMJP/QT6Qp5CPUiNtJ8uGZjIzmKZxFr7OncbuF0ifLnHw87fmVJKHqFyAyQBPgOSU hexzaW9WKoX/fhw7kOpeAtvkvvh2I1kMIKBHgE7z+kXUp+RHKZVbl5p5OKn8MawdWY3+ oZJG3/sMQzxw584xeyumJEUc1uhUSXBMzPiPQTD38JG/jlsIkXBiUY8jy4dpVCPmt2Re mq3aNe/yLFMRofn7x0pQAwpcUZKLmaTt6iiLNdWRzZf5SC22XfWhtNyJrgUj4XOrYX/C ej3osTS8ROAxrQUubTmEA45Ag59EdRadBDcpz7uwUabhILRWlHUTZWhHSbcWJ4jD6YCe D/xA== X-Forwarded-Encrypted: i=1; AFNElJ/4DbZbNqezSJA0Drq0aS5GLeqeucEBU27zSC4nNeDN6ctmeySyQ6s+ZGzOyWmsLXySR9Vz3cXzdp/XM5E=@vger.kernel.org X-Gm-Message-State: AOJu0YyjQmIX4OSdw/9XWVLfMXHD5xPvs2i1EuEhifjfZxEVz7aJtm5b JXrHuQqwCwoCzJ7PE+Sgu+20zBjxV6oP46Ky71V4HW5IhUr9St/4GpcpWHdgN5NGzPv60lr+wCl wCd82FWxdySapfROSiihc3Zc55cOf0L3jJ/adx+v32gpYh/sYGIrARKIoi4gTCUw1IA== X-Gm-Gg: Acq92OEl5sBQD0962ZKNwshqj3HNwNZVaVNCN3kjQ0e0PQvcD1DnWADjKS/XrBp+ynk YXk56mMGqW6nwc+eRfeA4E8I1sGTdmqSVG7fBF4QrQ/dH4t2XOLitKc7iaDmfe1j004xRBdE0Gx Q4yF81iIGSbQdExYpgnd/xIhigV1haDvbTNCe/gJFfJG9C120nT5laqFi32Rm66OqQUbYjuHAgT GO9c4lTMD2AALGkeyArixC+jWjpDINM1Flg6hRJ8/gTD2gBpracAubEXYnNDL77yH94p/eytb8G FHMhu09baXty3FyClMVfv7gQtrkN0qMqcfKRreBFAOOK8HpqDwZ4ZZb0YoADoO64HoRiFurG8/c Rd+Rak4dQDbZ1UmRpPRuaJN3Qe+t6/3RuZ3adUbWPR+egGBtIb0cCgQEnG+NtFofYVw== X-Received: by 2002:a5d:5d08:0:b0:44e:1984:5f3e with SMTP id ffacd0b85a97d-4515d3dc343mr20223715f8f.31.1778258665036; Fri, 08 May 2026 09:44:25 -0700 (PDT) X-Received: by 2002:a5d:5d08:0:b0:44e:1984:5f3e with SMTP id ffacd0b85a97d-4515d3dc343mr20223444f8f.31.1778258662937; Fri, 08 May 2026 09:44:22 -0700 (PDT) Received: from stex1.redhat.corp (host-87-11-6-2.retail.telecomitalia.it. [87.11.6.2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4548e6a5b65sm5572801f8f.8.2026.05.08.09.44.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 May 2026 09:44:22 -0700 (PDT) From: Stefano Garzarella To: netdev@vger.kernel.org Cc: Yiqi Sun , Stefano Garzarella , linux-kernel@vger.kernel.org, Xuan Zhuo , "Michael S. Tsirkin" , Stefan Hajnoczi , kvm@vger.kernel.org, Simon Horman , Bobby Eshleman , Jason Wang , Jakub Kicinski , "David S. Miller" , virtualization@lists.linux.dev, Eric Dumazet , Paolo Abeni , Arseniy Krasnov , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Bobby Eshleman Subject: [PATCH net 2/2] vsock/virtio: fix empty payload in tap skb for non-linear buffers Date: Fri, 8 May 2026 18:44:11 +0200 Message-ID: <20260508164411.261440-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260508164411.261440-1-sgarzare@redhat.com> References: <20260508164411.261440-1-sgarzare@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Stefano Garzarella For non-linear skbs, virtio_transport_build_skb() goes through virtio_transport_copy_nonlinear_skb() to copy the original payload in the new skb to be delivered to the vsockmon tap device. This manually initializes an iov_iter but does not set iov_iter.count. Since the iov_iter is zero-initialized, the copy length is zero and no payload is actually copied to the monitor interface, leaving data un-initialized. Fix this by removing the linear vs non-linear split and using skb_copy_datagram_iter() with iov_iter_kvec() for all cases, as vhost-vsock already does. This handles both linear and non-linear skbs, properly initializes the iov_iter, and removes the now unused virtio_transport_copy_nonlinear_skb(). While touching this code, let's also check the return value of skb_copy_datagram_iter(), even though it's unlikely to fail. Fixes: 4b0bf10eb077 ("vsock/virtio: non-linear skb handling for tap") Reported-by: Yiqi Sun Signed-off-by: Stefano Garzarella --- net/vmw_vsock/virtio_transport_common.c | 40 ++++++++----------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c index a678d5d75704..989cc252d3d3 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -136,27 +136,6 @@ static void virtio_transport_init_hdr(struct sk_buff *skb, hdr->fwd_cnt = cpu_to_le32(0); } -static void virtio_transport_copy_nonlinear_skb(const struct sk_buff *skb, - void *dst, - size_t len) -{ - struct iov_iter iov_iter = { 0 }; - struct kvec kvec; - size_t to_copy; - - kvec.iov_base = dst; - kvec.iov_len = len; - - iov_iter.iter_type = ITER_KVEC; - iov_iter.kvec = &kvec; - iov_iter.nr_segs = 1; - - to_copy = min_t(size_t, len, skb->len); - - skb_copy_datagram_iter(skb, VIRTIO_VSOCK_SKB_CB(skb)->offset, - &iov_iter, to_copy); -} - /* Packet capture */ static struct sk_buff *virtio_transport_build_skb(void *opaque) { @@ -214,13 +193,18 @@ static struct sk_buff *virtio_transport_build_skb(void *opaque) skb_put_data(skb, pkt_hdr, sizeof(*pkt_hdr)); if (payload_len) { - if (skb_is_nonlinear(pkt)) { - void *data = skb_put(skb, payload_len); - - virtio_transport_copy_nonlinear_skb(pkt, data, payload_len); - } else { - skb_put_data(skb, pkt->data + VIRTIO_VSOCK_SKB_CB(pkt)->offset, - payload_len); + struct iov_iter iov_iter; + struct kvec kvec; + void *data = skb_put(skb, payload_len); + + kvec.iov_base = data; + kvec.iov_len = payload_len; + iov_iter_kvec(&iov_iter, ITER_DEST, &kvec, 1, payload_len); + + if (skb_copy_datagram_iter(pkt, VIRTIO_VSOCK_SKB_CB(pkt)->offset, + &iov_iter, payload_len)) { + kfree_skb(skb); + return NULL; } } -- 2.54.0