Distributed Replicated Block Device (DRBD) development
 help / color / mirror / Atom feed
* [Drbd-dev] [PATCH v2] drbd: fix a race of drbd_free_peer_req
@ 2022-04-26  8:09 Rui Xu
  2022-04-28  8:59 ` Joel Colledge
  0 siblings, 1 reply; 2+ messages in thread
From: Rui Xu @ 2022-04-26  8:09 UTC (permalink / raw)
  To: philipp.reisner, drbd-dev, joel.colledge; +Cc: Rui Xu, dongsheng.yang

Commit e061feb8 and 9a11ebeb5 introduce a bug to race with drbd_free_peer_req()
in got_peer_ack.

drbd_free_page_chain in drbd_finish_peer_reqs and got_peer_ack may happen
concurrently, the sequence is as follows:

drbd_finish_peer_reqs                 got_peer_ack
drbd_free_page_chain                  drbd_free_peer_req
spin_lock()
page_chain_add
spin_unlock()                         spin_lock()
                                      page_chain_add
                                      spin_unlock()

We can see that page_chain_add will be called twice which will lead
to crash.

Swap drbd_may_finish_epoch() and drbd_free_page_chain() in e_end_block()
to ensure that got_peer_ack will not be called while still processing
the request in drbd_finish_peer_reqs().

Signed-off-by: Rui Xu <rui.xu@easystack.cn>
---
 drbd/drbd_receiver.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drbd/drbd_receiver.c b/drbd/drbd_receiver.c
index f077f2b..d0f42d3 100644
--- a/drbd/drbd_receiver.c
+++ b/drbd/drbd_receiver.c
@@ -2560,9 +2560,10 @@ static int e_end_block(struct drbd_work *w, int cancel)
 	} else
 		D_ASSERT(device, drbd_interval_empty(&peer_req->i));
 
+	drbd_free_page_chain(&peer_device->connection->transport, &peer_req->page_chain, 0);
+
 	drbd_may_finish_epoch(peer_device->connection, peer_req->epoch, EV_PUT + (cancel ? EV_CLEANUP : 0));
 
-	drbd_free_page_chain(&peer_device->connection->transport, &peer_req->page_chain, 0);
 	return err;
 }
 
-- 
1.8.3.1


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

* Re: [Drbd-dev] [PATCH v2] drbd: fix a race of drbd_free_peer_req
  2022-04-26  8:09 [Drbd-dev] [PATCH v2] drbd: fix a race of drbd_free_peer_req Rui Xu
@ 2022-04-28  8:59 ` Joel Colledge
  0 siblings, 0 replies; 2+ messages in thread
From: Joel Colledge @ 2022-04-28  8:59 UTC (permalink / raw)
  To: Rui Xu; +Cc: Philipp Reisner, dongsheng.yang, drbd-dev

Applied as https://github.com/LINBIT/drbd/commit/254f91494b5fa2e30b0aa816ea573edb3babac99

Thanks!
Joel

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

end of thread, other threads:[~2022-04-28  8:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-26  8:09 [Drbd-dev] [PATCH v2] drbd: fix a race of drbd_free_peer_req Rui Xu
2022-04-28  8:59 ` Joel Colledge

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