From patchwork Wed Jun 12 13:01:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 1946853 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=g/Jjp/MU; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Vzm1Y75gCz20Pb for ; Wed, 12 Jun 2024 23:03:13 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sHNcP-0003Td-U9; Wed, 12 Jun 2024 09:02:25 -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 1sHNcN-0003RE-HM for qemu-devel@nongnu.org; Wed, 12 Jun 2024 09:02:23 -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 1sHNcL-00082k-TQ for qemu-devel@nongnu.org; Wed, 12 Jun 2024 09:02:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718197341; 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=Su7ClX2VsFIEko0OXJVvgHI4Li50SabFJTO7o/P9fMs=; b=g/Jjp/MUT9cmEymAuu1oTMstFVioDCArQ905CPOg/xCIWPiVO4kqfop+5hIe5DWU/a4O0p cLd5+EPPM/qZQQEYc5MpIeUZBoH8sVkETse+Eqp6cuLMCt+M8lp7cI/8yTTD+qy91vp5OQ +JU47zf5fn94goL6XumAL+q80qvNoUE= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-681-otdwcqrwNoeLinQ4Gj14OA-1; Wed, 12 Jun 2024 09:02:19 -0400 X-MC-Unique: otdwcqrwNoeLinQ4Gj14OA-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-4406476507cso20626791cf.3 for ; Wed, 12 Jun 2024 06:02:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718197339; x=1718802139; 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=Su7ClX2VsFIEko0OXJVvgHI4Li50SabFJTO7o/P9fMs=; b=UB6PqWib4hJuOVuxNe1wEWEPVe8u8w0iu4Oqr26OBAC3IUr33md37MF496kg+Rd7P+ IUvSzHG/+ETlxN/IyJWnHyoWx+DAfiRBLmbdgskdQPt1Lb7vRMA/Vj63ICf31NG7gmw7 ZRy07zPv1GskjSmpaYrWhyZFxMFRQkAcEiXq5GLf7o506cFVb6klN6O5V145lqTsD34a bp539VWUVTEp4oMQPAecbTCxYWt8i2F7RpFAIqk1ct0CmMEqfXnUmuqnSyWM2mituwE3 aMTtfiiLXLQiYjB42gbGXICKpwhHdm4ShHNKOTHPgHTutEiKb9ioUELTKgFLWJBTkRVa KBGA== X-Forwarded-Encrypted: i=1; AJvYcCVfZnz/Gk9fImFCbbZcLWB4U6bYWPq4BpWJ3y8Qb79qks268l3kokhySLvNFMxpfqULPW+7+2uabWLtEZx/ILFOCgovBrc= X-Gm-Message-State: AOJu0YwFaGqMp4YWVtf/zmKTkjbnSWIwhZvnmFgGCd5ODD66GN+rUpDG gUy0qMF3QgZH8ZPfAcGZRsn7sHRKxY+aPHuIIsImu8y1PgW108AaooNvmWUYZmL3lbszZv6ozS0 LL9f7qJU1jES6R0/17arvAvlyg9027wPTOUwWaaVZadTdgs00WAyC X-Received: by 2002:a05:6214:3291:b0:6b0:8b40:c7e0 with SMTP id 6a1803df08f44-6b1a731b7d6mr18097986d6.44.1718197338850; Wed, 12 Jun 2024 06:02:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEderl/MfePzFiHQ2ncxEuElJrm+4BKYlXdhuE/JLFmI8+4UqTQNNgTmOVLm1w6aUl87AC0UQ== X-Received: by 2002:a05:6214:3291:b0:6b0:8b40:c7e0 with SMTP id 6a1803df08f44-6b1a731b7d6mr18097576d6.44.1718197338326; Wed, 12 Jun 2024 06:02:18 -0700 (PDT) Received: from step1.redhat.com ([193.207.132.52]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b07a727eb8sm33527016d6.9.2024.06.12.06.02.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 06:02:16 -0700 (PDT) From: Stefano Garzarella To: mst@redhat.com, qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Brad Smith , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Marc?= =?utf-8?q?-Andr=C3=A9_Lureau?= , Laurent Vivier , gmaglione@redhat.com, stefanha@redhat.com, Coiby Xu , Gerd Hoffmann , slp@redhat.com, Igor Mammedov , Raphael Norwitz , Thomas Huth , Eduardo Habkost , David Hildenbrand , Kevin Wolf , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Jason Wang , Markus Armbruster , Eric Blake , Stefano Garzarella Subject: [PATCH RESEND v7 02/12] libvhost-user: fail vu_message_write() if sendmsg() is failing Date: Wed, 12 Jun 2024 15:01:30 +0200 Message-ID: <20240612130140.63004-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240612130140.63004-1-sgarzare@redhat.com> References: <20240612130140.63004-1-sgarzare@redhat.com> MIME-Version: 1.0 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: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.143, 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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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. Reviewed-by: Daniel P. Berrangé Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Acked-by: Stefan Hajnoczi Reviewed-by: David Hildenbrand Signed-off-by: Stefano Garzarella --- subprojects/libvhost-user/libvhost-user.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-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 = sendmsg(conn_fd, &msg, 0); } while (rc < 0 && (errno == EINTR || errno == EAGAIN)); + if (rc <= 0) { + vu_panic(dev, "Error while writing: %s", strerror(errno)); + return false; + } + if (vmsg->size) { do { if (vmsg->data) {