From nobody Sat Apr 11 23:03:19 2026 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1772511518; cv=none; d=zohomail.com; s=zohoarc; b=W4NGjFqDUmpbvsfH9yOdulug9ZSX+8tdXNuCqwLC0akadWaYFUCXqcQpgcrdLoZACnjJ1X/KcCZ3HkXX/gqIW/GEyaAM0DibgPiD5uiwzMcKVm+CzdKkV+8dJoxbVIqZfIZ4SxLTd1T3BjXjIRCN/2SDeJ9nOqZs2u6iqJVIVQI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772511518; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=53zqa3khAxopP2aH9AXDCF45puHjLBt7Xl3ajmc+C4E=; b=ODL4NIP43xPvxbpUXLdKLQFh5AhXHXnUbm2oXq0djcJ+hYVigfq0l13mkYRguMClFaxiqNo6g4gwdV7lvHtfGP610g51TNrPNpPovfkYC1Th9jgJ5ix7bC5n3MFiOVeAevK9zKeVZXo+8+Vihqfrtb6+GKp2iEmmeDsTncMs8jQ= 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 1772511518515612.1378882400502; Mon, 2 Mar 2026 20:18:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vxHCa-0003Ov-8a; Mon, 02 Mar 2026 23:17:44 -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 1vxHCY-0003Ok-V1 for qemu-devel@nongnu.org; Mon, 02 Mar 2026 23:17:42 -0500 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vxHCX-0006Sr-4q for qemu-devel@nongnu.org; Mon, 02 Mar 2026 23:17:42 -0500 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-48373a4bca3so31258065e9.0 for ; Mon, 02 Mar 2026 20:17:40 -0800 (PST) Received: from ST.. ([102.185.186.72]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-483bd765604sm388547795e9.15.2026.03.02.20.17.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Mar 2026 20:17:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772511457; x=1773116257; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=53zqa3khAxopP2aH9AXDCF45puHjLBt7Xl3ajmc+C4E=; b=DMmeETYqz0meHgM3mRgcoUiuuGVfDqBeTkoMF5acCV0a99RlSggN2Eq94knh+NXwUz 6DHejfEBhQUkDQa+vHIzKnoD3EUrK1y7+ntA/xsjy+OABFZ/1qo8tAZS68cKx8LONnsd eqGkOtqb2wTsMJymx3rcTmstsuhLR6VHF/UiUh2+Vv9u42f0Ih3Y39HXQBySt81UG69p sEWfuT2oxUfLPR03vd0YbkEzIbCdvuJ1RXdbxMUzAxHbR6200hnHsqbPXk9rN9PNHnSg cPGYGr4yz4X1BTVOl1Km3dtZFEecwjCyOSr+2iWoYvPGk24Mngqzk3JuYtkzndr4Aemx T/8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772511457; x=1773116257; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=53zqa3khAxopP2aH9AXDCF45puHjLBt7Xl3ajmc+C4E=; b=a1yJf60IIR4NWQ9DWtgOwjAOn/aE/29W7DxVZCbdlcMwGb5lcHOu56BEz5RtKLLh08 VOcXRVVbSKsPg18sTZsFE1mwwLAtveFB0j4XOiMD7skbCK3c4EJ12z8UMJFIOuynJ19h sMOgHzRUuSLEzT5qHMmz2vTrvJLr++xpAav82A3T87uvp9hSw3bx47dAYb09y+gY/7A5 jShoWD23aVi+tqgEmW+fcv87Ep14Bec6pHgDGIWj8MyBtbzfbFL8qoMVSWsQvTcbrSfZ pMJvt/UzkKV+TmpA6OrV5eJlLc2IxDjGmhsgSjDud+pVddn27r6ehi38DFBQfl4G62AQ exzA== X-Gm-Message-State: AOJu0Yzt3lbskiMqE/AP+zZVYZkyrs1RigfsF6E8exXAFxtbsPIOr8ED zslEeMxckUhQHVdwCvuToNGuDfkvZXsWRxu+kUfeLNcuOFlSGBcUkMb8jj6BGdnQ0BRIRg== X-Gm-Gg: ATEYQzx92kKZjsfLY6qzAO0SOjFdPiZ8Zb2NkAbYsj+m1ys9w9XXHZ4PNfsJr5i8/If xFZUvm5w3HEIOX0CKJX/6xnCA25a+ozWWCXmArDMh2cakCDJDVm4WreIk5qkCFU5J/umbK5jfdD +A/zjWOW+N1aE5r54XNXTmAIpo5zE+pzH4lX4B6uZ1/PkNohcBEzAbSDdu3BN7VG1T/OzTfMtlQ 4Hfw+qxjyCFXtlisQ+2LEo1ieeDCkrGJGRwhmGun3Om/vKfTKmU7Z90gx/wfaCjIm6bsJeWPaBe sHunW5DNT8QKx4YGaWppAXteFGbSiccJtLxileEkgzGJ+tXXaPLpviHeNzltcE9+9mNzeGJ4Qr9 RCty8KNf4yONqq5C6PyTgRZGKIh75TJNfbzO2zAdAHTUZ8JYjuwqzt8bFficDI9T4dT5FDj5NAG YjSTiwHggkbAvi++pi4Wv/jBNgqX6W X-Received: by 2002:a05:600c:4f0e:b0:483:702f:4641 with SMTP id 5b1f17b1804b1-483c9b94367mr244616705e9.3.1772511457294; Mon, 02 Mar 2026 20:17:37 -0800 (PST) From: Mohamed Ayman To: qemu-devel@nongnu.org Cc: Mohamed Ayman , "Michael S. Tsirkin" , Stefano Garzarella Subject: [PATCH] vhost-user: document vhost_user_read() message handling Date: Tue, 3 Mar 2026 06:17:23 +0200 Message-Id: <20260303041723.7410-1-mohamedaymanworkspace@gmail.com> X-Mailer: git-send-email 2.34.1 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=2a00:1450:4864:20::32b; envelope-from=mohamedaymanworkspace@gmail.com; helo=mail-wm1-x32b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: qemu development 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 @gmail.com) X-ZM-MESSAGEID: 1772511519804139100 Content-Type: text/plain; charset="utf-8" Add a detailed documentation comment for vhost_user_read() describing its message header validation, payload size checks, and error handling. This clarifies how complete vhost-user messages (header + payload) are read from the character device and how protocol violations are handled. No functional changes. Signed-off-by: Mohamed Ayman --- hw/virtio/vhost-user.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index bb8f8eab77..157a869b35 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -300,6 +300,20 @@ static int vhost_user_read_header(struct vhost_dev *de= v, VhostUserMsg *msg) return 0; } =20 +/** + * vhost_user_read: + * @dev: The vhost device state + * @msg: Pointer to the vhost-user message structure to populate + * + * Reads a complete vhost-user message (header and optional payload) from=20 + * the character device. It first reads and validates the header, checks=20 + * the advertised payload size against maximum bounds, and then reads any=20 + * attached payload directly into the message structure. + * + * Returns: 0 on success, + * -EIO or -errno on read failure or short read, + * -EPROTO if the protocol flags or payload size are invalid. + */ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) { struct vhost_user *u =3D dev->opaque; @@ -307,12 +321,13 @@ static int vhost_user_read(struct vhost_dev *dev, Vho= stUserMsg *msg) uint8_t *p =3D (uint8_t *) msg; int r, size; =20 + /* 1. Read and validate the message header */ r =3D vhost_user_read_header(dev, msg); if (r < 0) { return r; } =20 - /* validate message size is sane */ + /* 2. Validate that the payload size is sane to prevent buffer overflo= ws */ if (msg->hdr.size > VHOST_USER_PAYLOAD_SIZE) { error_report("Failed to read msg header." " Size %d exceeds the maximum %zu.", msg->hdr.size, @@ -320,9 +335,13 @@ static int vhost_user_read(struct vhost_dev *dev, Vhos= tUserMsg *msg) return -EPROTO; } =20 + /* 3. If the header indicates a payload exists, read it */ if (msg->hdr.size) { + /* Advance the pointer to the start of the payload section */ p +=3D VHOST_USER_HDR_SIZE; size =3D msg->hdr.size; + =20 + /* Block and read the exact payload size */ r =3D qemu_chr_fe_read_all(chr, p, size); if (r !=3D size) { int saved_errno =3D errno; --=20 2.34.1