From nobody Mon Nov 25 15:50:28 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1715154518; cv=none; d=zohomail.com; s=zohoarc; b=laF/535edOmEX9k4Ao0PHUbGuY9+J76r2HkcIWk+SPX2SBzyH53E+dLsIDR5trA0kfDRS9mmurpHUmEkGqVghv0PipMJX5/zzacNT/80JdvXemnbLtDpm0oGyiXg5Wne0u58lfIFR7KXwfczNshAZuvwNhqvnDl2AEy59JtSqzs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715154518; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Vs3QOPT0b+rkefawz4PPNw8XtECEjgm+FjXJsIBmtfo=; b=XxiGa9hgG9dne6PEgM9nUsX8lOz4/gF77u7XrOuRAnC5uSxwDL5G7uJQwQR9dt298kwgK8AgMebTRe5FQppWmz0RiJJofhMjjsRTXnd4QIvyGu1E0L4QPGLRZ3A4i4Nh0/Gtz39g1jXDyAySmDo26uZfcSn7PAZKaSQzIhNuNkU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1715154518630905.9153453968975; Wed, 8 May 2024 00:48:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4bzs-0003az-8C; Wed, 08 May 2024 03:45:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4bzS-0003SE-Bn for qemu-devel@nongnu.org; Wed, 08 May 2024 03:45:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4bzO-0000q6-H0 for qemu-devel@nongnu.org; Wed, 08 May 2024 03:45:25 -0400 Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-33-LizKm5plOdKsxa1X90lQtg-1; Wed, 08 May 2024 03:45:15 -0400 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-572b3091d68so2349579a12.2 for ; Wed, 08 May 2024 00:45:15 -0700 (PDT) Received: from localhost.localdomain (host-87-12-25-56.business.telecomitalia.it. [87.12.25.56]) by smtp.gmail.com with ESMTPSA id bt9-20020a0564020a4900b005729c4c2501sm7303585edb.24.2024.05.08.00.45.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 00:45:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715154317; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Vs3QOPT0b+rkefawz4PPNw8XtECEjgm+FjXJsIBmtfo=; b=i5fMwZrFIGxXV/Uqcfj3hDCQz7qOiF8nWPf8NBRGd5uiEEBbJRnvGI4ZNIkS+yuXuApmtR 2anxvrRIveFhxRyOfrBKbz86pTMDoq8h/FZ8ul3VF5I3RFHYCbhzpEiRgMzLJ2wF/1KbIQ 7/1COt/PS23FKaD7kQ5VWA+DYoAOhYE= X-MC-Unique: LizKm5plOdKsxa1X90lQtg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715154314; x=1715759114; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Vs3QOPT0b+rkefawz4PPNw8XtECEjgm+FjXJsIBmtfo=; b=d/hwByzQa/L3J5cG2xyondP8wIrYm9SZBIfet1OKqDPF7z+cn75LZ0OLqk6QgQqw+t gzY0Z9koa0+r25/Azrcgpmq2JtBTvl9RAOqSH3BlvbehsXjwMWdoJtRQ2Uj81fYa5Sn2 s3hQLrWS76JuHxcc80qFAdcJl9J+FPvKJE9khOFeLpEnrJd8OPmXZ+CKkFzvFvTBlGRl Cn6ltG5vSMUAFFuw1/Ugd2EO14fx0YRMfXJ7AfFMo7fQ7wOBz9SomwN7VmvHrBKpn3VA 1qayeLnBGFWvG2mg2TWQrpdhZmxlwD70fIdRGI0NElsW3uFngWmTBGrx7QnG+hpPxdvs 0s2w== X-Gm-Message-State: AOJu0YwSF5IY3kKX2GNOQv3uPw+rSW6X3Z0AqnUDW5D9dkWti9Ny/zsK GqV/ie5v3HvUgoQNcFDDh6/IqMAtPJz87szKIT/KDYo3dki8DsQ8PSq7Mbixo3HUs8JGE9lPhc2 0FIbQiiOzpQV3BD3+smG28/tNTv6YcmeIHAQs30rg0CkoOhY5Ff7FJCxnV8413JKMRZpSm6P9UC wis7GMa+ZcLTc3Spqivm3I3xD6W3XvDPK62+e1 X-Received: by 2002:a50:9317:0:b0:572:8aab:441c with SMTP id 4fb4d7f45d1cf-5731da5b65amr1253646a12.26.1715154314054; Wed, 08 May 2024 00:45:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEHrsrWeJgIT3Ek9Coozq8NQkbRqXhAGzux1zrYc55O/lshafDqRssXbCHqeprmjqg24zdK3A== X-Received: by 2002:a50:9317:0:b0:572:8aab:441c with SMTP id 4fb4d7f45d1cf-5731da5b65amr1253613a12.26.1715154313727; Wed, 08 May 2024 00:45:13 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Jason Wang , Coiby Xu , Paolo Bonzini , qemu-block@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Gerd Hoffmann , slp@redhat.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Brad Smith , Eduardo Habkost , Thomas Huth , Eric Blake , Kevin Wolf , Markus Armbruster , Raphael Norwitz , gmaglione@redhat.com, Laurent Vivier , stefanha@redhat.com, David Hildenbrand , Hanna Reitz , "Michael S. Tsirkin" , Igor Mammedov , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Stefano Garzarella Subject: [PATCH v4 02/12] libvhost-user: fail vu_message_write() if sendmsg() is failing Date: Wed, 8 May 2024 09:44:46 +0200 Message-ID: <20240508074457.12367-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240508074457.12367-1-sgarzare@redhat.com> References: <20240508074457.12367-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1715154520455100003 Content-Type: text/plain; charset="utf-8" In vu_message_write() we use sendmsg() to send the message header, then a write() to send the payload. If sendmsg() fails we should avoid sending the payload, since we were unable to send the header. Discovered before fixing the issue with the previous patch, where sendmsg() failed on macOS due to wrong parameters, but the frontend still sent the payload which the backend incorrectly interpreted as a wrong header. Signed-off-by: Stefano Garzarella Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 --- subprojects/libvhost-user/libvhost-user.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvho= st-user/libvhost-user.c index 22bea0c775..a11afd1960 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -639,6 +639,11 @@ vu_message_write(VuDev *dev, int conn_fd, VhostUserMsg= *vmsg) rc =3D sendmsg(conn_fd, &msg, 0); } while (rc < 0 && (errno =3D=3D EINTR || errno =3D=3D EAGAIN)); =20 + if (rc <=3D 0) { + vu_panic(dev, "Error while writing: %s", strerror(errno)); + return false; + } + if (vmsg->size) { do { if (vmsg->data) { --=20 2.45.0