This is a note to let you know that I've just added the patch titled Fix memory leak in posix_clock_open() to the 6.7-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: fix-memory-leak-in-posix_clock_open.patch and it can be found in the queue-6.7 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 5b4cdd9c5676559b8a7c944ac5269b914b8c0bb8 Mon Sep 17 00:00:00 2001 From: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> Date: Tue, 26 Mar 2024 14:59:48 -0700 Subject: Fix memory leak in posix_clock_open() From: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> commit 5b4cdd9c5676559b8a7c944ac5269b914b8c0bb8 upstream. If the clk ops.open() function returns an error, we don't release the pccontext we allocated for this clock. Re-organize the code slightly to make it all more obvious. Reported-by: Rohit Keshri <rkeshri@xxxxxxxxxx> Acked-by: Oleg Nesterov <oleg@xxxxxxxxxx> Fixes: 60c6946675fc ("posix-clock: introduce posix_clock_context concept") Cc: Jakub Kicinski <kuba@xxxxxxxxxx> Cc: David S. Miller <davem@xxxxxxxxxxxxx> Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx> Signed-off-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- kernel/time/posix-clock.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) --- a/kernel/time/posix-clock.c +++ b/kernel/time/posix-clock.c @@ -129,15 +129,17 @@ static int posix_clock_open(struct inode goto out; } pccontext->clk = clk; - fp->private_data = pccontext; - if (clk->ops.open) + if (clk->ops.open) { err = clk->ops.open(pccontext, fp->f_mode); - else - err = 0; - - if (!err) { - get_device(clk->dev); + if (err) { + kfree(pccontext); + goto out; + } } + + fp->private_data = pccontext; + get_device(clk->dev); + err = 0; out: up_read(&clk->rwsem); return err; Patches currently in stable-queue which might be from torvalds@xxxxxxxxxxxxxxxxxxxx are queue-6.7/x86-cpu-amd-update-the-zenbleed-microcode-revisions.patch queue-6.7/ring-buffer-fix-resetting-of-shortest_full.patch queue-6.7/fix-memory-leak-in-posix_clock_open.patch queue-6.7/ring-buffer-use-wait_event_interruptible-in-ring_buf.patch queue-6.7/ring-buffer-fix-waking-up-ring-buffer-readers.patch queue-6.7/tracing-use-.flush-call-to-wake-up-readers.patch queue-6.7/x86-pm-work-around-false-positive-kmemleak-report-in.patch