]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
smb: use credential guards in cifs_get_spnego_key()
authorChristian Brauner <brauner@kernel.org>
Mon, 3 Nov 2025 11:27:01 +0000 (12:27 +0100)
committerChristian Brauner <brauner@kernel.org>
Tue, 4 Nov 2025 11:36:48 +0000 (12:36 +0100)
Use credential guards for scoped credential override with automatic
restoration on scope exit.

Link: https://patch.msgid.link/20251103-work-creds-guards-simple-v1-13-a3e156839e7f@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/smb/client/cifs_spnego.c

index 9891f55bac1e28f37247505a87f9a0b6a16f66d2..da935bd1ce8781596c9ffb491de05f2f9b51a765 100644 (file)
@@ -90,7 +90,6 @@ cifs_get_spnego_key(struct cifs_ses *sesInfo,
        size_t desc_len;
        struct key *spnego_key;
        const char *hostname = server->hostname;
-       const struct cred *saved_cred;
 
        /* length of fields (with semicolons): ver=0xyz ip4=ipaddress
           host=hostname sec=mechanism uid=0xFF user=username */
@@ -158,9 +157,8 @@ cifs_get_spnego_key(struct cifs_ses *sesInfo,
                dp += sprintf(dp, ";upcall_target=app");
 
        cifs_dbg(FYI, "key description = %s\n", description);
-       saved_cred = override_creds(spnego_cred);
-       spnego_key = request_key(&cifs_spnego_key_type, description, "");
-       revert_creds(saved_cred);
+       scoped_with_creds(spnego_cred)
+               spnego_key = request_key(&cifs_spnego_key_type, description, "");
 
 #ifdef CONFIG_CIFS_DEBUG2
        if (cifsFYI && !IS_ERR(spnego_key)) {