Skip to contentSkip to conversation

afs: Fix potential null pointer dereference in afs_put_server

PATCH Applied Zhen Ni 4 participants 4 messages Sep 23, 2025 – Sep 25, 2025

Subsystems (2)
lore
Share & tools
lore

Zhen Ni

author
#0 lore raw

PATCH 1/1 afs: Fix potential null pointer dereference in afs_put_server

afs_put_server() accessed server->debug_id before the NULL check, which could lead to a null pointer dereference. Move the debug_id assignment, ensuring we never dereference a NULL server pointer.

Fixes 2757a4dc1849 ("afs: Fix access after dec in put functions")
---
 fs/afs/server.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/afs/server.c +2 -1
index a97562f831eb..c4428ebddb1d 100644
@@ -331,13 +331,14 @@ struct afs_server *afs_use_server(struct afs_server *server, bool activate,
 void afs_put_server(struct afs_net *net, struct afs_server *server,
 		    enum afs_server_trace reason)
 {
-	unsigned int a, debug_id = server->debug_id;
+	unsigned int a, debug_id;
 	bool zero;
 	int r;
 
 	if (!server)
 		return;
 
+	debug_id = server->debug_id;
 	a = atomic_read(&server->active);
 	zero = __refcount_dec_and_test(&server->ref, &r);
 	trace_afs_server(debug_id, r - 1, a, reason);
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 21 lines · Zhen Ni

afs_put_server() accessed server->debug_id before the NULL check, which could lead to a null pointer dereference. Move the debug_id assignment, ensuring we never dereference a NULL server pointer.

Fixes 2757a4dc1849 ("afs: Fix access after dec in put functions")
---
  fs/afs/server.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
fs/afs/server.c +1 -1
index a97562f831eb..c4428ebddb1d 100644
@@ -331,13 +331,14 @@ struct afs_server *afs_use_server(struct afs_server *server, bool activate,
  void afs_put_server(struct afs_net *net, struct afs_server *server,
  		    enum afs_server_trace reason)
  {
-	unsigned int a, debug_id = server->debug_id;
+	unsigned int a, debug_id;

fs/afs/server.c struct afs_server *afs_use_server(struct afs_server *server, bool activate, · line 344

Quoted 10 lines
fs/afs/server.c +1 -0
  	bool zero;
  	int r;
 
  	if (!server)
  		return;
 
+	debug_id = server->debug_id;
  	a = atomic_read(&server->active);
  	zero = __refcount_dec_and_test(&server->ref, &r);
  	trace_afs_server(debug_id, r - 1, a, reason);

Looks good.

maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Zhen Ni

Hi Christian,

Quoted 7 lines · Zhen Ni

afs_put_server() accessed server->debug_id before the NULL check, which could lead to a null pointer dereference. Move the debug_id assignment, ensuring we never dereference a NULL server pointer.

Fixes 2757a4dc1849 ("afs: Fix access after dec in put functions")

Can you pick this patch up and add:

Thanks,
David

#3 lore raw
In reply to Zhen Ni
Quoted 5 lines · Zhen Ni

afs_put_server() accessed server->debug_id before the NULL check, which could lead to a null pointer dereference. Move the debug_id assignment, ensuring we never dereference a NULL server pointer.

Applied to the vfs.fixes branch of the vfs/vfs.git tree. Patches in the vfs.fixes branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.fixes

[1/1] afs: Fix potential null pointer dereference in afs_put_server

      https://git.kernel.org/vfs/vfs/c/9158c6bb2451