public inbox for linux-trace-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	 linux-aio@kvack.org, linux-unionfs@vger.kernel.org,
	 linux-erofs@lists.ozlabs.org, linux-nfs@vger.kernel.org,
	 linux-cifs@vger.kernel.org, samba-technical@lists.samba.org,
	 cgroups@vger.kernel.org, netdev@vger.kernel.org,
	 linux-crypto@vger.kernel.org,
	linux-trace-kernel@vger.kernel.org,
	 Christian Brauner <brauner@kernel.org>
Subject: [PATCH 10/12] coredump: use override credential guard
Date: Mon, 03 Nov 2025 15:57:36 +0100	[thread overview]
Message-ID: <20251103-work-creds-guards-prepare_creds-v1-10-b447b82f2c9b@kernel.org> (raw)
In-Reply-To: <20251103-work-creds-guards-prepare_creds-v1-0-b447b82f2c9b@kernel.org>

Use override credential guards for scoped credential override with
automatic restoration on scope exit.

Signed-off-by: Christian Brauner <brauner@kernel.org>
---
 fs/coredump.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/fs/coredump.c b/fs/coredump.c
index 5424a6c4e360..fe4099e0530b 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -1160,7 +1160,6 @@ void vfs_coredump(const kernel_siginfo_t *siginfo)
 	struct core_name cn;
 	const struct mm_struct *mm = current->mm;
 	const struct linux_binfmt *binfmt = mm->binfmt;
-	const struct cred *old_cred;
 	int argc = 0;
 	struct coredump_params cprm = {
 		.siginfo = siginfo,
@@ -1197,11 +1196,8 @@ void vfs_coredump(const kernel_siginfo_t *siginfo)
 	if (coredump_wait(siginfo->si_signo, &core_state) < 0)
 		return;
 
-	old_cred = override_creds(cred);
-
-	do_coredump(&cn, &cprm, &argv, &argc, binfmt);
-
-	revert_creds(old_cred);
+	scoped_with_creds(cred)
+		do_coredump(&cn, &cprm, &argv, &argc, binfmt);
 	coredump_cleanup(&cn, &cprm);
 	return;
 }

-- 
2.47.3


  parent reply	other threads:[~2025-11-03 14:58 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-03 14:57 [PATCH 00/12] credential guards: credential preparation Christian Brauner
2025-11-03 14:57 ` [PATCH 01/12] cred: add prepare credential guard Christian Brauner
2025-11-03 14:57 ` [PATCH 02/12] sev-dev: use guard for path Christian Brauner
2025-11-03 14:57 ` [PATCH 03/12] sev-dev: use prepare credential guard Christian Brauner
2025-11-03 14:57 ` [PATCH 04/12] sev-dev: use override credential guards Christian Brauner
2025-11-03 14:57 ` [PATCH 05/12] coredump: move revert_cred() before coredump_cleanup() Christian Brauner
2025-11-03 14:57 ` [PATCH 06/12] coredump: pass struct linux_binfmt as const Christian Brauner
2025-11-03 14:57 ` [PATCH 07/12] coredump: mark struct mm_struct " Christian Brauner
2025-11-03 14:57 ` [PATCH 08/12] coredump: split out do_coredump() from vfs_coredump() Christian Brauner
2025-11-03 14:57 ` [PATCH 09/12] coredump: use prepare credential guard Christian Brauner
2025-11-03 14:57 ` Christian Brauner [this message]
2025-11-03 14:57 ` [PATCH 11/12] trace: " Christian Brauner
2025-11-03 16:09   ` Steven Rostedt
2025-11-03 14:57 ` [PATCH 12/12] trace: use override " Christian Brauner
2025-11-03 16:10   ` Steven Rostedt

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=20251103-work-creds-guards-prepare_creds-v1-10-b447b82f2c9b@kernel.org \
    --to=brauner@kernel.org \
    --cc=cgroups@vger.kernel.org \
    --cc=linux-aio@kvack.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=samba-technical@lists.samba.org \
    --cc=torvalds@linux-foundation.org \
    /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