From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7EB2626AD9; Fri, 11 Apr 2025 14:14:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744380879; cv=none; b=DMQlDKf1ijXQAOz3uQUYtOd7DaPcjOwA13lz86NntZ3Cz+VcmuJTEn9+RZv3rTLAMnmD8X95qUUqP86RTsgXmYfB9/o7RcKivMTADRLFSy33aeQc7JTSDzcZf41r63N5Y/ulHEeX8tXe9n1T7sSrhalRgYDMqP9p27wmTuMbA3g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744380879; c=relaxed/simple; bh=QljkX+r+XBI4knPP4WhniYUqdQt7WoAGeY3UKOPefkE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=nx3Ye2Dq0KYQOzw5JpHUFOH5EwaI1LuBaJcGqDalK+IFj+L5BDljP+aZML8T/KEWT2GhPsYBl+vm/ArCo9dBpvLmexcoINNLsH2nrvfZwq5Fwa6jk3Ew4sOUIRofgFfvF3ma8PNsol9b8CDXrWOoujfveQuHxp5lpLpXcsaA0Y0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KEMT2J2Z; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KEMT2J2Z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8273EC4CEE2; Fri, 11 Apr 2025 14:14:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744380879; bh=QljkX+r+XBI4knPP4WhniYUqdQt7WoAGeY3UKOPefkE=; h=From:To:Cc:Subject:Date:From; b=KEMT2J2Z4c6wnfSXILDlSKvA3RNFBW0oD116QXIvAbhJA9b6/fX0KpS5ZEGUGriBi a5e5eC5cgDuvsB6jSmKn2/kvo9EppW7GQr6nGWUqzD1qLEOa1mxYtJ8M/uId7clK/C 1oVg0vlhBJScYuc/nnD3J0MbA9+ydRHmhOSXggKPokZ5n4dxaT6pF5ofPuPodrXz1y iQX+x9QXaefvwXV7xFqmojiAl66oGB1WluwaNO+wzNrF1igSpez1Z+imo4uKQrFHf2 wL4aDJYjI7igAr1lzZ60b5bw/khN51jBuK2uw1pkpPBemWB9iBGGnHrwxkSqt6+BwF NfkmJV8pRfqfQ== From: cel@kernel.org To: Cc: , Jeff Layton , syzbot+e34ad04f27991521104c@syzkaller.appspotmail.com Subject: [PATCH v6.13] nfsd: don't ignore the return code of svc_proc_register() Date: Fri, 11 Apr 2025 10:14:12 -0400 Message-ID: <20250411141412.27052-1-cel@kernel.org> X-Mailer: git-send-email 2.47.0 Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Jeff Layton [ Upstream commit 930b64ca0c511521f0abdd1d57ce52b2a6e3476b ] Currently, nfsd_proc_stat_init() ignores the return value of svc_proc_register(). If the procfile creation fails, then the kernel will WARN when it tries to remove the entry later. Fix nfsd_proc_stat_init() to return the same type of pointer as svc_proc_register(), and fix up nfsd_net_init() to check that and fail the nfsd_net construction if it occurs. svc_proc_register() can fail if the dentry can't be allocated, or if an identical dentry already exists. The second case is pretty unlikely in the nfsd_net construction codepath, so if this happens, return -ENOMEM. Reported-by: syzbot+e34ad04f27991521104c@syzkaller.appspotmail.com Closes: https://lore.kernel.org/linux-nfs/67a47501.050a0220.19061f.05f9.GAE@google.com/ Cc: stable@vger.kernel.org # v6.9 Signed-off-by: Jeff Layton Signed-off-by: Chuck Lever --- fs/nfsd/nfsctl.c | 9 ++++++++- fs/nfsd/stats.c | 4 ++-- fs/nfsd/stats.h | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) I did not have any problem cherry-picking 930b64 onto v6.13.11. This built and ran some simple NFSD tests in my lab. diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c index e83629f39604..2e835e7c107e 100644 --- a/fs/nfsd/nfsctl.c +++ b/fs/nfsd/nfsctl.c @@ -2244,8 +2244,14 @@ static __net_init int nfsd_net_init(struct net *net) NFSD_STATS_COUNTERS_NUM); if (retval) goto out_repcache_error; + memset(&nn->nfsd_svcstats, 0, sizeof(nn->nfsd_svcstats)); nn->nfsd_svcstats.program = &nfsd_programs[0]; + if (!nfsd_proc_stat_init(net)) { + retval = -ENOMEM; + goto out_proc_error; + } + for (i = 0; i < sizeof(nn->nfsd_versions); i++) nn->nfsd_versions[i] = nfsd_support_version(i); for (i = 0; i < sizeof(nn->nfsd4_minorversions); i++) @@ -2255,12 +2261,13 @@ static __net_init int nfsd_net_init(struct net *net) nfsd4_init_leases_net(nn); get_random_bytes(&nn->siphash_key, sizeof(nn->siphash_key)); seqlock_init(&nn->writeverf_lock); - nfsd_proc_stat_init(net); #if IS_ENABLED(CONFIG_NFS_LOCALIO) INIT_LIST_HEAD(&nn->local_clients); #endif return 0; +out_proc_error: + percpu_counter_destroy_many(nn->counter, NFSD_STATS_COUNTERS_NUM); out_repcache_error: nfsd_idmap_shutdown(net); out_idmap_error: diff --git a/fs/nfsd/stats.c b/fs/nfsd/stats.c index bb22893f1157..f7eaf95e20fc 100644 --- a/fs/nfsd/stats.c +++ b/fs/nfsd/stats.c @@ -73,11 +73,11 @@ static int nfsd_show(struct seq_file *seq, void *v) DEFINE_PROC_SHOW_ATTRIBUTE(nfsd); -void nfsd_proc_stat_init(struct net *net) +struct proc_dir_entry *nfsd_proc_stat_init(struct net *net) { struct nfsd_net *nn = net_generic(net, nfsd_net_id); - svc_proc_register(net, &nn->nfsd_svcstats, &nfsd_proc_ops); + return svc_proc_register(net, &nn->nfsd_svcstats, &nfsd_proc_ops); } void nfsd_proc_stat_shutdown(struct net *net) diff --git a/fs/nfsd/stats.h b/fs/nfsd/stats.h index 04aacb6c36e2..e4efb0e4e56d 100644 --- a/fs/nfsd/stats.h +++ b/fs/nfsd/stats.h @@ -10,7 +10,7 @@ #include #include -void nfsd_proc_stat_init(struct net *net); +struct proc_dir_entry *nfsd_proc_stat_init(struct net *net); void nfsd_proc_stat_shutdown(struct net *net); static inline void nfsd_stats_rc_hits_inc(struct nfsd_net *nn) -- 2.47.0