* [PATCH] tty: vt: fix memory leak in vc_allocate()
@ 2026-07-23 7:05 Mingyu Wang
2026-07-23 7:15 ` Greg KH
0 siblings, 1 reply; 4+ messages in thread
From: Mingyu Wang @ 2026-07-23 7:05 UTC (permalink / raw)
To: gregkh, jirislaby; +Cc: linux-kernel, linux-serial, stable, Mingyu Wang
If the screen buffer allocation fails in vc_allocate(), the error handling
path jumps to `err_free`. However, this path fails to release the unicode
screen map attached to `vc->uni_pagedict_loc`.
During the early stages of vc_allocate(), the unicode screen map is either
newly allocated via con_set_default_unimap() or shares the default unicode
map from a previously initialized console (which increments its refcount).
If the subsequent kzalloc() for the screen buffer fails, the err_free path
frees the vc structure but leaves the attached uni_pagedict with an
elevated refcount. This results in a memory leak if that console is later
deallocated.
Fix this by calling con_free_unimap(vc) in the err_free path before
kfree(vc). This safely decrements the refcount and releases the dictionary
memory if this was the last reference.
Fixes: 34902b7f2754 ("tty: vt, get rid of weird source code flow")
Cc: stable@vger.kernel.org
Signed-off-by: Mingyu Wang <25181214217@stu.xidian.edu.cn>
---
drivers/tty/vt/vt.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index 8f467b22b799..4bac89ea968a 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -1134,6 +1134,7 @@ int vc_allocate(unsigned int currcons) /* return 0 on success */
return 0;
err_free:
visual_deinit(vc);
+ con_free_unimap(vc);
kfree(vc);
vc_cons[currcons].d = NULL;
return err;
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] tty: vt: fix memory leak in vc_allocate()
2026-07-23 7:05 [PATCH] tty: vt: fix memory leak in vc_allocate() Mingyu Wang
@ 2026-07-23 7:15 ` Greg KH
2026-07-23 10:45 ` Mingyu Wang
0 siblings, 1 reply; 4+ messages in thread
From: Greg KH @ 2026-07-23 7:15 UTC (permalink / raw)
To: Mingyu Wang; +Cc: jirislaby, linux-kernel, linux-serial, stable
On Thu, Jul 23, 2026 at 03:05:30PM +0800, Mingyu Wang wrote:
> If the screen buffer allocation fails in vc_allocate(), the error handling
> path jumps to `err_free`. However, this path fails to release the unicode
> screen map attached to `vc->uni_pagedict_loc`.
>
> During the early stages of vc_allocate(), the unicode screen map is either
> newly allocated via con_set_default_unimap() or shares the default unicode
> map from a previously initialized console (which increments its refcount).
> If the subsequent kzalloc() for the screen buffer fails, the err_free path
> frees the vc structure but leaves the attached uni_pagedict with an
> elevated refcount. This results in a memory leak if that console is later
> deallocated.
>
> Fix this by calling con_free_unimap(vc) in the err_free path before
> kfree(vc). This safely decrements the refcount and releases the dictionary
> memory if this was the last reference.
>
> Fixes: 34902b7f2754 ("tty: vt, get rid of weird source code flow")
> Cc: stable@vger.kernel.org
> Signed-off-by: Mingyu Wang <25181214217@stu.xidian.edu.cn>
How was this tested? And how can this ever fail given this happens at
early boot time, right?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] tty: vt: fix memory leak in vc_allocate()
2026-07-23 7:15 ` Greg KH
@ 2026-07-23 10:45 ` Mingyu Wang
2026-07-30 14:25 ` Greg KH
0 siblings, 1 reply; 4+ messages in thread
From: Mingyu Wang @ 2026-07-23 10:45 UTC (permalink / raw)
To: Greg KH; +Cc: jirislaby, linux-kernel, linux-serial, stable
> How was this tested? And how can this ever fail given this happens at
> early boot time, right?
>
Hi Greg,
Thank you for the review.
Regarding how it can fail:
While vc_allocate() is indeed heavily used during early boot, it is also
reachable at runtime when dynamically allocating new virtual consoles
(e.g., via the VT_ACTIVATE ioctl). The failure we observed happened at
runtime because our fuzzing environment enables kernel fault injection
(failslab). The fuzzer intentionally forced the kzalloc() for the screen
buffer to fail, which exposed this specific error-handling path.
Regarding testing:
This issue was discovered using DevGen (our automated virtual device
modeling fuzzer on QEMU). While we do not have a standalone C reproducer
to run a dynamic runtime test, the fix was derived directly from dynamic
execution evidence: we cross-analyzed the precise kmemleak backtraces
and the fuzzer's execution logs.
The kmemleak traces clearly showed that when fault injection intercepted
the screen buffer allocation, the execution jumped to `err_free`,
permanently bypassing the cleanup of the unicode screen map (which had
its refcount incremented earlier).
The patch has been compile-tested. Since con_free_unimap() safely checks
for a NULL pointer internally, adding it to the err_free path ensures
the elevated refcount is safely dropped without introducing regressions.
I hope this clarifies the context of the bug and the fix.
Best regards,
Mingyu Wang
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] tty: vt: fix memory leak in vc_allocate()
2026-07-23 10:45 ` Mingyu Wang
@ 2026-07-30 14:25 ` Greg KH
0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2026-07-30 14:25 UTC (permalink / raw)
To: Mingyu Wang; +Cc: jirislaby, linux-kernel, linux-serial, stable
On Thu, Jul 23, 2026 at 06:45:23PM +0800, Mingyu Wang wrote:
>
> > How was this tested? And how can this ever fail given this happens at
> > early boot time, right?
> >
>
> Hi Greg,
>
> Thank you for the review.
>
> Regarding how it can fail:
> While vc_allocate() is indeed heavily used during early boot, it is also
> reachable at runtime when dynamically allocating new virtual consoles (e.g.,
> via the VT_ACTIVATE ioctl). The failure we observed happened at runtime
> because our fuzzing environment enables kernel fault injection (failslab).
> The fuzzer intentionally forced the kzalloc() for the screen buffer to fail,
> which exposed this specific error-handling path.
>
> Regarding testing:
> This issue was discovered using DevGen (our automated virtual device
> modeling fuzzer on QEMU). While we do not have a standalone C reproducer to
> run a dynamic runtime test, the fix was derived directly from dynamic
> execution evidence: we cross-analyzed the precise kmemleak backtraces and
> the fuzzer's execution logs.
You need to document the tools you use as per our documentation. Please
do so when you resend this.
thanks,
gre gk-h
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-07-30 16:19 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-23 7:05 [PATCH] tty: vt: fix memory leak in vc_allocate() Mingyu Wang
2026-07-23 7:15 ` Greg KH
2026-07-23 10:45 ` Mingyu Wang
2026-07-30 14:25 ` Greg KH
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.