Skip to content

Commit df8d829

Browse files
shardulsdk-mpiricchucklever
authored andcommitted
nfsd: fix memory leak in nfsd_create_serv error paths
When nfsd_create_serv() calls percpu_ref_init() to initialize nn->nfsd_net_ref, it allocates both a percpu reference counter and a percpu_ref_data structure (64 bytes). However, if the function fails later due to svc_create_pooled() returning NULL or svc_bind() returning an error, these allocations are not cleaned up, resulting in a memory leak. The leak manifests as: - Unreferenced percpu allocation (8 bytes per CPU) - Unreferenced percpu_ref_data structure (64 bytes) Fix this by adding percpu_ref_exit() calls in both error paths to properly clean up the percpu_ref_init() allocations. This patch fixes the percpu_ref leak in nfsd_create_serv() seen as an auxiliary leak in syzbot report 099461f8558eb0a1f4f3; the prepare_creds() and vsock-related leaks in the same report remain to be addressed separately. Reported-by: syzbot+099461f8558eb0a1f4f3@syzkaller.appspotmail.com Link: https://syzkaller.appspot.com/bug?extid=099461f8558eb0a1f4f3 Fixes: 47e9881 ("nfsd: add nfsd_serv_try_get and nfsd_serv_put") Signed-off-by: Shardul Bankar <shardul.b@mpiricsoftware.com> Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent ebae102 commit df8d829

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

fs/nfsd/nfssvc.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,12 +615,15 @@ int nfsd_create_serv(struct net *net)
615615
serv = svc_create_pooled(nfsd_programs, ARRAY_SIZE(nfsd_programs),
616616
&nn->nfsd_svcstats,
617617
nfsd_max_blksize, nfsd);
618-
if (serv == NULL)
618+
if (serv == NULL) {
619+
percpu_ref_exit(&nn->nfsd_net_ref);
619620
return -ENOMEM;
621+
}
620622

621623
error = svc_bind(serv, net);
622624
if (error < 0) {
623625
svc_destroy(&serv);
626+
percpu_ref_exit(&nn->nfsd_net_ref);
624627
return error;
625628
}
626629
spin_lock(&nfsd_notifier_lock);

0 commit comments

Comments
 (0)