Patch "afs: Fix delayed allocation of a cell's anonymous key" has been added to the 6.12-stable tree
gregkh at linuxfoundation.org
gregkh at linuxfoundation.org
Thu Jul 30 06:35:56 PDT 2026
This is a note to let you know that I've just added the patch titled
afs: Fix delayed allocation of a cell's anonymous key
to the 6.12-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
afs-fix-delayed-allocation-of-a-cell-s-anonymous-key.patch
and it can be found in the queue-6.12 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree,
please let <stable at vger.kernel.org> know about it.
>From d27c71257825dced46104eefe42e4d9964bd032e Mon Sep 17 00:00:00 2001
From: David Howells <dhowells at redhat.com>
Date: Fri, 28 Nov 2025 10:19:05 +0000
Subject: afs: Fix delayed allocation of a cell's anonymous key
From: David Howells <dhowells at redhat.com>
commit d27c71257825dced46104eefe42e4d9964bd032e upstream.
The allocation of a cell's anonymous key is done in a background thread
along with other cell setup such as doing a DNS upcall. In the reported
bug, this is triggered by afs_parse_source() parsing the device name given
to mount() and calling afs_lookup_cell() with the name of the cell.
The normal key lookup then tries to use the key description on the
anonymous authentication key as the reference for request_key() - but it
may not yet be set and so an oops can happen.
This has been made more likely to happen by the fix for dynamic lookup
failure.
Fix this by firstly allocating a reference name and attaching it to the
afs_cell record when the record is created. It can share the memory
allocation with the cell name (unfortunately it can't just overlap the cell
name by prepending it with "afs@" as the cell name already has a '.'
prepended for other purposes). This reference name is then passed to
request_key().
Secondly, the anon key is now allocated on demand at the point a key is
requested in afs_request_key() if it is not already allocated. A mutex is
used to prevent multiple allocation for a cell.
Thirdly, make afs_request_key_rcu() return NULL if the anonymous key isn't
yet allocated (if we need it) and then the caller can return -ECHILD to
drop out of RCU-mode and afs_request_key() can be called.
Note that the anonymous key is kind of necessary to make the key lookup
cache work as that doesn't currently cache a negative lookup, but it's
probably worth some investigation to see if NULL can be used instead.
Fixes: 330e2c514823 ("afs: Fix dynamic lookup to fail on cell lookup failure")
Reported-by: syzbot+41c68824eefb67cdf00c at syzkaller.appspotmail.com
Signed-off-by: David Howells <dhowells at redhat.com>
Link: https://patch.msgid.link/800328.1764325145@warthog.procyon.org.uk
cc: Marc Dionne <marc.dionne at auristor.com>
cc: linux-afs at lists.infradead.org
cc: linux-fsdevel at vger.kernel.org
Signed-off-by: Christian Brauner <brauner at kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh at linuxfoundation.org>
---
fs/afs/cell.c | 43 ++++++++-----------------------------------
fs/afs/internal.h | 1 +
fs/afs/security.c | 48 ++++++++++++++++++++++++++++++++++++++++--------
3 files changed, 49 insertions(+), 43 deletions(-)
--- a/fs/afs/cell.c
+++ b/fs/afs/cell.c
@@ -140,7 +140,9 @@ static struct afs_cell *afs_alloc_cell(s
return ERR_PTR(-ENOMEM);
}
- cell->name = kmalloc(1 + namelen + 1, GFP_KERNEL);
+ /* Allocate the cell name and the key name in one go. */
+ cell->name = kmalloc(1 + namelen + 1 +
+ 4 + namelen + 1, GFP_KERNEL);
if (!cell->name) {
kfree(cell);
return ERR_PTR(-ENOMEM);
@@ -151,7 +153,11 @@ static struct afs_cell *afs_alloc_cell(s
cell->name_len = namelen;
for (i = 0; i < namelen; i++)
cell->name[i] = tolower(name[i]);
- cell->name[i] = 0;
+ cell->name[i++] = 0;
+
+ cell->key_desc = cell->name + i;
+ memcpy(cell->key_desc, "afs@", 4);
+ memcpy(cell->key_desc + 4, cell->name, cell->name_len + 1);
cell->net = net;
refcount_set(&cell->ref, 1);
@@ -719,33 +725,6 @@ void afs_set_cell_timer(struct afs_cell
}
/*
- * Allocate a key to use as a placeholder for anonymous user security.
- */
-static int afs_alloc_anon_key(struct afs_cell *cell)
-{
- struct key *key;
- char keyname[4 + AFS_MAXCELLNAME + 1], *cp, *dp;
-
- /* Create a key to represent an anonymous user. */
- memcpy(keyname, "afs@", 4);
- dp = keyname + 4;
- cp = cell->name;
- do {
- *dp++ = tolower(*cp);
- } while (*cp++);
-
- key = rxrpc_get_null_key(keyname);
- if (IS_ERR(key))
- return PTR_ERR(key);
-
- cell->anonymous_key = key;
-
- _debug("anon key %p{%x}",
- cell->anonymous_key, key_serial(cell->anonymous_key));
- return 0;
-}
-
-/*
* Activate a cell.
*/
static int afs_activate_cell(struct afs_net *net, struct afs_cell *cell)
@@ -754,12 +733,6 @@ static int afs_activate_cell(struct afs_
struct afs_cell *pcell;
int ret;
- if (!cell->anonymous_key) {
- ret = afs_alloc_anon_key(cell);
- if (ret < 0)
- return ret;
- }
-
ret = afs_proc_cell_setup(cell);
if (ret < 0)
return ret;
--- a/fs/afs/internal.h
+++ b/fs/afs/internal.h
@@ -423,6 +423,7 @@ struct afs_cell {
u8 name_len; /* Length of name */
char *name; /* Cell name, case-flattened and NUL-padded */
+ char *key_desc; /* Authentication key description */
};
/*
--- a/fs/afs/security.c
+++ b/fs/afs/security.c
@@ -16,6 +16,30 @@
static DEFINE_HASHTABLE(afs_permits_cache, 10);
static DEFINE_SPINLOCK(afs_permits_lock);
+static DEFINE_MUTEX(afs_key_lock);
+
+/*
+ * Allocate a key to use as a placeholder for anonymous user security.
+ */
+static int afs_alloc_anon_key(struct afs_cell *cell)
+{
+ struct key *key;
+
+ mutex_lock(&afs_key_lock);
+ if (!cell->anonymous_key) {
+ key = rxrpc_get_null_key(cell->key_desc);
+ if (!IS_ERR(key))
+ cell->anonymous_key = key;
+ }
+ mutex_unlock(&afs_key_lock);
+
+ if (IS_ERR(key))
+ return PTR_ERR(key);
+
+ _debug("anon key %p{%x}",
+ cell->anonymous_key, key_serial(cell->anonymous_key));
+ return 0;
+}
/*
* get a key
@@ -23,11 +47,12 @@ static DEFINE_SPINLOCK(afs_permits_lock)
struct key *afs_request_key(struct afs_cell *cell)
{
struct key *key;
+ int ret;
- _enter("{%x}", key_serial(cell->anonymous_key));
+ _enter("{%s}", cell->key_desc);
- _debug("key %s", cell->anonymous_key->description);
- key = request_key_net(&key_type_rxrpc, cell->anonymous_key->description,
+ _debug("key %s", cell->key_desc);
+ key = request_key_net(&key_type_rxrpc, cell->key_desc,
cell->net->net, NULL);
if (IS_ERR(key)) {
if (PTR_ERR(key) != -ENOKEY) {
@@ -35,6 +60,12 @@ struct key *afs_request_key(struct afs_c
return key;
}
+ if (!cell->anonymous_key) {
+ ret = afs_alloc_anon_key(cell);
+ if (ret < 0)
+ return ERR_PTR(ret);
+ }
+
/* act as anonymous user */
_leave(" = {%x} [anon]", key_serial(cell->anonymous_key));
return key_get(cell->anonymous_key);
@@ -52,11 +83,10 @@ struct key *afs_request_key_rcu(struct a
{
struct key *key;
- _enter("{%x}", key_serial(cell->anonymous_key));
+ _enter("{%s}", cell->key_desc);
- _debug("key %s", cell->anonymous_key->description);
- key = request_key_net_rcu(&key_type_rxrpc,
- cell->anonymous_key->description,
+ _debug("key %s", cell->key_desc);
+ key = request_key_net_rcu(&key_type_rxrpc, cell->key_desc,
cell->net->net);
if (IS_ERR(key)) {
if (PTR_ERR(key) != -ENOKEY) {
@@ -65,6 +95,8 @@ struct key *afs_request_key_rcu(struct a
}
/* act as anonymous user */
+ if (!cell->anonymous_key)
+ return NULL; /* Need to allocate */
_leave(" = {%x} [anon]", key_serial(cell->anonymous_key));
return key_get(cell->anonymous_key);
} else {
@@ -408,7 +440,7 @@ int afs_permission(struct mnt_idmap *idm
if (mask & MAY_NOT_BLOCK) {
key = afs_request_key_rcu(vnode->volume->cell);
- if (IS_ERR(key))
+ if (IS_ERR_OR_NULL(key))
return -ECHILD;
ret = -ECHILD;
Patches currently in stable-queue which might be from dhowells at redhat.com are
queue-6.12/rxrpc-fix-notification-vs-call-release-vs-recvmsg.patch
queue-6.12/rxrpc-use-irq-disabling-spinlocks-between-app-and-i-o-thread.patch
queue-6.12/afs-fix-delayed-allocation-of-a-cell-s-anonymous-key.patch
queue-6.12/afs-simplify-cell-record-handling.patch
queue-6.12/afs-fix-lack-of-locking-around-modifications-of-net-cells_dyn_ino.patch
queue-6.12/rxrpc-pull-out-certain-app-callback-funcs-into-an-ops-table.patch
queue-6.12/rxrpc-fix-cpu-time-starvation-in-i-o-thread.patch
queue-6.12/afs-fix-dynamic-lookup-to-fail-on-cell-lookup-failure.patch
queue-6.12/afs-handle-cb.initcallbackstate3-requests-without-a-server-record.patch
queue-6.12/rxrpc-disable-irq-not-bh-to-take-the-lock-for-attend_link.patch
queue-6.12/rxrpc-fix-socket-notification-race.patch
queue-6.12/afs-fix-afs_server-ref-accounting.patch
queue-6.12/rxrpc-allow-the-app-to-store-private-data-on-peer-structs.patch
queue-6.12/rxrpc-serialize-kernel-accept-preallocation-with-socket-teardown.patch
queue-6.12/afs-use-the-per-peer-app-data-provided-by-rxrpc.patch
queue-6.12/afs-improve-server-refcount-active-count-tracing.patch
queue-6.12/afs-drop-the-net-parameter-from-afs_unuse_cell.patch
queue-6.12/afs-make-afs_lookup_cell-take-a-trace-note.patch
queue-6.12/rxrpc-don-t-need-barrier-for-tx_bottom-and-acks_hard_ack.patch
queue-6.12/rxrpc-fix-locking-issues-with-the-peer-record-hash.patch
queue-6.12/afs-set-vllist-to-null-if-addr-parsing-fails.patch
More information about the linux-afs
mailing list