nfsd: proper fix for NULL deref in svc_pool_stats_start()
Subsystems (3)
cover nfsd: proper fix for NULL deref in svc_pool_stats_start()
A recent patch attempted to fix a NULL pointer deref but introduced a different NULL pointer deref and a possible unbalance unlock.
This series fixes the bug correctly and reverts the faulty fix.
(Sorry for not reviewing this patch earlier)
NeilBrown
[PATCH 1/2] nfsd: initialise nfsd_info.mutex early. [PATCH 2/2] Revert "nfsd: fix oops when reading pool_stats before
PATCH 1/2 nfsd: initialise nfsd_info.mutex early.
nfsd_info.mutex can be dereferenced by dsvc_pool_stats_state() immediately after the the new netns is created. Currently this can trigger an oops.
Move the initialisation earlier before it can possibly be dereferenced.
--- fs/nfsd/nfsctl.c | 2 ++ fs/nfsd/nfssvc.c | 1 - 2 files changed, 2 insertions(+), 1 deletion(-)
fs/nfsd/nfsctl.c +2 -0
@@ -2169,6 +2169,8 @@ static __net_init int nfsd_net_init(struct net *net) nn->nfsd_svcstats.program = &nfsd_program; nn->nfsd_versions =NULL ; nn->nfsd4_minorversions =NULL ; + nn->nfsd_info.mutex = &nfsd_mutex; + nn->nfsd_serv =NULL ;nfsd4_init_leases_net (nn);get_random_bytes (&nn->siphash_key,sizeof (nn->siphash_key));seqlock_init (&nn->writeverf_lock);
fs/nfsd/nfssvc.c +0 -1
@@ -672,7 +672,6 @@ int nfsd_create_serv(struct net *net)return error; }spin_lock (&nfsd_notifier_lock); - nn->nfsd_info.mutex = &nfsd_mutex; nn->nfsd_serv = serv;spin_unlock (&nfsd_notifier_lock);
Signature · 1 line
2.44.0
PATCH 2/2 Revert "nfsd: fix oops when reading pool_stats before server is started"
In reply to NeilBrownThis reverts commit 8e948c365d9c10b685d1deb946bd833d6a9b43e0.
The reverted commit moves a test on a field protected by a mutex outside of the protection of that mutex, and so is obviously racey.
Depending on how the race goes, si->serv might be NULL when dereferenced in svc_pool_stats_start(), or svc_pool_stats_stop() might unlock a mutex that hadn't been locked.
This bug that the commit tried to fix has been addressed by initialising ->mutex earlier.
--- net/sunrpc/svc_xprt.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
net/sunrpc/svc_xprt.c +3 -5
@@ -1421,13 +1421,12 @@ static void *svc_pool_stats_start(struct seq_file *m, loff_t *pos)dprintk ("svc_pool_stats_start, *pidx=%u\n" , pidx); -if (!si->serv) -return NULL ; -mutex_lock (si->mutex);if (!pidx)return SEQ_START_TOKEN ; +if (!si->serv) +return NULL ;return pidx > si->serv->sv_nrpools ?NULL : &si->serv->sv_pools[pidx -1 ]; }
@@ -1459,8 +1458,7 @@ static void svc_pool_stats_stop(struct seq_file *m, void *p) {struct svc_info *si = m->private; -if (si->serv) -mutex_unlock (si->mutex); +mutex_unlock (si->mutex); }static int svc_pool_stats_show (struct seq_file *m,void *p)
Signature · 1 line
2.44.0
Quoted 11 lines · NeilBrown
A recent patch attempted to fix a NULL pointer deref but introduced a different NULL pointer deref and a possible unbalance unlock.
This series fixes the bug correctly and reverts the faulty fix.
(Sorry for not reviewing this patch earlier)
NeilBrown
[PATCH 1/2] nfsd: initialise nfsd_info.mutex early. [PATCH 2/2] Revert "nfsd: fix oops when reading
pool_statsbefore
Yes, this looks like a superior fix. Thanks, Neil!
Chuck Lever
AppliedQuoted 11 lines · NeilBrown
A recent patch attempted to fix a NULL pointer deref but introduced a different NULL pointer deref and a possible unbalance unlock.
This series fixes the bug correctly and reverts the faulty fix.
(Sorry for not reviewing this patch earlier)
NeilBrown
[PATCH 1/2] nfsd: initialise nfsd_info.mutex early. [PATCH 2/2] Revert "nfsd: fix oops when reading
pool_statsbefore
Applied to nfsd-fixes (for 6.10-rc). Thanks!
Signature · 1 line
Chuck Lever