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

Virtio-9P device attach: fix initialization of virtio_9p struct #2030

Merged
merged 1 commit into from
Jun 20, 2024

Conversation

francescolavra
Copy link
Member

Since commit d037970, in multi-vCPU instances root filesystem initialization can complete before PCI bus discovery; this means that any filesystem mount points specified in the manifest options can be already processed by the time a virtio-9p device is probed and a corresponding volume is added; this in turn means that the volume_add() function called by v9p_dev_attach() can trigger a direct call to v9p_fs_init().
The v9p_fs_init() function uses the general field of the virtio_9p struct, which in the current code is initialized after calling the volume_add() function; this causes v9p_fs_init() to access an uninitialized pointer, leading to an unhandled page fault. The same issue applies to the backed field of the struct.
This change fixes the above issue by moving the initialization of the struct fields before the call to volume_add(). In addition, the unused dev field is being removed, and setting the DRIVER_OK flag in the device status field is being moved before the call to volume_add() (according to the virtio specs, a driver must not send any buffer available notifications to the device before setting DRIVER_OK).

Since commit d037970, in multi-vCPU instances root filesystem
initialization can complete before PCI bus discovery; this means
that any filesystem mount points specified in the manifest options
can be already processed by the time a virtio-9p device is probed
and a corresponding volume is added; this in turn means that the
`volume_add()` function called by `v9p_dev_attach()` can trigger a
direct call to `v9p_fs_init()`.
The `v9p_fs_init()` function uses the `general` field of the
`virtio_9p` struct, which in the current code is initialized after
calling the `volume_add()` function; this causes `v9p_fs_init()`
to access an uninitialized pointer, leading to an unhandled page
fault. The same issue applies to the `backed` field of the struct.
This change fixes the above issue by moving the initialization of
the struct fields before the call to `volume_add()`. In addition,
the unused `dev` field is being removed, and setting the DRIVER_OK
flag in the device status field is being moved before the call to
`volume_add()` (according to the virtio specs, a driver must not
send any buffer available notifications to the device before
setting DRIVER_OK).
@francescolavra francescolavra merged commit 5649086 into master Jun 20, 2024
5 checks passed
@francescolavra francescolavra deleted the fix/vitio-9p branch June 20, 2024 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant