Skip to contentSkip to conversation

vhost: fix virtqueue access lock check for handlers

PATCH Applied David Marchand 3 participants 4 messages Mar 7, 2024 – Mar 13, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vhost: fix virtqueue access lock check for handlers

As the vhost library may receive a request for an unsupported request, it is necessary to check msg_handler before checking if locking queue pairs is requested.

Coverity issue: 415049

Fixes 5e8fcc60b59d ("vhost: enhance virtqueue access lock asserts")
---
 lib/vhost/vhost_user.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/vhost/vhost_user.c +1 -1
index 7fe1687f08..414192500e 100644
@@ -3171,7 +3171,7 @@ vhost_user_msg_handler(int vid, int fd)
 	 * inactive, so it is safe. Otherwise taking the access_lock
 	 * would cause a dead lock.
 	 */
-	if (msg_handler->lock_all_qps) {
+	if (msg_handler != NULL && msg_handler->lock_all_qps) {
 		if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED)) {
 			vhost_user_lock_all_queue_pairs(dev);
 			unlock_required = 1;
Signature · 1 line
2.44.0
Acked-by on v1 1/1
#1 lore raw
Quoted 17 lines · David Marchand

As the vhost library may receive a request for an unsupported request, it is necessary to check msg_handler before checking if locking queue pairs is requested.

Coverity issue: 415049

Fixes 5e8fcc60b59d ("vhost: enhance virtqueue access lock asserts")
---
 lib/vhost/vhost_user.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/vhost/vhost_user.c +0 -0
index 7fe1687f08..414192500e 100644

lib/vhost/vhost_user.c vhost_user_msg_handler(int vid, int fd) · line 3177

Quoted 8 lines
lib/vhost/vhost_user.c +1 -1
@@ -3171,7 +3171,7 @@ vhost_user_msg_handler(int vid, int fd)
 	 * inactive, so it is safe. Otherwise taking the access_lock
 	 * would cause a dead lock.
 	 */
-	if (msg_handler->lock_all_qps) {
+	if (msg_handler != NULL && msg_handler->lock_all_qps) {
 		if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED)) {
 			vhost_user_lock_all_queue_pairs(dev);
 			unlock_required = 1;
Reviewed-by on v1 1/1
#2 lore raw
In reply to David Marchand
Quoted 17 lines · David Marchand

As the vhost library may receive a request for an unsupported request, it is necessary to check msg_handler before checking if locking queue pairs is requested.

Coverity issue: 415049

Fixes 5e8fcc60b59d ("vhost: enhance virtqueue access lock asserts")
---
  lib/vhost/vhost_user.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
lib/vhost/vhost_user.c +0 -0
index 7fe1687f08..414192500e 100644

lib/vhost/vhost_user.c vhost_user_msg_handler(int vid, int fd) · line 3177

Quoted 8 lines
lib/vhost/vhost_user.c +1 -1
@@ -3171,7 +3171,7 @@ vhost_user_msg_handler(int vid, int fd)
  	 * inactive, so it is safe. Otherwise taking the access_lock
  	 * would cause a dead lock.
  	 */
-	if (msg_handler->lock_all_qps) {
+	if (msg_handler != NULL && msg_handler->lock_all_qps) {
  		if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED)) {
  			vhost_user_lock_all_queue_pairs(dev);
  			unlock_required = 1;

Thanks,
Maxime

author Applied
#3 lore raw
In reply to David Marchand
Quoted 9 lines · David Marchand

As the vhost library may receive a request for an unsupported request, it is necessary to check msg_handler before checking if locking queue pairs is requested.

Coverity issue: 415049

Fixes 5e8fcc60b59d ("vhost: enhance virtqueue access lock asserts")

Applied, thanks.

Signature · 1 line
David Marchand