From mboxrd@z Thu Jan  1 00:00:00 1970
Authentication-Results: passt.top; dmarc=pass (p=none dis=none) header.from=redhat.com
Authentication-Results: passt.top;
	dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=aRnXx573;
	dkim-atps=neutral
Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124])
	by passt.top (Postfix) with ESMTP id 386935A004E
	for <passt-dev@passt.top>; Thu, 12 Sep 2024 15:36:43 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
	s=mimecast20190719; t=1726148202;
	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=r6I5aja1oOSn4S99bbHIe76/hhhOnx1SuPCZscSC354=;
	b=aRnXx5739JPy4p35ogZQrqoa05vmGdDIPS5hw+rK3Wk8rRyEPgt1JQTImiVk/4I9QzGgs5
	UYnEL9hKWCb5NCgXQqSti+P2ev0veQsBoGw61421RVUqaiVd7Kn4a1TM9oywltfGOlsFKB
	Grio7EEu9yjqLgJhiaPegJ0IndNXWdQ=
Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com
 [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS
 (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id
 us-mta-595-CIko2f7PODmol39Z2SmSAA-1; Thu, 12 Sep 2024 09:36:39 -0400
X-MC-Unique: CIko2f7PODmol39Z2SmSAA-1
Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-42cb6ed7f9dso8315685e9.3
        for <passt-dev@passt.top>; Thu, 12 Sep 2024 06:36:38 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1726148196; x=1726752996;
        h=content-transfer-encoding:mime-version:organization:references
         :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state
         :from:to:cc:subject:date:message-id:reply-to;
        bh=r6I5aja1oOSn4S99bbHIe76/hhhOnx1SuPCZscSC354=;
        b=UuqmmDh0MpQCeiFiOX1YyXc7HhZutDNk8IIwSn2qjZbfsTD4DDNdL/artOnzR7XVE0
         pG3VzhG84qS0ZCBagGqQg2y6Rttvtf4U6V/4XbgMAH97aQHlx2Wjy36GZoRPhfs0H1Dp
         Q1us9U68E2+J2TbkuBz36aFJ+x14qc1GIEvnPu2l+RshscasaIS+yBSlaXdNM3qtE2al
         c+N0lOyHWOTnYX0klaE2q3i4j3/78wliEI+1BBbx+tgT+XiAm7LiLHJeXA1xgFRak/F7
         +bQUKj7dWsTTI1uL9WCs9gNB+n1Es7sbiCB17ZGb0eHCvQfnODqPn3TLcICoxU4wH+y7
         gg5g==
X-Gm-Message-State: AOJu0Yyi9XYcUqrV3mf/vS6lWjZXMlSy5AuoYt/ZnrIHB5SGVxebWozi
	0T28s+o8aozgQpwxwk6xi30iBnyqWNUJxpzPqJIW1NL3mdUZ91EWZm4VpgreLYWQ5ZfZJmeJZEb
	D+xX+0R/ygonIlXvGSCgjLX9dmKcyfsCClYqScspt9vKDd+aOID09nSMiJpDoPShoAwjLU0Exq+
	XdfqODy4mt00uqYS9yl/tyrBDrO1/iLh24
X-Received: by 2002:a05:600c:1c27:b0:426:62c5:4731 with SMTP id 5b1f17b1804b1-42cdb579f50mr28567515e9.29.1726148195837;
        Thu, 12 Sep 2024 06:36:35 -0700 (PDT)
X-Google-Smtp-Source: AGHT+IH4gL1Df34/kBO9kgLfSke1bRV1fWD14LpWpGJ/s1ICEwNDFtvzIyrcdpW21xG5yDFsgePKrQ==
X-Received: by 2002:a05:600c:1c27:b0:426:62c5:4731 with SMTP id 5b1f17b1804b1-42cdb579f50mr28567005e9.29.1726148194900;
        Thu, 12 Sep 2024 06:36:34 -0700 (PDT)
Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1])
        by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37895676093sm14372086f8f.65.2024.09.12.06.36.33
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 12 Sep 2024 06:36:33 -0700 (PDT)
Date: Thu, 12 Sep 2024 15:36:32 +0200
From: Stefano Brivio <sbrivio@redhat.com>
To: Laurent Vivier <lvivier@redhat.com>
Subject: Re: [PATCH v4 2/4] vhost-user: introduce virtio API
Message-ID: <20240912153632.66e880b1@elisabeth>
In-Reply-To: <e08f5076-7ff4-490e-bae4-a90edceaa3c7@redhat.com>
References: <20240906160455.2088854-1-lvivier@redhat.com>
	<20240906160455.2088854-3-lvivier@redhat.com>
	<20240910174731.3c4db56f@elisabeth>
	<e08f5076-7ff4-490e-bae4-a90edceaa3c7@redhat.com>
Organization: Red Hat
X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu)
MIME-Version: 1.0
X-Mimecast-Spam-Score: 0
X-Mimecast-Originator: redhat.com
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Message-ID-Hash: ZDM5TUEWBZXH7IBJ4CJNUEW523BHXY7X
X-Message-ID-Hash: ZDM5TUEWBZXH7IBJ4CJNUEW523BHXY7X
X-MailFrom: sbrivio@redhat.com
X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header
CC: passt-dev@passt.top
X-Mailman-Version: 3.3.8
Precedence: list
List-Id: Development discussion and patches for passt <passt-dev.passt.top>
Archived-At: <https://archives.passt.top/passt-dev/20240912153632.66e880b1@elisabeth/>
Archived-At: <https://passt.top/hyperkitty/list/passt-dev@passt.top/message/ZDM5TUEWBZXH7IBJ4CJNUEW523BHXY7X/>
List-Archive: <https://archives.passt.top/passt-dev/>
List-Archive: <https://passt.top/hyperkitty/list/passt-dev@passt.top/>
List-Help: <mailto:passt-dev-request@passt.top?subject=help>
List-Owner: <mailto:passt-dev-owner@passt.top>
List-Post: <mailto:passt-dev@passt.top>
List-Subscribe: <mailto:passt-dev-join@passt.top>
List-Unsubscribe: <mailto:passt-dev-leave@passt.top>

On Thu, 12 Sep 2024 13:23:58 +0200
Laurent Vivier <lvivier@redhat.com> wrote:

> On 10/09/2024 17:47, Stefano Brivio wrote:
> >> +
> >> +/**
> >> + * virtqueue_read_indirect_desc() - Copy virtio ring descriptors from guest
> >> + *                                  memory
> >> + * @dev:	Vhost-user device
> >> + * @desc:	Destination address to copy the descriptors to
> >> + * @addr:	Guest memory address to copy from
> >> + * @len:	Length of memory to copy
> >> + *
> >> + * Return: -1 if there is an error, 0 otherwise
> >> + */
> >> +static int virtqueue_read_indirect_desc(struct vu_dev *dev, struct vring_desc *desc,
> >> +					uint64_t addr, size_t len)
> >> +{
> >> +	uint64_t read_len;
> >> +
> >> +	if (len > (VIRTQUEUE_MAX_SIZE * sizeof(struct vring_desc)))
> >> +		return -1;
> >> +
> >> +	if (len == 0)
> >> +		return -1;
> >> +
> >> +	while (len) {
> >> +		const struct vring_desc *orig_desc;
> >> +
> >> +		read_len = len;
> >> +		orig_desc = vu_gpa_to_va(dev, &read_len, addr);  
> > In case you missed this in my review of v3 (I'm not sure if it's a
> > valid concern):
> > 
> > --
> > Should we also return if read_len < sizeof(struct vring_desc) after
> > this call? Can that ever happen, if we pick a particular value of addr
> > so that it's almost at the end of a region?
> > --  
> 
> In fact, read_len can be < sizeof(struct vring_desc) after this call but if orig_desc != 
> NULL it means we can continue in another region to continue to fill the structure.

Right, I see that.

> If there is not enough memory to fill "len" bytes it exits with -1.

...and this as well. But let's say that read_len is 1 (and struct
vring_desc is 16 bytes). Then:

		memcpy(desc, orig_desc, read_len);

copies one byte

		[...]

		desc += read_len / sizeof(struct vring_desc);

doesn't increase desc.

At the next iteration with len > 0 and read_len > 0, the memcpy() will
overwrite that one byte, as we didn't increase desc. Or it's not
possible for some other reason?

-- 
Stefano