From: Rui Xu <rui.xu@easystack.cn>
To: philipp.reisner@linbit.com, drbd-dev@lists.linbit.com,
joel.colledge@linbit.com
Cc: Rui Xu <rui.xu@easystack.cn>, dongsheng.yang@easystack.cn
Subject: [Drbd-dev] [PATCH] drbd: fix a race of drbd_free_peer_req
Date: Tue, 19 Apr 2022 20:16:47 +0800 [thread overview]
Message-ID: <20220419121647.638794-1-rui.xu@easystack.cn> (raw)
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.
Revert those two commits to ensure that drbd_free_page_chain will only
called once for one peer_req.
Signed-off-by: Rui Xu <rui.xu@easystack.cn>
---
drbd/drbd_receiver.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drbd/drbd_receiver.c b/drbd/drbd_receiver.c
index f077f2b..8cac89b 100644
--- a/drbd/drbd_receiver.c
+++ b/drbd/drbd_receiver.c
@@ -653,10 +653,12 @@ static int drbd_finish_peer_reqs(struct drbd_connection *connection)
++n;
/* list_del not necessary, next/prev members not touched */
- /* The callback may free peer_req. */
err2 = peer_req->w.cb(&peer_req->w, !!err);
if (!err)
err = err2;
+
+ if (list_empty(&peer_req->recv_order)) {
+ drbd_free_peer_req(peer_req);
}
if (atomic_sub_and_test(n, &connection->done_ee_cnt))
wake_up(&connection->ee_wait);
@@ -2293,7 +2295,6 @@ static int e_end_resync_block(struct drbd_work *w, int unused)
}
dec_unacked(peer_device);
- drbd_free_peer_req(peer_req);
return err;
}
@@ -2562,7 +2563,6 @@ static int e_end_block(struct drbd_work *w, int cancel)
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
next reply other threads:[~2022-04-19 12:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-19 12:16 Rui Xu [this message]
2022-04-20 10:22 ` [Drbd-dev] [PATCH] drbd: fix a race of drbd_free_peer_req Joel Colledge
2022-04-26 8:11 ` rui.xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220419121647.638794-1-rui.xu@easystack.cn \
--to=rui.xu@easystack.cn \
--cc=dongsheng.yang@easystack.cn \
--cc=drbd-dev@lists.linbit.com \
--cc=joel.colledge@linbit.com \
--cc=philipp.reisner@linbit.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox