All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] vfio: Clear the caps->buf to NULL after free
@ 2022-06-29  2:29 Schspa Shi
  2022-06-30 19:51 ` Alex Williamson
  0 siblings, 1 reply; 2+ messages in thread
From: Schspa Shi @ 2022-06-29  2:29 UTC (permalink / raw)
  To: alex.williamson, cohuck; +Cc: kvm, linux-kernel, Schspa Shi

On buffer resize failure, vfio_info_cap_add() will free the buffer,
report zero for the size, and return -ENOMEM.  As additional
hardening, also clear the buffer pointer to prevent any chance of a
double free.

Signed-off-by: Schspa Shi <schspa@gmail.com>

-- 

Changelog:
v1 -> v2:
        - Remove incorrect double free report in commit message.
v2 -> v3:
        - Update commit comment as Alex advised.
---
 drivers/vfio/vfio.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
index 61e71c1154be..a0fb93866f61 100644
--- a/drivers/vfio/vfio.c
+++ b/drivers/vfio/vfio.c
@@ -1812,6 +1812,7 @@ struct vfio_info_cap_header *vfio_info_cap_add(struct vfio_info_cap *caps,
 	buf = krealloc(caps->buf, caps->size + size, GFP_KERNEL);
 	if (!buf) {
 		kfree(caps->buf);
+		caps->buf = NULL;
 		caps->size = 0;
 		return ERR_PTR(-ENOMEM);
 	}
-- 
2.29.0


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

* Re: [PATCH v3] vfio: Clear the caps->buf to NULL after free
  2022-06-29  2:29 [PATCH v3] vfio: Clear the caps->buf to NULL after free Schspa Shi
@ 2022-06-30 19:51 ` Alex Williamson
  0 siblings, 0 replies; 2+ messages in thread
From: Alex Williamson @ 2022-06-30 19:51 UTC (permalink / raw)
  To: Schspa Shi; +Cc: cohuck, kvm, linux-kernel

On Wed, 29 Jun 2022 10:29:48 +0800
Schspa Shi <schspa@gmail.com> wrote:

> On buffer resize failure, vfio_info_cap_add() will free the buffer,
> report zero for the size, and return -ENOMEM.  As additional
> hardening, also clear the buffer pointer to prevent any chance of a
> double free.
> 
> Signed-off-by: Schspa Shi <schspa@gmail.com>
> 

Applied to vfio next branch for v5.20.  Thanks,

Alex


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

end of thread, other threads:[~2022-06-30 19:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-29  2:29 [PATCH v3] vfio: Clear the caps->buf to NULL after free Schspa Shi
2022-06-30 19:51 ` Alex Williamson

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.