LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Junrui Luo via B4 Relay <devnull+moonafterrain.outlook.com@kernel.org>
To: Madhavan Srinivasan <maddy@linux.ibm.com>,
	 Michael Ellerman <mpe@ellerman.id.au>,
	Nicholas Piggin <npiggin@gmail.com>,
	 "Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
	 Paul Mackerras <paulus@ozlabs.org>,
	Arnd Bergmann <arnd@arndb.de>,  Al Viro <viro@zeniv.linux.org.uk>
Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
	 Junrui Luo <moonafterrain@outlook.com>,
	Yuhao Jiang <danisjiang@gmail.com>,
	 stable@vger.kernel.org
Subject: [PATCH 1/6] powerpc/spufs: fix spu_context leak in coredump
Date: Sun, 02 Aug 2026 23:51:39 +0800	[thread overview]
Message-ID: <20260802-fixes-v1-1-7368423440f4@outlook.com> (raw)
In-Reply-To: <20260802-fixes-v1-0-7368423440f4@outlook.com>

From: Junrui Luo <moonafterrain@outlook.com>

coredump_next_context() returns a spu_context with a reference taken by
get_spu_context(), which the caller must drop.
spufs_coredump_extra_notes_size() does so on all of its exits, but
spufs_coredump_extra_notes_write() never calls put_spu_context(), so
every context dumped through elf_coredump_extra_notes_write() leaks a
reference, including on the success path.

Fix by dropping the reference on each of the three exits of the loop,
mirroring ..._size().

Fixes: 38b407be172d ("powerpc/spufs: Rework fcheck() usage")
Reported-by: Yuhao Jiang <danisjiang@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Junrui Luo <moonafterrain@outlook.com>
---
 arch/powerpc/platforms/cell/spufs/coredump.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/platforms/cell/spufs/coredump.c b/arch/powerpc/platforms/cell/spufs/coredump.c
index 301ee7d8b7df..f5964c9ebb3e 100644
--- a/arch/powerpc/platforms/cell/spufs/coredump.c
+++ b/arch/powerpc/platforms/cell/spufs/coredump.c
@@ -162,13 +162,16 @@ int spufs_coredump_extra_notes_write(struct coredump_params *cprm)
 	fd = 0;
 	while ((ctx = coredump_next_context(&fd)) != NULL) {
 		rc = spu_acquire_saved(ctx);
-		if (rc)
+		if (rc) {
+			put_spu_context(ctx);
 			return rc;
+		}
 
 		for (j = 0; spufs_coredump_read[j].name != NULL; j++) {
 			rc = spufs_arch_write_note(ctx, j, cprm, fd);
 			if (rc) {
 				spu_release_saved(ctx);
+				put_spu_context(ctx);
 				return rc;
 			}
 		}
@@ -177,6 +180,7 @@ int spufs_coredump_extra_notes_write(struct coredump_params *cprm)
 
 		/* start searching the next fd next time */
 		fd++;
+		put_spu_context(ctx);
 	}
 
 	return 0;

-- 
2.51.2




  reply	other threads:[~2026-08-02 15:52 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-02 15:51 [PATCH 0/6] powerpc/spufs: assorted fixes Junrui Luo via B4 Relay
2026-08-02 15:51 ` Junrui Luo via B4 Relay [this message]
2026-08-03  9:05   ` [PATCH 1/6] powerpc/spufs: fix spu_context leak in coredump Arnd Bergmann
2026-08-02 15:51 ` [PATCH 2/6] powerpc/spufs: don't leak kernel stack via spu_run Junrui Luo via B4 Relay
2026-08-03  9:09   ` Arnd Bergmann
2026-08-02 15:51 ` [PATCH 3/6] powerpc/spufs: bound NPC against local store size Junrui Luo via B4 Relay
2026-08-03  9:14   ` Arnd Bergmann
2026-08-04  6:30     ` Junrui Luo
2026-08-02 15:51 ` [PATCH 4/6] powerpc/spufs: check permissions in spufs_setattr() Junrui Luo via B4 Relay
2026-08-03  9:16   ` Arnd Bergmann
2026-08-02 15:51 ` [PATCH 5/6] powerpc/spufs: fix deadlock on gang creation failure Junrui Luo via B4 Relay
2026-08-02 15:51 ` [PATCH 6/6] powerpc/spufs: don't hold state_mutex during user access Junrui Luo via B4 Relay
2026-08-03  9:26   ` Arnd Bergmann
2026-08-03  9:28 ` [PATCH 0/6] powerpc/spufs: assorted fixes Arnd Bergmann
2026-08-03  9:59   ` Junrui Luo
2026-08-03 10:18     ` Arnd Bergmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260802-fixes-v1-1-7368423440f4@outlook.com \
    --to=devnull+moonafterrain.outlook.com@kernel.org \
    --cc=arnd@arndb.de \
    --cc=chleroy@kernel.org \
    --cc=danisjiang@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=moonafterrain@outlook.com \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    --cc=paulus@ozlabs.org \
    --cc=stable@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox