From: Christian Brauner <brauner@kernel.org>
To: Jens Axboe <axboe@kernel.dk>,
Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org,
Christian Brauner <brauner@kernel.org>
Subject: [PATCH 2/8] cred: add kernel_cred() helper
Date: Mon, 03 Nov 2025 00:12:41 +0100 [thread overview]
Message-ID: <20251103-work-creds-init_cred-v1-2-cb3ec8711a6a@kernel.org> (raw)
In-Reply-To: <20251103-work-creds-init_cred-v1-0-cb3ec8711a6a@kernel.org>
Access kernel creds based off of init_task. This will let us avoid any
direct access to init_cred.
Link: https://patch.msgid.link/20251031-work-creds-init_cred-v1-1-cbf0400d6e0e@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
---
include/linux/cred.h | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/include/linux/cred.h b/include/linux/cred.h
index 89ae50ad2ace..8ab3718184ad 100644
--- a/include/linux/cred.h
+++ b/include/linux/cred.h
@@ -20,6 +20,8 @@
struct cred;
struct inode;
+extern struct task_struct init_task;
+
/*
* COW Supplementary groups list
*/
@@ -156,6 +158,11 @@ extern struct cred *prepare_exec_creds(void);
extern int commit_creds(struct cred *);
extern void abort_creds(struct cred *);
extern struct cred *prepare_kernel_cred(struct task_struct *);
+static inline const struct cred *kernel_cred(void)
+{
+ /* shut up sparse */
+ return rcu_dereference_raw(init_task.cred);
+}
extern int set_security_override(struct cred *, u32);
extern int set_security_override_from_ctx(struct cred *, const char *);
extern int set_create_files_as(struct cred *, struct inode *);
--
2.47.3
next prev parent reply other threads:[~2025-11-02 23:12 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-02 23:12 [PATCH 0/8] creds: add {scoped_}with_kernel_creds() Christian Brauner
2025-11-02 23:12 ` [PATCH 1/8] cleanup: fix scoped_class() Christian Brauner
2025-11-02 23:12 ` Christian Brauner [this message]
2025-11-02 23:12 ` [PATCH 3/8] cred: make init_cred static Christian Brauner
2025-11-02 23:12 ` [PATCH 4/8] cred: add {scoped_}with_kernel_creds Christian Brauner
2025-11-02 23:12 ` [PATCH 5/8] firmware: don't copy kernel creds Christian Brauner
2025-11-02 23:12 ` [PATCH 6/8] nbd: " Christian Brauner
2025-11-02 23:12 ` [PATCH 7/8] target: " Christian Brauner
2025-11-02 23:12 ` [PATCH 8/8] unix: don't copy creds Christian Brauner
2025-11-03 15:59 ` [PATCH 0/8] creds: add {scoped_}with_kernel_creds() Jens Axboe
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-init_cred-v1-2-cb3ec8711a6a@kernel.org \
--to=brauner@kernel.org \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).