In the Linux kernel, the following vulnerability has been resolved:
ntb: ntbhwswitchtec: Fix use after free vulnerability in switchtecntbremove due to race condition
In the switchtecntbadd function, it can call switchtecntbinitsndev function, then &sndev->checklinkstatuswork is bound with checklinkstatuswork. switchtecntblinknotification may be called to start the work.
If we remove the module which will call switchtecntbremove to make cleanup, it will free sndev through kfree(sndev), while the work mentioned above will be used. The sequence of operations that may lead to a UAF bug is as follows:
CPU0 CPU1
| check_link_status_work
switchtecntbremove | kfree(sndev); | | if (sndev->linkforcedown) | // use sndev
Fix it by ensuring that the work is canceled before proceeding with the cleanup in switchtecntbremove.