virtio: fix NULL pointer dereference in virtqueue_notification#689
virtio: fix NULL pointer dereference in virtqueue_notification#689masc2008 wants to merge 1 commit into
Conversation
Add a NULL check for vq before dereferencing it in virtqueue_notification() to prevent a crash when vq is NULL. Signed-off-by: Shichun Ma <masc2008@gmail.com>
d44cc09 to
4e7587f
Compare
| { | ||
| atomic_thread_fence(memory_order_seq_cst); | ||
| if (vq->callback) | ||
| if (vq && vq->callback) |
There was a problem hiding this comment.
To me this check seems overkill. Why virtqueue_notification should be called at all if the appropriate virtqueue was not retrieved in the first place? The caller of this function must ensure that vq is retrieved properly before calling this function.
There was a problem hiding this comment.
Also, when vq is NULL, please add error level log that vq is not expected to be NULL.
edmooring
left a comment
There was a problem hiding this comment.
This looks okay to me.
I can see a case where it might be possible to call virtqueue_notification() on a virtueue that has a vring that has not yet been created.
|
Okay, since @arnopo and @edmooring have acked, I am okay with this patch. |
@tnmysh : Because |
Add a NULL check for the vq pointer before dereferencing it in virtqueue_notification(). Without this check, a NULL virtqueue pointer passed to the function would cause a crash when accessing vq->callback.