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: 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 <jlayton@kernel.org> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>pull/1191/head
parent
2ed4f6fe15
commit
930b64ca0c
|
|
@ -2202,8 +2202,14 @@ static __net_init int nfsd_net_init(struct net *net)
|
||||||
NFSD_STATS_COUNTERS_NUM);
|
NFSD_STATS_COUNTERS_NUM);
|
||||||
if (retval)
|
if (retval)
|
||||||
goto out_repcache_error;
|
goto out_repcache_error;
|
||||||
|
|
||||||
memset(&nn->nfsd_svcstats, 0, sizeof(nn->nfsd_svcstats));
|
memset(&nn->nfsd_svcstats, 0, sizeof(nn->nfsd_svcstats));
|
||||||
nn->nfsd_svcstats.program = &nfsd_programs[0];
|
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++)
|
for (i = 0; i < sizeof(nn->nfsd_versions); i++)
|
||||||
nn->nfsd_versions[i] = nfsd_support_version(i);
|
nn->nfsd_versions[i] = nfsd_support_version(i);
|
||||||
for (i = 0; i < sizeof(nn->nfsd4_minorversions); i++)
|
for (i = 0; i < sizeof(nn->nfsd4_minorversions); i++)
|
||||||
|
|
@ -2213,13 +2219,14 @@ static __net_init int nfsd_net_init(struct net *net)
|
||||||
nfsd4_init_leases_net(nn);
|
nfsd4_init_leases_net(nn);
|
||||||
get_random_bytes(&nn->siphash_key, sizeof(nn->siphash_key));
|
get_random_bytes(&nn->siphash_key, sizeof(nn->siphash_key));
|
||||||
seqlock_init(&nn->writeverf_lock);
|
seqlock_init(&nn->writeverf_lock);
|
||||||
nfsd_proc_stat_init(net);
|
|
||||||
#if IS_ENABLED(CONFIG_NFS_LOCALIO)
|
#if IS_ENABLED(CONFIG_NFS_LOCALIO)
|
||||||
spin_lock_init(&nn->local_clients_lock);
|
spin_lock_init(&nn->local_clients_lock);
|
||||||
INIT_LIST_HEAD(&nn->local_clients);
|
INIT_LIST_HEAD(&nn->local_clients);
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
out_proc_error:
|
||||||
|
percpu_counter_destroy_many(nn->counter, NFSD_STATS_COUNTERS_NUM);
|
||||||
out_repcache_error:
|
out_repcache_error:
|
||||||
nfsd_idmap_shutdown(net);
|
nfsd_idmap_shutdown(net);
|
||||||
out_idmap_error:
|
out_idmap_error:
|
||||||
|
|
|
||||||
|
|
@ -73,11 +73,11 @@ static int nfsd_show(struct seq_file *seq, void *v)
|
||||||
|
|
||||||
DEFINE_PROC_SHOW_ATTRIBUTE(nfsd);
|
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);
|
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)
|
void nfsd_proc_stat_shutdown(struct net *net)
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
#include <uapi/linux/nfsd/stats.h>
|
#include <uapi/linux/nfsd/stats.h>
|
||||||
#include <linux/percpu_counter.h>
|
#include <linux/percpu_counter.h>
|
||||||
|
|
||||||
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);
|
void nfsd_proc_stat_shutdown(struct net *net);
|
||||||
|
|
||||||
static inline void nfsd_stats_rc_hits_inc(struct nfsd_net *nn)
|
static inline void nfsd_stats_rc_hits_inc(struct nfsd_net *nn)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue