Page MenuHomeFreeBSD

virtio_p9fs: Fix kernel panic on module unload
ClosedPublic

Authored by arichardson on Sat, Apr 18, 6:00 AM.
Tags
None
Referenced Files
F156023596: D56497.diff
Sun, May 10, 7:16 AM
F156022567: D56497.diff
Sun, May 10, 7:10 AM
F155960354: D56497.id175820.diff
Sat, May 9, 11:32 PM
F155958981: D56497.id175820.diff
Sat, May 9, 11:23 PM
Unknown Object (File)
Fri, May 8, 4:54 AM
Unknown Object (File)
Tue, May 5, 1:58 AM
Unknown Object (File)
Mon, May 4, 9:31 PM
Unknown Object (File)
Mon, May 4, 1:08 PM
Subscribers

Details

Summary

The virtio_p9fs module event handler can be invoked multiple times.
Previously, this caused p9_init_zones() and p9_register_trans() to be
executed multiple times, leaking UMA zones and corrupting the transport
list. During module unload, p9_destroy_zones() was also called multiple
times on the same zone pointers, triggering a duplicate free kernel panic
in uma_zdestroy().

This patch introduces a static reference counter in vt9p_modevent() to
ensure the zones and transports are only initialized and destroyed exactly
once, aligning with the approach used by other virtio drivers like vtnet.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

This revision is now accepted and ready to land.Sat, Apr 18, 7:51 PM
zlei added inline comments.
sys/dev/virtio/p9fs/virtio_p9fs.c
479

This makes me nervous about the whole lifecycle of a module. I noticed that the module event will be only invoked exactly once ( if successfully ) while I was hacking the SYSINITs .

The virtio_p9fs module event handler can be invoked multiple times.

How does it possible to happen ?

sys/dev/virtio/p9fs/virtio_p9fs.c
493

Ahh, I see what happened.

VIRTIO_DRIVER_MODULE expands to two different DRIVER_MODULE and both of them share the same modevent handler vt9p_modevent. So on module load, the event handler vt9p_modevent will be invoked twice.