From nobody Tue Nov 26 09:36:07 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=1709120962; cv=none; d=zohomail.com; s=zohoarc; b=WNTEze2goVDWjF3Fi7ppdQGarKwIWP+9x/cq+94rXNZrhPgEwnZw1QjQMmJfDXQ/EvDj1hbdviN4tSoAx3f1CsJOdf/ooBmM0jytjOktg57vI5jQ7pOuxB+v+hcGg2N1/aQs9xK25279oWUe3riL7R6MewqKPsoahF/ex2GJvAQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709120962; 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=ERqbbN2GBkLZQ1HHjRaVA+d7aKobFGUJTjgGsOPEJxA=; b=T2CXxawLEFtHpiVlDKOOqH02SJjCE9FElhFsuArobvVcF5aeuK4Rdrwq1rE9Z1gtWu9dzsZXwOfkNJ4o+vurMWGO131wW5i3MyQmUz1st7qmi4A6lkp4+85j50DgV6OfIK46mxUSTnk0jBtMNaJoKbRAA34s93EkefulL73QMhc= 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 1709120962561149.2145917579736; Wed, 28 Feb 2024 03:49:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfIQT-0002ev-6n; Wed, 28 Feb 2024 06:48:41 -0500 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 1rfIQE-000239-Ch for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:48:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfIQB-00034K-9J for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:48:26 -0500 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-630-fMnTfEsRNmO7mpEDIiNY5g-1; Wed, 28 Feb 2024 06:48:21 -0500 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-7830ab8fb5aso690667985a.2 for ; Wed, 28 Feb 2024 03:48:21 -0800 (PST) Received: from step1.redhat.com (host-82-57-51-64.retail.telecomitalia.it. [82.57.51.64]) by smtp.gmail.com with ESMTPSA id j25-20020a05620a147900b00787ad5ca70fsm4469892qkl.122.2024.02.28.03.48.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 03:48:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709120902; 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=ERqbbN2GBkLZQ1HHjRaVA+d7aKobFGUJTjgGsOPEJxA=; b=aSdK6AlyQLHRnTwars/mXsL8Cr743H7+ni0W3JO33wBIYr/md/mCVIkRwJGAEa7WCzzEMo CEHURWrGBCDdbeHS3F8yFNLh+kIlB6VZIrnEY2Ga5VxatphyHb2Mpla+dCMf5OWEvEEaU3 OlA4Qb4sN6JAlmTBXLqoJbr6Z0hKZIM= X-MC-Unique: fMnTfEsRNmO7mpEDIiNY5g-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709120900; x=1709725700; 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=ERqbbN2GBkLZQ1HHjRaVA+d7aKobFGUJTjgGsOPEJxA=; b=IvviR/Vl/io5UJX7c3PoxtH5yb2D4heBNkAv/Nzhe3AIGW/Ao0KNoP5z1Xy3WaZaYx np32kEjm5GI+y9Hsd26cpUx3s4mjAcblXWIIxPsNGsiKDklAWMOywmTYaHSePe+z+t7j 0Rs9nOOtFBqM27YkwO6WPYGiYUJivUB5Kdfbab7BpKONAh8+ALTIng6oWzph2id2OxGS DHk0nH6ocHBrSL35zOMpVbIxZ96lTbvBXXufZptrQlC9Vs/xy76H5CiSotPjbVDSB9M8 /Uvm0tA2yAJ0DkL/RQLWYwnxnRseoufQYFb1U4IbZECMqWxdWpKm77Q98hrqZetvdQCe xVqw== X-Gm-Message-State: AOJu0YycjTLOwn7ewRR8pKf8+m3tgAvUfCx187hJrYPzrH2yqNV29gXq dFRRb/Cefg8x5BhxCai6bafqGuR9gFWu6OlU/PQJlHNDm7A8MEI4stLY71uuVsm78mCoD5BnxZl vSfB9EA7Cq7GJtYlKsLyVWkTwo/VnSu4jEJpCaED53UhIO7aNlsfi6IQ86nPk+NZg5kRV9FAPM8 djoLpZlDFHU85MilJmGEgD2GROs6GyboAPU8WC X-Received: by 2002:a05:620a:2994:b0:787:870b:3021 with SMTP id r20-20020a05620a299400b00787870b3021mr6252027qkp.25.1709120900619; Wed, 28 Feb 2024 03:48:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IHWCFBKAKLh2a9z+1xczZ5ji44WuCsPiijnvIyXIlLgM8olszwBXmmUP6TBWWSYAvrhcOd1GA== X-Received: by 2002:a05:620a:2994:b0:787:870b:3021 with SMTP id r20-20020a05620a299400b00787870b3021mr6251988qkp.25.1709120900261; Wed, 28 Feb 2024 03:48:20 -0800 (PST) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Paolo Bonzini , qemu-block@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Thomas Huth , "Michael S. Tsirkin" , Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Markus Armbruster , Eric Blake , Coiby Xu , slp@redhat.com, Eduardo Habkost , Hanna Reitz , Igor Mammedov , Raphael Norwitz , Kevin Wolf , David Hildenbrand , stefanha@redhat.com, gmaglione@redhat.com, Stefano Garzarella Subject: [PATCH 2/9] libvhost-user: fail vu_message_write() if sendmsg() is failing Date: Wed, 28 Feb 2024 12:47:52 +0100 Message-ID: <20240228114759.44758-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240228114759.44758-1-sgarzare@redhat.com> References: <20240228114759.44758-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.133.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.102, 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=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: 1709120963673100003 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 --- 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 b9c18eee53..527a550345 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -394,6 +394,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.43.2