-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vhost: fix crash caused by accessing a freed vsocket
When a vhost user message handling error in the event dispatch thread, vsocket reconn is added to the reconnection list of the reconnection thread. Since the reconnection, event dispatching and app configuration thread do not have common thread protection restrictions, the app config thread freed vsocket in the rte_vhost_driver_unregister process, but vsocket reconn can still exist in the reconn_list through this mechanism. Then in the reconnection thread, the vsocket is connected again and conn is added to the dispatch thread. Finally, the vsocket that has been freed by rte_vhost_driver_unregister is accessed again in the event dispatch thread, resulting in a use-after-free error. This patch adds a vhost threads read-write lock to restrict reconnection, event dispatching and app configuration threads. When the vhost driver unregisters, it exclusively holds the lock to safely free the vsocket. #0 0x0000000000000025 in ?? () DPDK#1 0x0000000003ed7ca0 in vhost_user_read_cb at lib/vhost/socket.c:323 DPDK#2 0x0000000003ed625f in fdset_event_dispatch at lib/vhost/fd_man.c:365 DPDK#3 0x0000000004168336 in ctrl_thread_init at lib/eal/common/eal_common_thread.c:282 DPDK#4 0x00007ffff7bc6ea5 in start_thread () from /lib64/libpthread.so.0 DPDK#5 0x00007ffff6209b0d in clone () from /lib64/libc.so.6 Fixes: e623e0c ("vhost: add vhost-user client mode") Cc: stable@dpdk.org Signed-off-by: Gongming Chen <chengm11@chinatelecom.cn> Signed-off-by: 0-day Robot <robot@bytheb.org>
- Loading branch information
Showing
5 changed files
with
57 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <rte_rwlock.h> | ||
|
||
#include "vhost_thread.h" | ||
|
||
static rte_rwlock_t vhost_thread_lock = RTE_RWLOCK_INITIALIZER; | ||
|
||
void | ||
vhost_thread_read_lock(void) | ||
{ | ||
rte_rwlock_read_lock(&vhost_thread_lock); | ||
} | ||
|
||
void | ||
vhost_thread_read_unlock(void) | ||
{ | ||
rte_rwlock_read_unlock(&vhost_thread_lock); | ||
} | ||
|
||
void | ||
vhost_thread_write_lock(void) | ||
{ | ||
rte_rwlock_write_lock(&vhost_thread_lock); | ||
} | ||
|
||
void | ||
vhost_thread_write_unlock(void) | ||
{ | ||
rte_rwlock_write_unlock(&vhost_thread_lock); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef _VHOST_THREAD_H_ | ||
#define _VHOST_THREAD_H_ | ||
|
||
void vhost_thread_read_lock(void); | ||
|
||
void vhost_thread_read_unlock(void); | ||
|
||
void vhost_thread_write_lock(void); | ||
|
||
void vhost_thread_write_unlock(void); | ||
|
||
#endif |