Skip to contentSkip to conversation

Patch "nfsd: fix oops when reading pool_stats before server is started" has been added to the 6.9-stable tree

DISCUSSION NeilBrown 2 participants 2 messages Jun 24, 2024 – Jun 25, 2024 1 message not in the archive Stable branch

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

NeilBrown

author
#1 lore raw
Quoted 7 lines · On Mon, 24 Jun 2024, [email protected] wrote:

This is a note to let you know that I've just added the patch titled

nfsd: fix oops when reading pool_stats before server is started

to the 6.9-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

Quoted 6 lines

The filename of the patch is:
nfsd-fix-oops-when-reading-pool_stats-before-server-.patch
and it can be found in the queue-6.9 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

I feel this should not be added to the stable tree.

It moves at 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.

I'll post a revert and a better fix for mainline.

Thanks,
NeilBrown

Quoted 54 lines

commit 388a527c6cf55bde74bc0891d0b4c38f50d896be

Author: Jeff Layton <[email protected]>
Date:   Mon Jun 17 07:54:08 2024 -0400

nfsd: fix oops when reading pool_stats before server is started

[ Upstream commit 8e948c365d9c10b685d1deb946bd833d6a9b43e0 ]

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 +5 -3
index b4a85a227bd7d..1a2982051f986 100644
@@ -1371,12 +1371,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];
 }
@@ -1408,7 +1409,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)
#2 lore raw
Quoted 17 lines · NeilBrown
Quoted 7 lines · On Mon, 24 Jun 2024, [email protected] wrote:

This is a note to let you know that I've just added the patch titled

nfsd: fix oops when reading pool_stats before server is started

to the 6.9-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

Quoted 6 lines

The filename of the patch is:
nfsd-fix-oops-when-reading-pool_stats-before-server-.patch
and it can be found in the queue-6.9 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

I feel this should not be added to the stable tree.

Quoted 8 lines

It moves at 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.

I'll post a revert and a better fix for mainline.

Now dropped, thanks!

greg k-h