Skip to contentSkip to conversation

afs: Fix uninit var in afs_alloc_anon_key()

PATCH Applied David Howells 2 participants 2 messages Nov 29, 2025

Subsystems (2)
lore
Share & tools
lore

David Howells

author maintainer
#0 lore raw

PATCH 1/1 afs: Fix uninit var in afs_alloc_anon_key()

Fix an uninitialised variable (key) in afs_alloc_anon_key() by setting it to cell->anonymous_key. Without this change, the error check may return a false failure with a bad error number.

Most of the time this is unlikely to happen because the first encounter with afs_alloc_anon_key() will usually be from (auto)mount, for which all subsequent operations must wait - apart from other (auto)mounts. Once the call->anonymous_key is allocated, all further calls to afs_request_key() will skip the call to afs_alloc_anon_key() for that cell.

Fixes d27c71257825 ("afs: Fix delayed allocation of a cell's anonymous key")
cc Marc Dionne <[email protected]>
---
 fs/afs/security.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/afs/security.c +2 -1
index ff8830e6982f..55ddce94af03 100644
@@ -26,7 +26,8 @@ static int afs_alloc_anon_key(struct afs_cell *cell)
 	struct key *key;
 
 	mutex_lock(&afs_key_lock);
-	if (!cell->anonymous_key) {
+	key = cell->anonymous_key;
+	if (!key) {
 		key = rxrpc_get_null_key(cell->key_desc);
 		if (!IS_ERR(key))
 			cell->anonymous_key = key;
#1 lore raw

I've applied this directly, since it seems to be a recent regression and final 6.18 is days away.

And it seems like an obvious fix. Famous last words...

Linus

Quoted 4 lines · David Howells

Fix an uninitialised variable (key) in afs_alloc_anon_key() by setting it to cell->anonymous_key. Without this change, the error check may return a false failure with a bad error number.