Skip to content

Commit 6a59b70

Browse files
jtlaytongregkh
authored andcommitted
nfsd: don't ignore the return code of svc_proc_register()
commit 930b64c upstream. 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: [email protected] Closes: https://lore.kernel.org/linux-nfs/[email protected]/ Cc: [email protected] # v6.9 Signed-off-by: Jeff Layton <[email protected]> Signed-off-by: Chuck Lever <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent b2b18a9 commit 6a59b70

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

fs/nfsd/nfsctl.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2244,8 +2244,14 @@ static __net_init int nfsd_net_init(struct net *net)
22442244
NFSD_STATS_COUNTERS_NUM);
22452245
if (retval)
22462246
goto out_repcache_error;
2247+
22472248
memset(&nn->nfsd_svcstats, 0, sizeof(nn->nfsd_svcstats));
22482249
nn->nfsd_svcstats.program = &nfsd_programs[0];
2250+
if (!nfsd_proc_stat_init(net)) {
2251+
retval = -ENOMEM;
2252+
goto out_proc_error;
2253+
}
2254+
22492255
for (i = 0; i < sizeof(nn->nfsd_versions); i++)
22502256
nn->nfsd_versions[i] = nfsd_support_version(i);
22512257
for (i = 0; i < sizeof(nn->nfsd4_minorversions); i++)
@@ -2255,12 +2261,13 @@ static __net_init int nfsd_net_init(struct net *net)
22552261
nfsd4_init_leases_net(nn);
22562262
get_random_bytes(&nn->siphash_key, sizeof(nn->siphash_key));
22572263
seqlock_init(&nn->writeverf_lock);
2258-
nfsd_proc_stat_init(net);
22592264
#if IS_ENABLED(CONFIG_NFS_LOCALIO)
22602265
INIT_LIST_HEAD(&nn->local_clients);
22612266
#endif
22622267
return 0;
22632268

2269+
out_proc_error:
2270+
percpu_counter_destroy_many(nn->counter, NFSD_STATS_COUNTERS_NUM);
22642271
out_repcache_error:
22652272
nfsd_idmap_shutdown(net);
22662273
out_idmap_error:

fs/nfsd/stats.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ static int nfsd_show(struct seq_file *seq, void *v)
7373

7474
DEFINE_PROC_SHOW_ATTRIBUTE(nfsd);
7575

76-
void nfsd_proc_stat_init(struct net *net)
76+
struct proc_dir_entry *nfsd_proc_stat_init(struct net *net)
7777
{
7878
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
7979

80-
svc_proc_register(net, &nn->nfsd_svcstats, &nfsd_proc_ops);
80+
return svc_proc_register(net, &nn->nfsd_svcstats, &nfsd_proc_ops);
8181
}
8282

8383
void nfsd_proc_stat_shutdown(struct net *net)

fs/nfsd/stats.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <uapi/linux/nfsd/stats.h>
1111
#include <linux/percpu_counter.h>
1212

13-
void nfsd_proc_stat_init(struct net *net);
13+
struct proc_dir_entry *nfsd_proc_stat_init(struct net *net);
1414
void nfsd_proc_stat_shutdown(struct net *net);
1515

1616
static inline void nfsd_stats_rc_hits_inc(struct nfsd_net *nn)

0 commit comments

Comments
 (0)