Skip to contentSkip to conversation

nfsd: fix oops when reading pool_stats before server is started

PATCH Applied Jeff Layton 3 participants 3 messages Jun 17, 2024

Subsystems (3)
lore
Share & tools
lore

Jeff Layton

author maintainer
#0 lore raw

PATCH 1/1 nfsd: fix oops when reading pool_stats before server is started

Sourbh reported an oops that is triggerable by trying to read the pool_stats procfile before nfsd had been started. Move the check for a NULL serv in svc_pool_stats_start above the mutex acquisition, and fix the stop routine not to unlock the mutex if there is no serv yet.

Fixes 7b207ccd9833 ("svc: don't hold reference for poolstats, only mutex.")
---
 net/sunrpc/svc_xprt.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
net/sunrpc/svc_xprt.c +5 -3
index d3735ab3e6d1..b757a8891813 100644
@@ -1422,12 +1422,13 @@ 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,7 +1460,8 @@ static void svc_pool_stats_stop(struct seq_file *m, void *p)
 {
 	struct svc_info *si = m->private;
 
-	mutex_unlock(si->mutex);
+	if (si->serv)
+		mutex_unlock(si->mutex);
 }
 
 static int svc_pool_stats_show(struct seq_file *m, void *p)

---
base-commit: 4ddfda417a50309f17aeb85f8d1a9a9efbc7d81c
change-id: 20240617-nfsd-next-8593f73544f5

Best regards,

Signature · 1 line
Jeff Layton <[email protected]>
Tested-by on v1 1/1
#1 lore raw

Hello Jeff,

With the below fix applied, the issue is not observed.

Thanks for the fix.

- Sourabh Jain

Quoted 48 lines · Jeff Layton

Sourbh reported an oops that is triggerable by trying to read the pool_stats procfile before nfsd had been started. Move the check for a NULL serv in svc_pool_stats_start above the mutex acquisition, and fix the stop routine not to unlock the mutex if there is no serv yet.

Fixes 7b207ccd9833 ("svc: don't hold reference for poolstats, only mutex.")
---
  net/sunrpc/svc_xprt.c | 8 +++++---
  1 file changed, 5 insertions(+), 3 deletions(-)
net/sunrpc/svc_xprt.c +5 -4
index d3735ab3e6d1..b757a8891813 100644
@@ -1422,12 +1422,13 @@ 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,7 +1460,8 @@ static void svc_pool_stats_stop(struct seq_file *m, void *p)
  {
  	struct svc_info *si = m->private;
 
-	mutex_unlock(si->mutex);
+	if (si->serv)
+		mutex_unlock(si->mutex);
  }
 
  static int svc_pool_stats_show(struct seq_file *m, void *p)
 
---

base-commit: 4ddfda417a50309f17aeb85f8d1a9a9efbc7d81c
change-id: 20240617-nfsd-next-8593f73544f5

Best regards,

Applied
#2 lore raw
In reply to Jeff Layton
Quoted 8 lines · Jeff Layton

Sourbh reported an oops that is triggerable by trying to read the pool_stats procfile before nfsd had been started. Move the check for a NULL serv in svc_pool_stats_start above the mutex acquisition, and fix the stop routine not to unlock the mutex if there is no serv yet.

Fixes 7b207ccd9833 ("svc: don't hold reference for poolstats, only mutex.")

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

Quoted 43 lines
---
 net/sunrpc/svc_xprt.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
net/sunrpc/svc_xprt.c +5 -4
index d3735ab3e6d1..b757a8891813 100644
@@ -1422,12 +1422,13 @@ 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,7 +1460,8 @@ static void svc_pool_stats_stop(struct seq_file *m, void *p)
 {
 	struct svc_info *si = m->private;
 
-	mutex_unlock(si->mutex);
+	if (si->serv)
+		mutex_unlock(si->mutex);
 }
 
 static int svc_pool_stats_show(struct seq_file *m, void *p)
 
---

base-commit: 4ddfda417a50309f17aeb85f8d1a9a9efbc7d81c
change-id: 20240617-nfsd-next-8593f73544f5

Best regards,

Signature · 1 line
Jeff Layton <[email protected]>
Signature · 1 line
Chuck Lever