Distributed Replicated Block Device (DRBD) development
 help / color / mirror / Atom feed
* [Drbd-dev] [PATCH] Fixed possible use after free in drbd_thread_setup
@ 2017-12-21 17:53 johannes
  2017-12-22 14:50 ` Lars Ellenberg
  0 siblings, 1 reply; 2+ messages in thread
From: johannes @ 2017-12-21 17:53 UTC (permalink / raw)
  To: drbd-dev

From: Johannes Thoma <johannes@johannesthoma.com>

drbd_thread might already be freed when complete returns,
hence we shouldn't access the drbd_thread object (thi)
after calling complete().

I am not 100% sure if this creates any further races,
alternative would be to acquire the lock before freeing
the thread object (so that spin_unlock_irqrestore() has
exited already). Please let me know what you think.

Signed-off-by: Johannes Thoma <johannes@johannesthoma.com>
---
 drbd/drbd_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drbd/drbd_main.c b/drbd/drbd_main.c
index a2b5683..dbf2e41 100644
--- a/drbd/drbd_main.c
+++ b/drbd/drbd_main.c
@@ -563,8 +563,8 @@ restart:
 	else
 		drbd_info(resource, "Terminating %s thread\n", thi->name);
 
-	complete(&thi->stop);
 	spin_unlock_irqrestore(&thi->t_lock, flags);
+	complete(&thi->stop);
 
 	if (connection)
 		kref_put(&connection->kref, drbd_destroy_connection);
-- 
2.8.0-rc4


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

* Re: [Drbd-dev] [PATCH] Fixed possible use after free in drbd_thread_setup
  2017-12-21 17:53 [Drbd-dev] [PATCH] Fixed possible use after free in drbd_thread_setup johannes
@ 2017-12-22 14:50 ` Lars Ellenberg
  0 siblings, 0 replies; 2+ messages in thread
From: Lars Ellenberg @ 2017-12-22 14:50 UTC (permalink / raw)
  To: drbd-dev

On Thu, Dec 21, 2017 at 06:53:30PM +0100, johannes@johannesthoma.com wrote:
> drbd_thread might already be freed when complete returns,

The lifetime of our "struct drbd_tread" thingies, which are embeded in
our struct drbd_resource and struct drbd_connection,
is different from the "running" time of the threads.

So no, this won't happen.

> hence we shouldn't access the drbd_thread object (thi)
> after calling complete().
> 
> I am not 100% sure if this creates any further races,

Moving that complete out of the spinlock would introduce
potential races between drbd_thread_setup, drbd_thread_start,
and _drbd_thread_stop, yes.

	Lars


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

end of thread, other threads:[~2017-12-22 14:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-21 17:53 [Drbd-dev] [PATCH] Fixed possible use after free in drbd_thread_setup johannes
2017-12-22 14:50 ` Lars Ellenberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox