Skip to contentSkip to conversation

nfsd: proper fix for NULL deref in svc_pool_stats_start()

PATCH Applied NeilBrown 3 participants 5 messages Jun 24, 2024 – Jun 25, 2024

Subsystems (3)
lore
Share & tools
lore

NeilBrown

author
#0 lore raw

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

author
#1 lore raw

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.

Fixes 7b207ccd9833 ("svc: don't hold reference for poolstats, only mutex.")
---
 fs/nfsd/nfsctl.c | 2 ++
 fs/nfsd/nfssvc.c | 1 -
 2 files changed, 2 insertions(+), 1 deletion(-)
fs/nfsd/nfsctl.c +2 -0
index 533b65057e18..c848ebe5d08f 100644
@@ -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
index cd9a6a1a9fc8..89d7918de7b1 100644
@@ -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
author
#2 lore raw

PATCH 2/2 Revert "nfsd: fix oops when reading pool_stats before server is started"

In reply to NeilBrown

This 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.

Fixes 8e948c365d9c ("nfsd: fix oops when reading pool_stats before server is started")
---
 net/sunrpc/svc_xprt.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
net/sunrpc/svc_xprt.c +3 -5
index 49a3bea33f9d..dd86d7f1e97e 100644
@@ -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
maintainer Reviewed-by on the v1 series
#3 lore raw
In reply to NeilBrown
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_stats before

Yes, this looks like a superior fix. Thanks, Neil!

Applied
#4 lore raw
In reply to NeilBrown
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_stats before

Applied to nfsd-fixes (for 6.10-rc). Thanks!

Signature · 1 line
Chuck Lever