Skip to contentSkip to conversation

sunrpc: what prevents an xprt from being freed before task_cleanup runs?

PATCH In review Jeff Layton 5 participants 9 messages Aug 3, 2010 5 messages not in the archive

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

We got a report recently about a panic in RHEL5 (2.6.18 based kernel). The problem appears to be that a task_cleanup workqueue job ran and got passed a pointer to an xprt that had been freed. The bug is here in case anyone is interested in the details:

    https://bugzilla.redhat.com/show_bug.cgi?id=611938

The situation seems to be pretty difficult to reproduce, but I don't see anything that's intended to ensure that this doesn't occur in RHEL5 or mainline. The task_cleanup workqueue job doesn't hold a reference to the xprt, and the job isn't canceled when the xprt is torn down.

Bruce had a look and suggested that we may need something like the patch below (pasted in, so it probably won't apply correctly). I've tested a backported version of it on RHEL5 and it seems to work fine.

Is it reasonable to cancel task_cleanup when destroying the xprt? Or, am I missing something that should prevent this situation in mainline (and perhaps isn't in RHEL5's kernel).

Any help is appreciated...

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

net/sunrpc/xprt.c +1 -0
index dcd0132..2a1f664 100644
@@ -1129,6 +1129,7 @@ static void xprt_destroy(struct kref *kref)
  rpc_destroy_wait_queue(&xprt->sending);
  rpc_destroy_wait_queue(&xprt->resend);
  rpc_destroy_wait_queue(&xprt->backlog);
+ cancel_work_sync(&xprt->task_cleanup);
  /*
   * Tear down transport state and free the rpc_xprt
   */

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

Thanks,

Signature · 5 lines
Jeff Layton <[email protected]>
--
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

A message that is not in the archive (sent off-list or not yet received): 20100803132453.4fa18444-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org

#2 lore raw
Quoted 37 lines · Jeff Layton

We got a report recently about a panic in RHEL5 (2.6.18 based kernel). The problem appears to be that a task_cleanup workqueue job ran and got passed a pointer to an xprt that had been freed. The bug is here in case anyone is interested in the details:

    https://bugzilla.redhat.com/show_bug.cgi?id=611938

The situation seems to be pretty difficult to reproduce, but I don't see anything that's intended to ensure that this doesn't occur in RHEL5 or mainline. The task_cleanup workqueue job doesn't hold a reference to the xprt, and the job isn't canceled when the xprt is torn down.

Bruce had a look and suggested that we may need something like the patch below (pasted in, so it probably won't apply correctly). I've tested a backported version of it on RHEL5 and it seems to work fine.

Is it reasonable to cancel task_cleanup when destroying the xprt? Or, am I missing something that should prevent this situation in mainline (and perhaps isn't in RHEL5's kernel).

Any help is appreciated...

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

net/sunrpc/xprt.c +1 -1
index dcd0132..2a1f664 100644
@@ -1129,6 +1129,7 @@ static void xprt_destroy(struct kref *kref)
  rpc_destroy_wait_queue(&xprt->sending);
  rpc_destroy_wait_queue(&xprt->resend);
  rpc_destroy_wait_queue(&xprt->backlog);
+ cancel_work_sync(&xprt->task_cleanup);
  /*
   * Tear down transport state and free the rpc_xprt
   */
-----------------------------[snip]---------------------------------
Quoted 1 line

Thanks,

How about doing a wait_on_bit_lock(&xprt->state, XPRT_LOCKED,...) instead?

Cheers
Trond

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

A message that is not in the archive (sent off-list or not yet received): 1280860815.9771.25.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org

#4 lore raw
Quoted 38 lines · Trond Myklebust
Quoted 37 lines · Jeff Layton

We got a report recently about a panic in RHEL5 (2.6.18 based kernel). The problem appears to be that a task_cleanup workqueue job ran and got passed a pointer to an xprt that had been freed. The bug is here in case anyone is interested in the details:

    https://bugzilla.redhat.com/show_bug.cgi?id=611938

The situation seems to be pretty difficult to reproduce, but I don't see anything that's intended to ensure that this doesn't occur in RHEL5 or mainline. The task_cleanup workqueue job doesn't hold a reference to the xprt, and the job isn't canceled when the xprt is torn down.

Bruce had a look and suggested that we may need something like the patch below (pasted in, so it probably won't apply correctly). I've tested a backported version of it on RHEL5 and it seems to work fine.

Is it reasonable to cancel task_cleanup when destroying the xprt? Or, am I missing something that should prevent this situation in mainline (and perhaps isn't in RHEL5's kernel).

Any help is appreciated...

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

net/sunrpc/xprt.c +1 -1
index dcd0132..2a1f664 100644
@@ -1129,6 +1129,7 @@ static void xprt_destroy(struct kref *kref)
  rpc_destroy_wait_queue(&xprt->sending);
  rpc_destroy_wait_queue(&xprt->resend);
  rpc_destroy_wait_queue(&xprt->backlog);
+ cancel_work_sync(&xprt->task_cleanup);
  /*
   * Tear down transport state and free the rpc_xprt
   */
-----------------------------[snip]---------------------------------
Quoted 4 lines
Quoted 1 line

Thanks,

How about doing a wait_on_bit_lock(&xprt->state, XPRT_LOCKED,...) instead?

Hmm... On the other hand, since xprt_destroy() may get called from inside the rpciod_workqueue, the wait_on_bit_lock() may end up deadlocking.

Nevermind, then. Let's go with the cancel_work_sync().

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

A message that is not in the archive (sent off-list or not yet received): 1280861363.12283.2.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org

#6 lore raw

PATCH 1/1 SUNRPC: prevent task_cleanup running on freed xprt

From: J. Bruce Fields <[email protected]>

We saw a report of a NULL dereference in xprt_autoclose:

	https://bugzilla.redhat.com/show_bug.cgi?id=611938

This appears to be the result of an xprt's task_cleanup running after the xprt is destroyed. Nothing in the current code appears to prevent that.

---
 net/sunrpc/xprt.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
Quoted 5 lines · Trond Myklebust

Hmm... On the other hand, since xprt_destroy() may get called from inside the rpciod_workqueue, the wait_on_bit_lock() may end up deadlocking.

Nevermind, then. Let's go with the cancel_work_sync().

Here you are--only if you don't have something equivalent already queued up.--b.

net/sunrpc/xprt.c +1 -0
index dcd0132..2a1f664 100644
@@ -1129,6 +1129,7 @@ static void xprt_destroy(struct kref *kref)
 	rpc_destroy_wait_queue(&xprt->sending);
 	rpc_destroy_wait_queue(&xprt->resend);
 	rpc_destroy_wait_queue(&xprt->backlog);
+	cancel_work_sync(&xprt->task_cleanup);
 	/*
 	 * Tear down transport state and free the rpc_xprt
 	 */
Signature · 6 lines
1.7.0.4

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

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

#8 lore raw

Re: [PATCH] SUNRPC: prevent task_cleanup running on freed xprt

Quoted 4 lines · J. Bruce Fields

From: J. Bruce Fields <[email protected]>

We saw a report of a NULL dereference in xprt_autoclose:

Quoted 8 lines
	https://bugzilla.redhat.com/show_bug.cgi?id=611938

This appears to be the result of an xprt's task_cleanup running after the xprt is destroyed. Nothing in the current code appears to prevent that.

---

Thanks. Applied to nfs-for-2.6.36...

Trond

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

#9 lore raw
In reply to Trond Myklebust
Quoted 38 lines · Trond Myklebust
Quoted 37 lines · Jeff Layton

We got a report recently about a panic in RHEL5 (2.6.18 based kernel). The problem appears to be that a task_cleanup workqueue job ran and got passed a pointer to an xprt that had been freed. The bug is here in case anyone is interested in the details:

    https://bugzilla.redhat.com/show_bug.cgi?id=611938

The situation seems to be pretty difficult to reproduce, but I don't see anything that's intended to ensure that this doesn't occur in RHEL5 or mainline. The task_cleanup workqueue job doesn't hold a reference to the xprt, and the job isn't canceled when the xprt is torn down.

Bruce had a look and suggested that we may need something like the patch below (pasted in, so it probably won't apply correctly). I've tested a backported version of it on RHEL5 and it seems to work fine.

Is it reasonable to cancel task_cleanup when destroying the xprt? Or, am I missing something that should prevent this situation in mainline (and perhaps isn't in RHEL5's kernel).

Any help is appreciated...

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

net/sunrpc/xprt.c +1 -1
index dcd0132..2a1f664 100644
@@ -1129,6 +1129,7 @@ static void xprt_destroy(struct kref *kref)
  rpc_destroy_wait_queue(&xprt->sending);
  rpc_destroy_wait_queue(&xprt->resend);
  rpc_destroy_wait_queue(&xprt->backlog);
+ cancel_work_sync(&xprt->task_cleanup);
  /*
   * Tear down transport state and free the rpc_xprt
   */
-----------------------------[snip]---------------------------------
Quoted 4 lines
Quoted 1 line

Thanks,

How about doing a wait_on_bit_lock(&xprt->state, XPRT_LOCKED,...) instead?

I'll believe you, but I don't get it: what guarantees that XPRT_LOCKED isn't cleared while xprt_autoclose autoclose is still running?

--b.

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

#11 lore raw
Quoted 39 lines · J. Bruce Fields
Quoted 38 lines · Trond Myklebust
Quoted 37 lines · Jeff Layton

We got a report recently about a panic in RHEL5 (2.6.18 based kernel). The problem appears to be that a task_cleanup workqueue job ran and got passed a pointer to an xprt that had been freed. The bug is here in case anyone is interested in the details:

    https://bugzilla.redhat.com/show_bug.cgi?id=611938

The situation seems to be pretty difficult to reproduce, but I don't see anything that's intended to ensure that this doesn't occur in RHEL5 or mainline. The task_cleanup workqueue job doesn't hold a reference to the xprt, and the job isn't canceled when the xprt is torn down.

Bruce had a look and suggested that we may need something like the patch below (pasted in, so it probably won't apply correctly). I've tested a backported version of it on RHEL5 and it seems to work fine.

Is it reasonable to cancel task_cleanup when destroying the xprt? Or, am I missing something that should prevent this situation in mainline (and perhaps isn't in RHEL5's kernel).

Any help is appreciated...

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

net/sunrpc/xprt.c +1 -1
index dcd0132..2a1f664 100644
@@ -1129,6 +1129,7 @@ static void xprt_destroy(struct kref *kref)
  rpc_destroy_wait_queue(&xprt->sending);
  rpc_destroy_wait_queue(&xprt->resend);
  rpc_destroy_wait_queue(&xprt->backlog);
+ cancel_work_sync(&xprt->task_cleanup);
  /*
   * Tear down transport state and free the rpc_xprt
   */
-----------------------------[snip]---------------------------------
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Thanks,

How about doing a wait_on_bit_lock(&xprt->state, XPRT_LOCKED,...) instead?

I'll believe you, but I don't get it: what guarantees that XPRT_LOCKED isn't cleared while xprt_autoclose autoclose is still running?

Look more closely: the callers that enqueue task_cleanup on the workqueue all ensure that XPRT_LOCKED is held, and it isn't released until the call to xprt_release_write() at the very end of xprt_autoclose().

The rpciod_workqueue deadlocking is an issue, though, so unfortunately, we won't be able to make use of the above.

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

#12 lore raw
Quoted 45 lines · Trond Myklebust
Quoted 44 lines · J. Bruce Fields
Quoted 42 lines · Trond Myklebust
Quoted 37 lines · Jeff Layton

We got a report recently about a panic in RHEL5 (2.6.18 based kernel). The problem appears to be that a task_cleanup workqueue job ran and got passed a pointer to an xprt that had been freed. The bug is here in case anyone is interested in the details:

    https://bugzilla.redhat.com/show_bug.cgi?id=611938

The situation seems to be pretty difficult to reproduce, but I don't see anything that's intended to ensure that this doesn't occur in RHEL5 or mainline. The task_cleanup workqueue job doesn't hold a reference to the xprt, and the job isn't canceled when the xprt is torn down.

Bruce had a look and suggested that we may need something like the patch below (pasted in, so it probably won't apply correctly). I've tested a backported version of it on RHEL5 and it seems to work fine.

Is it reasonable to cancel task_cleanup when destroying the xprt? Or, am I missing something that should prevent this situation in mainline (and perhaps isn't in RHEL5's kernel).

Any help is appreciated...

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

net/sunrpc/xprt.c +1 -1
index dcd0132..2a1f664 100644
@@ -1129,6 +1129,7 @@ static void xprt_destroy(struct kref *kref)
  rpc_destroy_wait_queue(&xprt->sending);
  rpc_destroy_wait_queue(&xprt->resend);
  rpc_destroy_wait_queue(&xprt->backlog);
+ cancel_work_sync(&xprt->task_cleanup);
  /*
   * Tear down transport state and free the rpc_xprt
   */
-----------------------------[snip]---------------------------------
Quoted 1 line

Thanks,

How about doing a wait_on_bit_lock(&xprt->state, XPRT_LOCKED,...) instead?

Quoted 7 lines
Quoted 2 lines

I'll believe you, but I don't get it: what guarantees that XPRT_LOCKED isn't cleared while xprt_autoclose autoclose is still running?

Look more closely: the callers that enqueue task_cleanup on the workqueue all ensure that XPRT_LOCKED is held, and it isn't released until the call to xprt_release_write() at the very end of xprt_autoclose().

I see that (assuming snd_task is always NULL--but, OK, I think I see why that's true), but we still dereference the xprt after returning from xprt_release_write(). Only to drop the transport_lock, but I don't see why there isn't a race.

Quoted 2 lines

The rpciod_workqueue deadlocking is an issue, though, so unfortunately, we won't be able to make use of the above.

Yeah, OK, it was just bugging me that I didn't feel like I understood how XPRT_LOCKED is used.

--b.

#13 lore raw
In reply to Trond Myklebust
Quoted 38 lines · On Tue, 03 Aug 2010 14:40:15 -0400 Trond Myklebust…
Quoted 37 lines · Jeff Layton

We got a report recently about a panic in RHEL5 (2.6.18 based kernel). The problem appears to be that a task_cleanup workqueue job ran and got passed a pointer to an xprt that had been freed. The bug is here in case anyone is interested in the details:

    https://bugzilla.redhat.com/show_bug.cgi?id=611938

The situation seems to be pretty difficult to reproduce, but I don't see anything that's intended to ensure that this doesn't occur in RHEL5 or mainline. The task_cleanup workqueue job doesn't hold a reference to the xprt, and the job isn't canceled when the xprt is torn down.

Bruce had a look and suggested that we may need something like the patch below (pasted in, so it probably won't apply correctly). I've tested a backported version of it on RHEL5 and it seems to work fine.

Is it reasonable to cancel task_cleanup when destroying the xprt? Or, am I missing something that should prevent this situation in mainline (and perhaps isn't in RHEL5's kernel).

Any help is appreciated...

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

net/sunrpc/xprt.c +1 -1
index dcd0132..2a1f664 100644
@@ -1129,6 +1129,7 @@ static void xprt_destroy(struct kref *kref)
  rpc_destroy_wait_queue(&xprt->sending);
  rpc_destroy_wait_queue(&xprt->resend);
  rpc_destroy_wait_queue(&xprt->backlog);
+ cancel_work_sync(&xprt->task_cleanup);
  /*
   * Tear down transport state and free the rpc_xprt
   */
-----------------------------[snip]---------------------------------
Quoted 5 lines
Quoted 1 line

Thanks,

How about doing a wait_on_bit_lock(&xprt->state, XPRT_LOCKED,...) instead?

I haven't quite grokked what XPRT_LOCKED is supposed to signify. What would be the advantage of doing that over just killing off the task_cleanup job? It seems like if we're tearing down the xprt then waiting for task_cleanup to run is sort of pointless -- xs_destroy will take care of closing the socket anyway.

Also, if we do go that route, do we need a wake_up_bit call in xprt_clear_locked?

Thanks,

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