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

QEMU/libvfio-user might use different VFIO headers #230

Open
tmakatos opened this issue Jan 11, 2021 · 3 comments
Open

QEMU/libvfio-user might use different VFIO headers #230

tmakatos opened this issue Jan 11, 2021 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@tmakatos
Copy link
Member

tmakatos commented Jan 11, 2021

Discussion copied from Slack:

JJ pointed out that there can be seemingly unnoticed additions of members to structs, e.g. the addition of cap_offset to struct vfio_device_info (https://lore.kernel.org/qemu-devel/[email protected]/#Z30linux-headers:linux:vfio.h). IIUC this isn't accompanied by some VFIO version change. QEMU has it's own version of the VFIO headers, plus QEMU and libvfio-user can be compiled with different versions of VFIO headers anyway, so we need to figure out how to make sure they work in such cases.

@jlevon
Copy link
Collaborator

jlevon commented Jan 11, 2021

maybe we should ship with our own copy too

@tmakatos
Copy link
Member Author

Actually, such incompatibilities are expected and they're solved by the argsz field. In this particular case there's a bug in libvfio-user:

int
handle_device_get_info(vfu_ctx_t *vfu_ctx, uint32_t size,
                       struct vfio_device_info *dev_info)
{
    assert(vfu_ctx != NULL);
    assert(dev_info != NULL);

    if (size != sizeof *dev_info) {
        return -EINVAL;
    }

We should be checking argsz and use struct vfio_device_info accordingly (e.g. don't access fields of the strcut whose offset is past argsz).

@tmakatos tmakatos added the bug Something isn't working label Jan 12, 2021
@tmakatos
Copy link
Member Author

#232 fixes this specific problem, however I realize that we have a bigger problem because of the way we use the VFIO headers: if we assume that some struct member exists in some VFIO struct (e.g. struct vfio_device_info.cap_offset but the VFIO headers installed in the system don't have this recently-added member, libvfio-user will fail to compile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants