[PATCH] Keys: Remove redundant initialization of cred

David Howells dhowells at redhat.com
Tue May 11 10:50:14 UTC 2021


Yang Li <yang.lee at linux.alibaba.com> wrote:

> -	const struct cred *cred = current_cred();
> +	const struct cred *cred;

Good catch, but it's probably the wrong fix.

In that function, there is:

	const struct cred *cred = current_cred();
	...
	cred = get_current_cred();
	keyring = keyring_alloc(desc, cred->fsuid, cred->fsgid, cred, ...);
	put_cred(cred);
	...
	sprintf(uid_str, "%d", from_kuid(&init_user_ns, cred->fsuid));
	...

So we get the creds again, but with a ref, and then drop after calling
keyring_alloc()... and then access cred again, which is dodgy - but we get
away with it because cred is still pinned by our task_struct.

I think what is actually needed is to remove the get_current_cred() and the
put_cred() calls, in which case, you want this:

	Fixes: d84f4f992cbd ("CRED: Inaugurate COW credentials")

David



More information about the Linux-security-module-archive mailing list