All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/2] orangefs: fix double-unlock issue in service_operation().
@ 2020-05-23  4:35 wu000273
  2020-05-23  5:41 ` Al Viro
  0 siblings, 1 reply; 2+ messages in thread
From: wu000273 @ 2020-05-23  4:35 UTC (permalink / raw)
  To: hubcap; +Cc: martin, devel, linux-kernel, kjlu, wu000273

From: Qiushi Wu <wu000273@umn.edu>

spin_unlock(&op->lock) is called before calling wake_up_interruptible().
But spin_unlock() was called again after a call of the function
"wait_for_matching_downcall" failed. Fix this issue by remove
the second spin_unlock().

Signed-off-by: Qiushi Wu <wu000273@umn.edu>
---
 fs/orangefs/waitqueue.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/fs/orangefs/waitqueue.c b/fs/orangefs/waitqueue.c
index beafc33d57be..3981507ad920 100644
--- a/fs/orangefs/waitqueue.c
+++ b/fs/orangefs/waitqueue.c
@@ -152,7 +152,6 @@ int service_operation(struct orangefs_kernel_op_s *op,
 
 	/* got matching downcall; make sure status is in errno format */
 	if (!ret) {
-		spin_unlock(&op->lock);
 		op->downcall.status =
 		    orangefs_normalize_to_errno(op->downcall.status);
 		ret = op->downcall.status;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 2/2] orangefs: fix double-unlock issue in service_operation().
  2020-05-23  4:35 [PATCH 2/2] orangefs: fix double-unlock issue in service_operation() wu000273
@ 2020-05-23  5:41 ` Al Viro
  0 siblings, 0 replies; 2+ messages in thread
From: Al Viro @ 2020-05-23  5:41 UTC (permalink / raw)
  To: wu000273; +Cc: hubcap, martin, devel, linux-kernel, kjlu

On Fri, May 22, 2020 at 11:35:51PM -0500, wu000273@umn.edu wrote:
> From: Qiushi Wu <wu000273@umn.edu>
> 
> spin_unlock(&op->lock) is called before calling wake_up_interruptible().
> But spin_unlock() was called again after a call of the function
> "wait_for_matching_downcall" failed.

Yes, it was.

> Fix this issue by remove
> the second spin_unlock().

Why is that a bug?  That's not an idle question - you could demonstrate
that if you had reproduced an unbalanced unlock experimentally, or you
could've proven it possible by analysis of the source.

The former ought to be clearly reported; the latter... AFAICS, your
reasoning is
	1) at the time of wait_for_matching_downcall() call the spinlock
is not being held, since we'd unlocked it upstream of that call and had
done nothing that could have reacquired it.
	2) after the return from that function we are doing unlock.
That is a bug, because one should not unlock a spinlock that is not
locked.

The gap in that proof is the unverified assumption that the locking
conditions upon return from wait_for_matching_downcall() are the same
as upon its call.  IF that assumption holds, there is, indeed a bug.
Now, a look at the function in question shows
	* a comment right before it claiming that it
" * Returns with op->lock taken.".  Which might or might not be correct.
	* one of the wait_for_completion...() called; that clearly
indicates that no spinlocks should be held upon the entry.
	* unconditional spin_lock(&op->lock); right after that.
	* several predicates checked, apparently some debugging
output possibly produced and a value returned.  The predicates
(op_state_service(), op_state_purged()) are clearly locking-neutral -
grep shows
fs/orangefs/orangefs-kernel.h:154:#define op_state_serviced(op)    ((op)->op_state & OP_VFS_STATE_SERVICED)
fs/orangefs/orangefs-kernel.h:155:#define op_state_purged(op)      ((op)->op_state & OP_VFS_STATE_PURGED)
so it's plain arithmetics.  The same, of course, applies to
comparisons.

In other words, the function *does* acquire that spinlock and
does not release it, regardless of the value it returns.  Which
means that your patch would very likely to cause deadlocks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-05-23  5:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-23  4:35 [PATCH 2/2] orangefs: fix double-unlock issue in service_operation() wu000273
2020-05-23  5:41 ` Al Viro

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.