[PATCH 1/2] libceph: check ac->ops in ceph_build_auth()
From: Yiming Zhu
Date: Fri Dec 04 2026 - 03:25:37 EST
When authentication protocol initialization fails (for example, when the
monitor requires cephx while no secret is configured, or init_protocol()
returns an error) or before a protocol is selected, ac->ops remains
NULL.
If delayed_work() -> __validate_auth() -> ceph_build_auth() runs while
ac->ops is NULL (for instance, when mount teardown is delayed flushing
messenger workqueues after a failed msgr1 handshake, or via
ceph_monc_validate_auth()), ac->ops->should_authenticate(ac)
dereferences NULL at offset 0x8 in struct ceph_auth_client_ops:
[5670766.374139] libceph: no secret set (for auth_x protocol)
[5670766.380717] libceph: auth protocol 'cephx' init failed: -22
[5670766.387514] ceph: No mds server is up or the cluster is laggy
[5670776.877828] BUG: kernel NULL pointer dereference, address: 0000000000000008
[5670776.901712] Oops: 0000 [#1] SMP NOPTI
[5670776.930961] Workqueue: events delayed_work [libceph]
[5670776.937181] RIP: 0010:ceph_build_auth+0x29/0x70 [libceph]
[5670777.063682] Call Trace:
[5670777.067223] __validate_auth.part.14+0x27/0x40 [libceph]
[5670777.074017] delayed_work+0xd2/0x160 [libceph]
[5670777.079842] process_one_work+0x1cb/0x370
Guard ac->ops against NULL before calling should_authenticate() in
ceph_build_auth(), matching ceph_auth_is_authenticated() directly below
it. Returning 0 when no protocol handler is initialized preserves the
-EACCES error return in callers such as osd_handle_auth_bad_method()
and mds_handle_auth_bad_method().
Cc: stable@xxxxxxxxxxxxxxx
Fixes: 464691bd52b4 ("libceph: ceph_build_auth() doesn't need ceph_auth_build_hello()")
Signed-off-by: Yiming Zhu <zhuyiming@xxxxxxxxxxxx>
---
net/ceph/auth.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/ceph/auth.c b/net/ceph/auth.c
index 17660bde896b..2d9ffa6c8aad 100644
--- a/net/ceph/auth.c
+++ b/net/ceph/auth.c
@@ -289,7 +289,7 @@ int ceph_build_auth(struct ceph_auth_client *ac,
int ret = 0;
mutex_lock(&ac->mutex);
- if (ac->ops->should_authenticate(ac))
+ if (ac->ops && ac->ops->should_authenticate(ac))
ret = build_request(ac, true, msg_buf, msg_len);
mutex_unlock(&ac->mutex);
return ret;
--
2.56.1