Linux virtualization list
 help / color / mirror / Atom feed
* [PATCH] virtio_console: drop device reference when DMA allocation fails
@ 2026-11-23 10:23 Ziheng Wei
  2026-11-23 10:27 ` sashiko-bot
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Ziheng Wei @ 2026-11-23 10:23 UTC (permalink / raw)
  To: Amit Shah, Arnd Bergmann, Greg Kroah-Hartman; +Cc: virtualization, linux-kernel

alloc_buf() takes a device reference before dma_alloc_coherent(), but its
failure label only frees the buffer:

  get_device() -> dma_alloc_coherent() fails -> kfree(buf)
                -> device reference is permanently leaked

Release the reference on the failure path as free_buf() does on success.

Found by LLM-assisted static analysis. Build tested with allmodconfig;
no runtime fault-injection test.

Fixes: 1b6370463e88 ("virtio_console: Add support for remoteproc serial")
Signed-off-by: Ziheng Wei <zihengw03@163.com>
---
 drivers/char/virtio_console.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index b1b1aaf43..ef942c0df 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -464,6 +464,8 @@ static struct port_buffer *alloc_buf(struct virtio_device *vdev, size_t buf_size
 	return buf;
 
 free_buf:
+	if (buf->dev)
+		put_device(buf->dev);
 	kfree(buf);
 fail:
 	return NULL;

base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
-- 
2.43.0


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

* Re: [PATCH] virtio_console: drop device reference when DMA allocation fails
  2026-11-23 10:23 [PATCH] virtio_console: drop device reference when DMA allocation fails Ziheng Wei
@ 2026-11-23 10:27 ` sashiko-bot
  2026-11-24  2:47 ` Jiaming Fan
  2026-11-24  7:04 ` Ziheng Wei
  2 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-23 10:27 UTC (permalink / raw)
  To: Ziheng Wei; +Cc: virtualization, Michael S. Tsirkin, Eugenio Perez

> alloc_buf() takes a device reference before dma_alloc_coherent(), but its
> failure label only frees the buffer:
> 
>   get_device() -> dma_alloc_coherent() fails -> kfree(buf)
>                 -> device reference is permanently leaked
> 
> Release the reference on the failure path as free_buf() does on success.
> 
> Found by LLM-assisted static analysis. Build tested with allmodconfig;
> no runtime fault-injection test.
> 
> Fixes: 1b6370463e88 ("virtio_console: Add support for remoteproc serial")
> Signed-off-by: Ziheng Wei <zihengw03@163.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123102321.8605-1-zihengw03@163.com?part=1

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

* Re: [PATCH] virtio_console: drop device reference when DMA allocation fails
  2026-11-23 10:23 [PATCH] virtio_console: drop device reference when DMA allocation fails Ziheng Wei
  2026-11-23 10:27 ` sashiko-bot
@ 2026-11-24  2:47 ` Jiaming Fan
  2026-11-24  7:04 ` Ziheng Wei
  2 siblings, 0 replies; 6+ messages in thread
From: Jiaming Fan @ 2026-11-24  2:47 UTC (permalink / raw)
  To: Ziheng Wei
  Cc: Amit Shah, Arnd Bergmann, Greg Kroah-Hartman, virtualization,
	linux-kernel

Is this a duplicate of https://lore.kernel.org/all/aoWK_qpSBeO6Bw0M@michalis-linux/?


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

* Re: [PATCH] virtio_console: drop device reference when DMA allocation fails
  2026-11-23 10:23 [PATCH] virtio_console: drop device reference when DMA allocation fails Ziheng Wei
  2026-11-23 10:27 ` sashiko-bot
  2026-11-24  2:47 ` Jiaming Fan
@ 2026-11-24  7:04 ` Ziheng Wei
  2026-11-24  7:27   ` Greg KH
  2 siblings, 1 reply; 6+ messages in thread
From: Ziheng Wei @ 2026-11-24  7:04 UTC (permalink / raw)
  To: Jiaming Fan; +Cc: amit, arnd, gregkh, virtualization, linux-kernel

Yes, you are right. This is the same issue and effectively the same fix
as Michail's earlier patch.

I should have found that patch before posting. My duplicate search was
too narrow: I checked the code trees and searched using my own wording,
but did not properly search the mailing-list archives by function and
Fixes tag. That was entirely my oversight.

Please ignore my patch. I am sorry for the duplicate submission and for
the review time it cost you and the other recipients. I will search the
archives more thoroughly before posting future patches.

Ziheng Wei


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

* Re: [PATCH] virtio_console: drop device reference when DMA allocation fails
  2026-11-24  7:04 ` Ziheng Wei
@ 2026-11-24  7:27   ` Greg KH
  2026-11-24 10:00     ` Ziheng Wei
  0 siblings, 1 reply; 6+ messages in thread
From: Greg KH @ 2026-11-24  7:27 UTC (permalink / raw)
  To: Ziheng Wei; +Cc: Jiaming Fan, amit, arnd, virtualization, linux-kernel

On Tue, Nov 24, 2026 at 07:04:14AM +0000, Ziheng Wei wrote:
> Yes, you are right. This is the same issue and effectively the same fix
> as Michail's earlier patch.

There is no context here at all :(

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

* Re: [PATCH] virtio_console: drop device reference when DMA allocation fails
  2026-11-24  7:27   ` Greg KH
@ 2026-11-24 10:00     ` Ziheng Wei
  0 siblings, 0 replies; 6+ messages in thread
From: Ziheng Wei @ 2026-11-24 10:00 UTC (permalink / raw)
  To: gregkh; +Cc: fan.jiaming, amit, arnd, virtualization, linux-kernel

Sorry for the missing context. The question I was answering was:

  Is this a duplicate of
  https://lore.kernel.org/all/aoWK_qpSBeO6Bw0M@michalis-linux/?

Yes, it is. Both patches fix the same alloc_buf() device-reference leak
when dma_alloc_coherent() fails. I missed Michail Tatas's earlier patch
during my duplicate search, so please ignore mine.

Sorry again for the noise.

Ziheng Wei


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

end of thread, other threads:[~2026-11-24 10:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 10:23 [PATCH] virtio_console: drop device reference when DMA allocation fails Ziheng Wei
2026-11-23 10:27 ` sashiko-bot
2026-11-24  2:47 ` Jiaming Fan
2026-11-24  7:04 ` Ziheng Wei
2026-11-24  7:27   ` Greg KH
2026-11-24 10:00     ` Ziheng Wei

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox