Skip to contentSkip to conversation

NFS: hold BKL when clearing nfs_callback_info.task

PATCH New Jeff Layton 5 participants 14 messages Apr 7, 2008 – Apr 8, 2008

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 NFS: hold BKL when clearing nfs_callback_info.task

The global task pointers for the nfs4 callback thread is normally protected by the nfs_callback_mutex. The exception is when the thread exits abnormally. When this occurs, this variable is cleared without any locking.

Make sure that this variable is cleared while still holding the BKL.

Also, there's no reason that nfs_callback_up and nfs_callback_down need to hold the BKL while trying to lock nfs_callback_mutex. Reverse the lock order as a micro-optimization.

---
 fs/nfs/callback.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
fs/nfs/callback.c +5 -5
index 2e5de77..2646724 100644
@@ -84,8 +84,8 @@ nfs_callback_svc(void *vrqstp)
 		}
 		svc_process(rqstp);
 	}
-	unlock_kernel();
 	nfs_callback_info.task = NULL;
+	unlock_kernel();
 	svc_exit_thread(rqstp);
 	return 0;
 }
@@ -99,8 +99,8 @@ int nfs_callback_up(void)
 	struct svc_rqst *rqstp;
 	int ret = 0;
 
-	lock_kernel();
 	mutex_lock(&nfs_callback_mutex);
+	lock_kernel();
 	if (nfs_callback_info.users++ || nfs_callback_info.task != NULL)
 		goto out;
 	serv = svc_create(&nfs4_callback_program, NFS4_CALLBACK_BUFSIZE, NULL);
@@ -142,8 +142,8 @@ out:
 	 */
 	if (serv)
 		svc_destroy(serv);
-	mutex_unlock(&nfs_callback_mutex);
 	unlock_kernel();
+	mutex_unlock(&nfs_callback_mutex);
 	return ret;
 out_err:
 	dprintk("Couldn't create callback socket or server thread; err = %d\n",
@@ -157,13 +157,13 @@ out_err:
  */
 void nfs_callback_down(void)
 {
-	lock_kernel();
 	mutex_lock(&nfs_callback_mutex);
+	lock_kernel();
 	nfs_callback_info.users--;
 	if (nfs_callback_info.users == 0 && nfs_callback_info.task != NULL)
 		kthread_stop(nfs_callback_info.task);
-	mutex_unlock(&nfs_callback_mutex);
 	unlock_kernel();
+	mutex_unlock(&nfs_callback_mutex);
 }
 
 static int nfs_callback_authenticate(struct svc_rqst *rqstp)
Signature · 1 line
1.5.4.1
#1 lore raw

PATCH 1/1 NLM: hold BKL when clearing global lockd task and serv vars

The global task and serv pointers for lockd are normally protected by the nlmsvc_mutex. The exception is when the lockd exits abnormally. When this occurs, these variables are cleared without any locking.

Make sure that these variables are cleared while still holding the BKL, and have lockd_up and lockd_down take the BKL.

---
 fs/lockd/svc.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
fs/lockd/svc.c +6 -3
index 66b5c98..efba919 100644
@@ -191,12 +191,11 @@ lockd(void *vrqstp)
 	if (nlmsvc_ops)
 		nlmsvc_invalidate_all();
 	nlm_shutdown_hosts();
-
-	unlock_kernel();
-
 	nlmsvc_task = NULL;
 	nlmsvc_serv = NULL;
 
+	unlock_kernel();
+
 	/* Exit the RPC thread */
 	svc_exit_thread(rqstp);
 
@@ -250,6 +249,7 @@ lockd_up(int proto) /* Maybe add a 'family' option when IPv6 is supported ?? */
 	int		error = 0;
 
 	mutex_lock(&nlmsvc_mutex);
+	lock_kernel();
 	/*
 	 * Check whether we're already up and running.
 	 */
@@ -312,6 +312,7 @@ destroy_and_out:
 out:
 	if (!error)
 		nlmsvc_users++;
+	unlock_kernel();
 	mutex_unlock(&nlmsvc_mutex);
 	return error;
 }
@@ -324,6 +325,7 @@ void
 lockd_down(void)
 {
 	mutex_lock(&nlmsvc_mutex);
+	lock_kernel();
 	if (nlmsvc_users) {
 		if (--nlmsvc_users)
 			goto out;
@@ -339,6 +341,7 @@ lockd_down(void)
 	}
 	kthread_stop(nlmsvc_task);
 out:
+	unlock_kernel();
 	mutex_unlock(&nlmsvc_mutex);
 }
 EXPORT_SYMBOL(lockd_down);
Signature · 1 line
1.5.4.1
#2 lore raw

Re: [PATCH] NLM: hold BKL when clearing global lockd task and serv vars

Quoted 3 lines · Jeff Layton

The global task and serv pointers for lockd are normally protected by the nlmsvc_mutex. The exception is when the lockd exits abnormally. When this occurs, these variables are cleared without any locking.

Shouldn't we get rid of the case where it exits abnormally instead?

#3 lore raw

Re: [PATCH] NLM: hold BKL when clearing global lockd task and serv vars

Quoted 7 lines · On Mon, 7 Apr 2008 12:45:01 -0400 Christoph Hellwig <[email protected]> wrote:
Quoted 3 lines · Jeff Layton

The global task and serv pointers for lockd are normally protected by the nlmsvc_mutex. The exception is when the lockd exits abnormally. When this occurs, these variables are cleared without any locking.

Shouldn't we get rid of the case where it exits abnormally instead?

Not a bad idea. After chatting with Christoph a bit on IRC, I suppose we have 2 options if we want to pursue this. When we get an unexpected error from svc_recv(), we could:

1) sleep for a bit and then retry

2) call schedule() and sleep until kthread_stop shuts down the thread

I think #1 is probably the best option. It's certainly the more fault tolerant. That also fixes another potential problem -- right now if the thread exits and the nlmsvc_users count isn't 0, then we can potentially BUG() on the next lockd_up/lockd_down.

Any thoughts on what an appropriate sleep timeout should be when this happens? I was thinking 1s or so...

Trond, Bruce, any thoughts?

Signature · 1 line
Jeff Layton <[email protected]>
#4 lore raw

Re: [PATCH] NLM: hold BKL when clearing global lockd task and serv vars

In reply to Christoph Hellwig
Quoted 6 lines · Christoph Hellwig
Quoted 3 lines · Jeff Layton

The global task and serv pointers for lockd are normally protected by the nlmsvc_mutex. The exception is when the lockd exits abnormally. When this occurs, these variables are cleared without any locking.

Shouldn't we get rid of the case where it exits abnormally instead?

I tried to figure out when this could actually occur (when can svc_recv() return an error other than -EINTR or -EAGAIN?), and got lost in sock_recvmsg():

- svc_recv() itself returns only -EAGAIN or the return from ->xpo_recvfrom().
- the only xpo_recvfrom() that's interesting is svc_tcp_recvfrom(), which can return the error it gets from svc_recvfrom(), which can return the error from kernel_recvmsg(), which gets its return from sock_recvmsg().

Since __sock_recvmsg() has a security hook, it looks like we can end up with an -EACCES from selinux?

So one case would be selinux deciding we weren't allowed to receive packets from this socket. Huh.

--b.

#5 lore raw

Re: [PATCH] NLM: hold BKL when clearing global lockd task and serv vars

Quoted 19 lines · J. Bruce Fields
Quoted 6 lines · Christoph Hellwig
Quoted 3 lines · Jeff Layton

The global task and serv pointers for lockd are normally protected by the nlmsvc_mutex. The exception is when the lockd exits abnormally. When this occurs, these variables are cleared without any locking.

Shouldn't we get rid of the case where it exits abnormally instead?

I tried to figure out when this could actually occur (when can svc_recv() return an error other than -EINTR or -EAGAIN?), and got lost in sock_recvmsg():

- svc_recv() itself returns only -EAGAIN or the return from ->xpo_recvfrom().
- the only xpo_recvfrom() that's interesting is svc_tcp_recvfrom(), which can return the error it gets from svc_recvfrom(), which can return the error from kernel_recvmsg(), which gets its return from sock_recvmsg().

Quoted 2 lines

Since __sock_recvmsg() has a security hook, it looks like we can end up with an -EACCES from selinux?

FWIW: I believe that if svc_recv returns anything other then -EINTR or -EAGAIN, the service thread exits. I believe that the current design (could be broken) is that if the transport finds an error, the action is to set the XPT_CLOSE bit, enqueue the transport and return -EAGAIN. This will cause the service thread to call svc_recv again and close processing to occur.

Quoted 9 lines

So one case would be selinux deciding we weren't allowed to receive packets from this socket. Huh.

--b.
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw

Re: [PATCH] NLM: hold BKL when clearing global lockd task and serv vars

In reply to J. Bruce Fields
Quoted 19 lines · On Mon, 7 Apr 2008 13:56:15 -0400 "J. Bruce Fields" <[email protected]>…
Quoted 6 lines · Christoph Hellwig
Quoted 3 lines · Jeff Layton

The global task and serv pointers for lockd are normally protected by the nlmsvc_mutex. The exception is when the lockd exits abnormally. When this occurs, these variables are cleared without any locking.

Shouldn't we get rid of the case where it exits abnormally instead?

I tried to figure out when this could actually occur (when can svc_recv() return an error other than -EINTR or -EAGAIN?), and got lost in sock_recvmsg():

- svc_recv() itself returns only -EAGAIN or the return from ->xpo_recvfrom().
- the only xpo_recvfrom() that's interesting is svc_tcp_recvfrom(), which can return the error it gets from svc_recvfrom(), which can return the error from kernel_recvmsg(), which gets its return from sock_recvmsg().

Quoted 5 lines

Since __sock_recvmsg() has a security hook, it looks like we can end up with an -EACCES from selinux?

So one case would be selinux deciding we weren't allowed to receive packets from this socket. Huh.

I got lost there too, but I would suspect that there are other errors that can bubble up from the lower networking layers as well. Even if there aren't currently, it's probably still prudent to assume that it's a possibility and code for it.

I tend to think the safest thing is probably to do a long sleep (1s or so and retry when we get an error (maybe also a ratelimited printk?). It's unlikely to do any harm (other than a few wasted CPU cycles), and if the error is transient then we have the possibility to recover and continue normal operation.

The current situation is rather bad. If lockd exits abnormally, then we'll BUG if someone happens to do a lockd_down().

Signature · 1 line
Jeff Layton <[email protected]>
#7 lore raw

Re: [PATCH] NLM: hold BKL when clearing global lockd task and serv vars

Quoted 28 lines · Jeff Layton
Quoted 19 lines · On Mon, 7 Apr 2008 13:56:15 -0400 "J. Bruce Fields" <[email protected]>…
Quoted 6 lines · Christoph Hellwig
Quoted 3 lines · Jeff Layton

The global task and serv pointers for lockd are normally protected by the nlmsvc_mutex. The exception is when the lockd exits abnormally. When this occurs, these variables are cleared without any locking.

Shouldn't we get rid of the case where it exits abnormally instead?

I tried to figure out when this could actually occur (when can svc_recv() return an error other than -EINTR or -EAGAIN?), and got lost in sock_recvmsg():

- svc_recv() itself returns only -EAGAIN or the return from ->xpo_recvfrom().
- the only xpo_recvfrom() that's interesting is svc_tcp_recvfrom(), which can return the error it gets from svc_recvfrom(), which can return the error from kernel_recvmsg(), which gets its return from sock_recvmsg().

Quoted 5 lines

Since __sock_recvmsg() has a security hook, it looks like we can end up with an -EACCES from selinux?

So one case would be selinux deciding we weren't allowed to receive packets from this socket. Huh.

Quoted 7 lines

I got lost there too, but I would suspect that there are other errors that can bubble up from the lower networking layers as well. Even if there aren't currently, it's probably still prudent to assume that it's a possibility and code for it.

I tend to think the safest thing is probably to do a long sleep (1s or so and retry when we get an error (maybe also a ratelimited printk?).

Yeah, I guess I can't think of anything better.

--b.

Quoted 3 lines

It's unlikely to do any harm (other than a few wasted CPU cycles), and if the error is transient then we have the possibility to recover and continue normal operation.

#8 lore raw

Re: [PATCH] NLM: hold BKL when clearing global lockd task and serv vars

Quoted 34 lines · On Mon, 7 Apr 2008 16:50:27 -0400 "J. Bruce Fields" <[email protected]>…
Quoted 33 lines · Jeff Layton
Quoted 19 lines · On Mon, 7 Apr 2008 13:56:15 -0400 "J. Bruce Fields" <[email protected]>…
Quoted 6 lines · Christoph Hellwig
Quoted 3 lines · Jeff Layton

The global task and serv pointers for lockd are normally protected by the nlmsvc_mutex. The exception is when the lockd exits abnormally. When this occurs, these variables are cleared without any locking.

Shouldn't we get rid of the case where it exits abnormally instead?

I tried to figure out when this could actually occur (when can svc_recv() return an error other than -EINTR or -EAGAIN?), and got lost in sock_recvmsg():

- svc_recv() itself returns only -EAGAIN or the return from ->xpo_recvfrom().
- the only xpo_recvfrom() that's interesting is svc_tcp_recvfrom(), which can return the error it gets from svc_recvfrom(), which can return the error from kernel_recvmsg(), which gets its return from sock_recvmsg().

Quoted 5 lines

Since __sock_recvmsg() has a security hook, it looks like we can end up with an -EACCES from selinux?

So one case would be selinux deciding we weren't allowed to receive packets from this socket. Huh.

I got lost there too, but I would suspect that there are other errors that can bubble up from the lower networking layers as well. Even if there aren't currently, it's probably still prudent to assume that it's a possibility and code for it.

Quoted 5 lines
Quoted 2 lines

I tend to think the safest thing is probably to do a long sleep (1s or so and retry when we get an error (maybe also a ratelimited printk?).

Yeah, I guess I can't think of anything better.

Ok, I went ahead and did patches for this and gave them a quick test this morning. Obviously, these are hard to fully unit test since this seems to be a very uncommon occurrence.

Any thoughts?

Signature · 1 line
Jeff Layton <[email protected]>
#9 lore raw

Re: [PATCH] NLM: hold BKL when clearing global lockd task and serv vars

Quoted 40 lines · Jeff Layton
Quoted 37 lines · On Mon, 7 Apr 2008 16:50:27 -0400 "J. Bruce Fields" <[email protected]>…
Quoted 35 lines · Jeff Layton
Quoted 19 lines · On Mon, 7 Apr 2008 13:56:15 -0400 "J. Bruce Fields" <[email protected]>…
Quoted 6 lines · Christoph Hellwig
Quoted 3 lines · Jeff Layton

The global task and serv pointers for lockd are normally protected by the nlmsvc_mutex. The exception is when the lockd exits abnormally. When this occurs, these variables are cleared without any locking.

Shouldn't we get rid of the case where it exits abnormally instead?

I tried to figure out when this could actually occur (when can svc_recv() return an error other than -EINTR or -EAGAIN?), and got lost in sock_recvmsg():

- svc_recv() itself returns only -EAGAIN or the return from ->xpo_recvfrom().
- the only xpo_recvfrom() that's interesting is svc_tcp_recvfrom(), which can return the error it gets from svc_recvfrom(), which can return the error from kernel_recvmsg(), which gets its return from sock_recvmsg().

Quoted 5 lines

Since __sock_recvmsg() has a security hook, it looks like we can end up with an -EACCES from selinux?

So one case would be selinux deciding we weren't allowed to receive packets from this socket. Huh.

I got lost there too, but I would suspect that there are other errors that can bubble up from the lower networking layers as well. Even if there aren't currently, it's probably still prudent to assume that it's a possibility and code for it.

I tend to think the safest thing is probably to do a long sleep (1s or so and retry when we get an error (maybe also a ratelimited printk?).

Quoted 6 lines
Quoted 2 lines

Yeah, I guess I can't think of anything better.

Ok, I went ahead and did patches for this and gave them a quick test this morning. Obviously, these are hard to fully unit test since this seems to be a very uncommon occurrence.

I suppose this could probably be reproduced with some selinux magic.

Quoted 1 line

Any thoughts?

If anyone does ever hit this and it doesn't go away, the printk (even with the ratelimiting) could be pretty annoying, so it might be worth arranging to print this just once. But perhaps we can wait and see if that actually happens.

Given what appears to be a very unusual crash, and what I'm assuming is an impending release, I suppose we should wait for the merge window (but possibly also submit to 2.6.25.x).

--b.

#10 lore raw

Re: [PATCH] NLM: hold BKL when clearing global lockd task and serv vars

Quoted 41 lines · On Tue, 8 Apr 2008 12:28:21 -0400 "J. Bruce Fields" <[email protected]>…
Quoted 40 lines · Jeff Layton
Quoted 37 lines · On Mon, 7 Apr 2008 16:50:27 -0400 "J. Bruce Fields" <[email protected]>…
Quoted 35 lines · Jeff Layton
Quoted 19 lines · On Mon, 7 Apr 2008 13:56:15 -0400 "J. Bruce Fields" <[email protected]>…
Quoted 6 lines · Christoph Hellwig
Quoted 3 lines · Jeff Layton

The global task and serv pointers for lockd are normally protected by the nlmsvc_mutex. The exception is when the lockd exits abnormally. When this occurs, these variables are cleared without any locking.

Shouldn't we get rid of the case where it exits abnormally instead?

I tried to figure out when this could actually occur (when can svc_recv() return an error other than -EINTR or -EAGAIN?), and got lost in sock_recvmsg():

- svc_recv() itself returns only -EAGAIN or the return from ->xpo_recvfrom().
- the only xpo_recvfrom() that's interesting is svc_tcp_recvfrom(), which can return the error it gets from svc_recvfrom(), which can return the error from kernel_recvmsg(), which gets its return from sock_recvmsg().

Quoted 5 lines

Since __sock_recvmsg() has a security hook, it looks like we can end up with an -EACCES from selinux?

So one case would be selinux deciding we weren't allowed to receive packets from this socket. Huh.

I got lost there too, but I would suspect that there are other errors that can bubble up from the lower networking layers as well. Even if there aren't currently, it's probably still prudent to assume that it's a possibility and code for it.

I tend to think the safest thing is probably to do a long sleep (1s or so and retry when we get an error (maybe also a ratelimited printk?).

Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

Yeah, I guess I can't think of anything better.

Ok, I went ahead and did patches for this and gave them a quick test this morning. Obviously, these are hard to fully unit test since this seems to be a very uncommon occurrence.

I suppose this could probably be reproduced with some selinux magic.

Good idea. I'll chat with our SELinux guys and see if they can point me in the right direction on this.

Quoted 7 lines
Quoted 1 line

Any thoughts?

If anyone does ever hit this and it doesn't go away, the printk (even with the ratelimiting) could be pretty annoying, so it might be worth arranging to print this just once. But perhaps we can wait and see if that actually happens.

I tend to think that this is most likely to happen when there's a significant problem in lower level networking (or maybe a VM problem?). SELinux is also a possibility, as you pointed out, but I'm not sure how much kernel threads are affected by SELinux...

In any case, if this happens, then we're probably going to have bigger problems than a printk every second. My suggestion would be that we keep it like this for now, and reconsider it if it turns out to be a problem...

Quoted 4 lines

Given what appears to be a very unusual crash, and what I'm assuming is an impending release, I suppose we should wait for the merge window (but possibly also submit to 2.6.25.x).

Yes. I was thinking that all of this should probably be 2.6.26 material (along with all of the kthread conversion patches). Aside from this possibly happening in Michael's crash, I've never seen lockd exit abnormally like this.

Signature · 1 line
Jeff Layton <[email protected]>
#11 lore raw

Re: [PATCH] NLM: hold BKL when clearing global lockd task and serv vars

In reply to J. Bruce Fields
Quoted 41 lines · On Tue, 8 Apr 2008 12:28:21 -0400 "J. Bruce Fields" <[email protected]>…
Quoted 40 lines · Jeff Layton
Quoted 37 lines · On Mon, 7 Apr 2008 16:50:27 -0400 "J. Bruce Fields" <[email protected]>…
Quoted 35 lines · Jeff Layton
Quoted 19 lines · On Mon, 7 Apr 2008 13:56:15 -0400 "J. Bruce Fields" <[email protected]>…
Quoted 6 lines · Christoph Hellwig
Quoted 3 lines · Jeff Layton

The global task and serv pointers for lockd are normally protected by the nlmsvc_mutex. The exception is when the lockd exits abnormally. When this occurs, these variables are cleared without any locking.

Shouldn't we get rid of the case where it exits abnormally instead?

I tried to figure out when this could actually occur (when can svc_recv() return an error other than -EINTR or -EAGAIN?), and got lost in sock_recvmsg():

- svc_recv() itself returns only -EAGAIN or the return from ->xpo_recvfrom().
- the only xpo_recvfrom() that's interesting is svc_tcp_recvfrom(), which can return the error it gets from svc_recvfrom(), which can return the error from kernel_recvmsg(), which gets its return from sock_recvmsg().

Quoted 5 lines

Since __sock_recvmsg() has a security hook, it looks like we can end up with an -EACCES from selinux?

So one case would be selinux deciding we weren't allowed to receive packets from this socket. Huh.

I got lost there too, but I would suspect that there are other errors that can bubble up from the lower networking layers as well. Even if there aren't currently, it's probably still prudent to assume that it's a possibility and code for it.

I tend to think the safest thing is probably to do a long sleep (1s or so and retry when we get an error (maybe also a ratelimited printk?).

Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

Yeah, I guess I can't think of anything better.

Ok, I went ahead and did patches for this and gave them a quick test this morning. Obviously, these are hard to fully unit test since this seems to be a very uncommon occurrence.

I suppose this could probably be reproduced with some selinux magic.

This turns out to be rather difficult. SELinux apparently doesn't have much support for restricting kernel threads. I ended up hacking together the following fault-injection patch to unit test this:

--------[snip]--------

include/linux/sunrpc/debug.h +1 -0
index 10709cb..3e86cba 100644
@@ -24,6 +24,7 @@
 #define RPCDBG_SVCDSP		0x0200
 #define RPCDBG_MISC		0x0400
 #define RPCDBG_CACHE		0x0800
+#define RPCDBG_BREAKME		0x1000
 #define RPCDBG_ALL		0x7fff
 
 #ifdef __KERNEL__
net/sunrpc/svc_xprt.c +3 -1
index d8e8d79..0333c64 100644
@@ -569,6 +569,9 @@ int svc_recv(struct svc_rqst *rqstp, long timeout)
 	struct xdr_buf		*arg;
 	DECLARE_WAITQUEUE(wait, current);
 
+	if (rpc_debug & RPCDBG_BREAKME)
+		return -EACCES;
+
 	dprintk("svc: server %p waiting for data (to = %ld)\n",
 		rqstp, timeout);
--------[snip]--------

...with that, I can see the new code working as expected, but I think you have a point that those printk's could get to be rather annoying. I've got a new set of patches that I'll send out that has it only print the warning on the first unexpected error, or if the error changes.

Thanks,

Signature · 1 line
Jeff Layton <[email protected]>
#12 lore raw

Re: [PATCH] NLM: hold BKL when clearing global lockd task and serv vars

In reply to J. Bruce Fields
Quoted 59 lines · J. Bruce Fields
Quoted 51 lines · Jeff Layton
Quoted 48 lines · On Mon, 7 Apr 2008 16:50:27 -0400 "J. Bruce Fields" <[email protected]>…
Quoted 46 lines · Jeff Layton
Quoted 23 lines · On Mon, 7 Apr 2008 13:56:15 -0400 "J. Bruce Fields" <[email protected]>…
Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · Jeff Layton

The global task and serv pointers for lockd are normally protected by
the nlmsvc_mutex. The exception is when the lockd exits abnormally. When
this occurs, these variables are cleared without any locking.

Shouldn't we get rid of the case where it exits abnormally instead?

I tried to figure out when this could actually occur (when can svc_recv() return an error other than -EINTR or -EAGAIN?), and got lost
in sock_recvmsg():

- svc_recv() itself returns only -EAGAIN or the return from ->xpo_recvfrom().
- the only xpo_recvfrom() that's interesting is svc_tcp_recvfrom(), which can return the error it gets from svc_recvfrom(), which can return the error from kernel_recvmsg(), which gets its return from sock_recvmsg().

Quoted 7 lines

Since __sock_recvmsg() has a security hook, it looks like we can end up
with an -EACCES from selinux?

So one case would be selinux deciding we weren't allowed to receive
packets from this socket. Huh.

I got lost there too, but I would suspect that there are other errors
that can bubble up from the lower networking layers as well. Even if
there aren't currently, it's probably still prudent to assume that it's
a possibility and code for it.

I tend to think the safest thing is probably to do a long sleep (1s or
so and retry when we get an error (maybe also a ratelimited printk?).

Quoted 6 lines
Quoted 2 lines

Yeah, I guess I can't think of anything better.

Ok, I went ahead and did patches for this and gave them a quick test this morning. Obviously, these are hard to fully unit test since this seems to be a very uncommon occurrence.

Quoted 8 lines

I suppose this could probably be reproduced with some selinux magic.

Quoted 1 line

Any thoughts?

If anyone does ever hit this and it doesn't go away, the printk (even with the ratelimiting) could be pretty annoying, so it might be worth arranging to print this just once. But perhaps we can wait and see if that actually happens.

Coding by contract would be useful here.

If svc_recv() returns only specific error codes (and never anything else) then its callers don't need any special logic for "unrecognized" return codes.

Thus, ensuring that svc_recv() returns only EINTR, EACCES, or EAGAIN would limit the complexity and failure modes of its callers.

--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com

#13 lore raw

Re: [PATCH] NLM: hold BKL when clearing global lockd task and serv vars

Quoted 70 lines · On Tue, 8 Apr 2008 16:08:40 -0400 Chuck Lever <[email protected]> wrote:
Quoted 59 lines · J. Bruce Fields
Quoted 51 lines · Jeff Layton
Quoted 48 lines · On Mon, 7 Apr 2008 16:50:27 -0400 "J. Bruce Fields" <[email protected]>…
Quoted 46 lines · Jeff Layton
Quoted 23 lines · On Mon, 7 Apr 2008 13:56:15 -0400 "J. Bruce Fields" <[email protected]>…
Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · Jeff Layton

The global task and serv pointers for lockd are normally protected by
the nlmsvc_mutex. The exception is when the lockd exits abnormally. When
this occurs, these variables are cleared without any locking.

Shouldn't we get rid of the case where it exits abnormally instead?

I tried to figure out when this could actually occur (when can svc_recv() return an error other than -EINTR or -EAGAIN?), and got lost
in sock_recvmsg():

- svc_recv() itself returns only -EAGAIN or the return from ->xpo_recvfrom().
- the only xpo_recvfrom() that's interesting is svc_tcp_recvfrom(), which can return the error it gets from svc_recvfrom(), which can return the error from kernel_recvmsg(), which gets its return from sock_recvmsg().

Quoted 7 lines

Since __sock_recvmsg() has a security hook, it looks like we can end up
with an -EACCES from selinux?

So one case would be selinux deciding we weren't allowed to receive
packets from this socket. Huh.

I got lost there too, but I would suspect that there are other errors
that can bubble up from the lower networking layers as well. Even if
there aren't currently, it's probably still prudent to assume that it's
a possibility and code for it.

I tend to think the safest thing is probably to do a long sleep (1s or
so and retry when we get an error (maybe also a ratelimited printk?).

Quoted 6 lines
Quoted 2 lines

Yeah, I guess I can't think of anything better.

Ok, I went ahead and did patches for this and gave them a quick test this morning. Obviously, these are hard to fully unit test since this seems to be a very uncommon occurrence.

Quoted 8 lines

I suppose this could probably be reproduced with some selinux magic.

Quoted 1 line

Any thoughts?

If anyone does ever hit this and it doesn't go away, the printk (even with the ratelimiting) could be pretty annoying, so it might be worth arranging to print this just once. But perhaps we can wait and see if that actually happens.

Quoted 9 lines

Coding by contract would be useful here.

If svc_recv() returns only specific error codes (and never anything else) then its callers don't need any special logic for "unrecognized" return codes.

Thus, ensuring that svc_recv() returns only EINTR, EACCES, or EAGAIN would limit the complexity and failure modes of its callers.

I don't think that gains us much. The errors of interest are basically EINTR, EAGAIN and "everything else". If we have to deal with EACCES anyway, then it's not really too much more complexity to just deal with "everything else" at this level.

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