From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Christian Brauner <brauner@kernel.org>,
Jens Axboe <axboe@kernel.dk>, Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.18.y 2/3] cred: add scoped_with_kernel_creds()
Date: Mon, 27 Jul 2026 16:59:57 -0400 [thread overview]
Message-ID: <20260727205958.1929027-2-sashal@kernel.org> (raw)
In-Reply-To: <20260727205958.1929027-1-sashal@kernel.org>
From: Christian Brauner <brauner@kernel.org>
[ Upstream commit ae40e6c65791f47c76cc14d0cce2707fe6053f72 ]
Add a new cleanup class for override creds. We can make use of this in a
bunch of places going forward.
Based on this scoped_with_kernel_creds() that can be used to temporarily
assume kernel credentials for specific tasks such as firmware loading,
or coredump socket connections. At no point will the caller interact
with the kernel credentials directly.
Link: https://patch.msgid.link/20251103-work-creds-init_cred-v1-4-cb3ec8711a6a@kernel.org
Reviewed-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Christian Brauner <brauner@kernel.org>
Stable-dep-of: 981ccd97f715 ("dm: avoid leaking the caller's thread keyring via the table device file")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
include/linux/cred.h | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/include/linux/cred.h b/include/linux/cred.h
index 8ab3718184adf8..be2cd07b174c5e 100644
--- a/include/linux/cred.h
+++ b/include/linux/cred.h
@@ -187,6 +187,14 @@ static inline const struct cred *revert_creds(const struct cred *revert_cred)
return rcu_replace_pointer(current->cred, revert_cred, 1);
}
+DEFINE_CLASS(override_creds,
+ const struct cred *,
+ revert_creds(_T),
+ override_creds(override_cred), const struct cred *override_cred)
+
+#define scoped_with_kernel_creds() \
+ scoped_class(override_creds, __UNIQUE_ID(cred), kernel_cred())
+
/**
* get_cred_many - Get references on a set of credentials
* @cred: The credentials to reference
--
2.53.0
next prev parent reply other threads:[~2026-07-27 21:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-20 15:30 FAILED: patch "[PATCH] dm: avoid leaking the caller's thread keyring via the table" failed to apply to 6.18-stable tree gregkh
2026-07-27 20:59 ` [PATCH 6.18.y 1/3] cred: add kernel_cred() helper Sasha Levin
2026-07-27 20:59 ` Sasha Levin [this message]
2026-07-27 20:59 ` [PATCH 6.18.y 3/3] dm: avoid leaking the caller's thread keyring via the table device file Sasha Levin
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=20260727205958.1929027-2-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=axboe@kernel.dk \
--cc=brauner@kernel.org \
--cc=stable@vger.kernel.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