Skip to content

Commit 930b64c

Browse files
jtlaytonchucklever
authored andcommitted
nfsd: don't ignore the return code of svc_proc_register()
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]>
1 parent 2ed4f6f commit 930b64c

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
@@ -2202,8 +2202,14 @@ static __net_init int nfsd_net_init(struct net *net)
22022202
NFSD_STATS_COUNTERS_NUM);
22032203
if (retval)
22042204
goto out_repcache_error;
2205+
22052206
memset(&nn->nfsd_svcstats, 0, sizeof(nn->nfsd_svcstats));
22062207
nn->nfsd_svcstats.program = &nfsd_programs[0];
2208+
if (!nfsd_proc_stat_init(net)) {
2209+
retval = -ENOMEM;
2210+
goto out_proc_error;
2211+
}
2212+
22072213
for (i = 0; i < sizeof(nn->nfsd_versions); i++)
22082214
nn->nfsd_versions[i] = nfsd_support_version(i);
22092215
for (i = 0; i < sizeof(nn->nfsd4_minorversions); i++)
@@ -2213,13 +2219,14 @@ static __net_init int nfsd_net_init(struct net *net)
22132219
nfsd4_init_leases_net(nn);
22142220
get_random_bytes(&nn->siphash_key, sizeof(nn->siphash_key));
22152221
seqlock_init(&nn->writeverf_lock);
2216-
nfsd_proc_stat_init(net);
22172222
#if IS_ENABLED(CONFIG_NFS_LOCALIO)
22182223
spin_lock_init(&nn->local_clients_lock);
22192224
INIT_LIST_HEAD(&nn->local_clients);
22202225
#endif
22212226
return 0;
22222227

2228+
out_proc_error:
2229+
percpu_counter_destroy_many(nn->counter, NFSD_STATS_COUNTERS_NUM);
22232230
out_repcache_error:
22242231
nfsd_idmap_shutdown(net);
22252232
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)