nanovms / nanos

A kernel designed to run one and only one application in a virtualized environment
https://nanos.org
Apache License 2.0
2.58k stars 133 forks source link

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

Closed francescolavra closed 2 months ago

francescolavra commented 2 months ago

Since commit d037970c, 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).