All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] virtio_ring: Check null pointer
@ 2022-01-04 15:12 Jiasheng Jiang
  2022-01-05  3:20   ` Jason Wang
  2022-01-06 12:59   ` Michael S. Tsirkin
  0 siblings, 2 replies; 5+ messages in thread
From: Jiasheng Jiang @ 2022-01-04 15:12 UTC (permalink / raw)
  To: jasowang; +Cc: mst, virtualization, linux-kernel, Jiasheng Jiang

As the alloc_indirect_packed() returns kmalloc_array() that could
allocation fail and return null pointer, it should be check in order to
prevent the dereference of null pointer.

Fixes: 1ce9e6055fa0 ("virtio_ring: introduce packed ring support")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
v2: Remove the redundant empty line.
---
 drivers/virtio/virtio_ring.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 71e16b53e9c1..2923d8a68dc3 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -992,6 +992,10 @@ static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq,
 
 	head = vq->packed.next_avail_idx;
 	desc = alloc_indirect_packed(total_sg, gfp);
+	if (!desc) {
+		END_USE(vq);
+		return -ENOMEM;
+	}
 
 	if (unlikely(vq->vq.num_free < 1)) {
 		pr_debug("Can't add buf len 1 - avail = 0\n");
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] virtio_ring: Check null pointer
  2022-01-04 15:12 [PATCH v2] virtio_ring: Check null pointer Jiasheng Jiang
@ 2022-01-05  3:20   ` Jason Wang
  2022-01-06 12:59   ` Michael S. Tsirkin
  1 sibling, 0 replies; 5+ messages in thread
From: Jason Wang @ 2022-01-05  3:20 UTC (permalink / raw)
  To: Jiasheng Jiang; +Cc: mst, virtualization, linux-kernel

On Tue, Jan 4, 2022 at 11:13 PM Jiasheng Jiang <jiasheng@iscas.ac.cn> wrote:
>
> As the alloc_indirect_packed() returns kmalloc_array() that could
> allocation fail and return null pointer, it should be check in order to
> prevent the dereference of null pointer.
>
> Fixes: 1ce9e6055fa0 ("virtio_ring: introduce packed ring support")
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
> ---
> v2: Remove the redundant empty line.
> ---
>  drivers/virtio/virtio_ring.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> index 71e16b53e9c1..2923d8a68dc3 100644
> --- a/drivers/virtio/virtio_ring.c
> +++ b/drivers/virtio/virtio_ring.c
> @@ -992,6 +992,10 @@ static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq,
>
>         head = vq->packed.next_avail_idx;
>         desc = alloc_indirect_packed(total_sg, gfp);
> +       if (!desc) {
> +               END_USE(vq);
> +               return -ENOMEM;

Just notice this:

My tree contains this commit: fc6d70f40b3d0 ("virtio_ring: check desc
== NULL when using indirect with packed"). It has fixed the wrong
error value but not the END_USE().

Thanks

> +       }
>
>         if (unlikely(vq->vq.num_free < 1)) {
>                 pr_debug("Can't add buf len 1 - avail = 0\n");
> --
> 2.25.1
>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] virtio_ring: Check null pointer
@ 2022-01-05  3:20   ` Jason Wang
  0 siblings, 0 replies; 5+ messages in thread
From: Jason Wang @ 2022-01-05  3:20 UTC (permalink / raw)
  To: Jiasheng Jiang; +Cc: virtualization, linux-kernel, mst

On Tue, Jan 4, 2022 at 11:13 PM Jiasheng Jiang <jiasheng@iscas.ac.cn> wrote:
>
> As the alloc_indirect_packed() returns kmalloc_array() that could
> allocation fail and return null pointer, it should be check in order to
> prevent the dereference of null pointer.
>
> Fixes: 1ce9e6055fa0 ("virtio_ring: introduce packed ring support")
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
> ---
> v2: Remove the redundant empty line.
> ---
>  drivers/virtio/virtio_ring.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> index 71e16b53e9c1..2923d8a68dc3 100644
> --- a/drivers/virtio/virtio_ring.c
> +++ b/drivers/virtio/virtio_ring.c
> @@ -992,6 +992,10 @@ static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq,
>
>         head = vq->packed.next_avail_idx;
>         desc = alloc_indirect_packed(total_sg, gfp);
> +       if (!desc) {
> +               END_USE(vq);
> +               return -ENOMEM;

Just notice this:

My tree contains this commit: fc6d70f40b3d0 ("virtio_ring: check desc
== NULL when using indirect with packed"). It has fixed the wrong
error value but not the END_USE().

Thanks

> +       }
>
>         if (unlikely(vq->vq.num_free < 1)) {
>                 pr_debug("Can't add buf len 1 - avail = 0\n");
> --
> 2.25.1
>

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] virtio_ring: Check null pointer
  2022-01-04 15:12 [PATCH v2] virtio_ring: Check null pointer Jiasheng Jiang
@ 2022-01-06 12:59   ` Michael S. Tsirkin
  2022-01-06 12:59   ` Michael S. Tsirkin
  1 sibling, 0 replies; 5+ messages in thread
From: Michael S. Tsirkin @ 2022-01-06 12:59 UTC (permalink / raw)
  To: Jiasheng Jiang; +Cc: jasowang, virtualization, linux-kernel

On Tue, Jan 04, 2022 at 11:12:51PM +0800, Jiasheng Jiang wrote:
> As the alloc_indirect_packed() returns kmalloc_array() that could
> allocation fail and return null pointer, it should be check in order to
> prevent the dereference of null pointer.
> 
> Fixes: 1ce9e6055fa0 ("virtio_ring: introduce packed ring support")
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>


Well upstream has:

    virtio_ring: check desc == NULL when using indirect with packed

so this no longer applies.
I think we do need to fix it: the END_USE is missing there.
Sending a patch.


> ---
> v2: Remove the redundant empty line.
> ---
>  drivers/virtio/virtio_ring.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> index 71e16b53e9c1..2923d8a68dc3 100644
> --- a/drivers/virtio/virtio_ring.c
> +++ b/drivers/virtio/virtio_ring.c
> @@ -992,6 +992,10 @@ static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq,
>  
>  	head = vq->packed.next_avail_idx;
>  	desc = alloc_indirect_packed(total_sg, gfp);
> +	if (!desc) {
> +		END_USE(vq);
> +		return -ENOMEM;
> +	}
>  
>  	if (unlikely(vq->vq.num_free < 1)) {
>  		pr_debug("Can't add buf len 1 - avail = 0\n");
> -- 
> 2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] virtio_ring: Check null pointer
@ 2022-01-06 12:59   ` Michael S. Tsirkin
  0 siblings, 0 replies; 5+ messages in thread
From: Michael S. Tsirkin @ 2022-01-06 12:59 UTC (permalink / raw)
  To: Jiasheng Jiang; +Cc: linux-kernel, virtualization

On Tue, Jan 04, 2022 at 11:12:51PM +0800, Jiasheng Jiang wrote:
> As the alloc_indirect_packed() returns kmalloc_array() that could
> allocation fail and return null pointer, it should be check in order to
> prevent the dereference of null pointer.
> 
> Fixes: 1ce9e6055fa0 ("virtio_ring: introduce packed ring support")
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>


Well upstream has:

    virtio_ring: check desc == NULL when using indirect with packed

so this no longer applies.
I think we do need to fix it: the END_USE is missing there.
Sending a patch.


> ---
> v2: Remove the redundant empty line.
> ---
>  drivers/virtio/virtio_ring.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> index 71e16b53e9c1..2923d8a68dc3 100644
> --- a/drivers/virtio/virtio_ring.c
> +++ b/drivers/virtio/virtio_ring.c
> @@ -992,6 +992,10 @@ static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq,
>  
>  	head = vq->packed.next_avail_idx;
>  	desc = alloc_indirect_packed(total_sg, gfp);
> +	if (!desc) {
> +		END_USE(vq);
> +		return -ENOMEM;
> +	}
>  
>  	if (unlikely(vq->vq.num_free < 1)) {
>  		pr_debug("Can't add buf len 1 - avail = 0\n");
> -- 
> 2.25.1

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-01-06 12:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-04 15:12 [PATCH v2] virtio_ring: Check null pointer Jiasheng Jiang
2022-01-05  3:20 ` Jason Wang
2022-01-05  3:20   ` Jason Wang
2022-01-06 12:59 ` Michael S. Tsirkin
2022-01-06 12:59   ` Michael S. Tsirkin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.