Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Descriptor count in virtio_vring_info and fw_rsc_vdev_vring are differing data types, leading to possible truncation on assignment #399

Closed
tammyleino opened this issue Jun 8, 2022 · 5 comments · Fixed by #403 or #407

Comments

@tammyleino
Copy link
Collaborator

num is a uint32_t in fw_rsc_vdev_vring, but this value gets cast to uint16_t by rproc_virtio_init_vring when assigning num_descs to vring_info->info.num_descs.

It is improbable that someone would configure uint32_t number of descriptors, but it would be more correct for these two data members to match in type.

@arnopo
Copy link
Collaborator

arnopo commented Jun 9, 2022

Right!
as the vring_alloc_info structure contains a padding field following update could be done smoothly:

struct vring_alloc_info {
	void *vaddr;
	uint32_t align;
-	uint16_t num_descs;
-	uint16_t pad;
+	uint32_t num_descs;
};

could you send a PR to propose it?

@tammyleino
Copy link
Collaborator Author

@arnopo Yes, will do. I have a couple PRs I'm going to push out together maybe next week - week after at the latest.

@tammyleino
Copy link
Collaborator Author

@arnopo Changing num_descs to uint32_t will also require vq_nentries in the virtqueue struct to change to uint32_t (otherwise we're just pushing the truncation further up), which causes additional fallout throughout the code with data type changes. Is it even feasible that an application would want more buffers than 65,535? If no, I suggest we not make this change. We cannot change num in fw_rsc_vdev_vring to be uint16_t or the resource tables won't be compatible going forward, but can we document that num can only be 16-bits in length?

@arnopo
Copy link
Collaborator

arnopo commented Jun 16, 2022

Having more than 65,535 does not seem like a realistic use case to me.
In short term we could also add a metal_assert in rproc_virtio_init_vring with an inline associated comment.

@tammyleino
Copy link
Collaborator Author

#407
#403

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants