* [PATCH] drbd: add missing kref_get in handle_write_conflicts
@ 2025-06-27 9:57 Christoph Böhmwalder
2025-07-08 18:00 ` Jens Axboe
0 siblings, 1 reply; 2+ messages in thread
From: Christoph Böhmwalder @ 2025-06-27 9:57 UTC (permalink / raw)
To: Jens Axboe
Cc: drbd-dev, linux-kernel, Lars Ellenberg, Philipp Reisner,
linux-block, Sarah Newman, Lars Ellenberg,
Christoph Böhmwalder
From: Sarah Newman <srn@prgmr.com>
With `two-primaries` enabled, DRBD tries to detect "concurrent" writes
and handle write conflicts, so that even if you write to the same sector
simultaneously on both nodes, they end up with the identical data once
the writes are completed.
In handling "superseeded" writes, we forgot a kref_get,
resulting in a premature drbd_destroy_device and use after free,
and further to kernel crashes with symptoms.
Relevance: No one should use DRBD as a random data generator, and apparently
all users of "two-primaries" handle concurrent writes correctly on layer up.
That is cluster file systems use some distributed lock manager,
and live migration in virtualization environments stops writes on one node
before starting writes on the other node.
Which means that other than for "test cases",
this code path is never taken in real life.
FYI, in DRBD 9, things are handled differently nowadays. We still detect
"write conflicts", but no longer try to be smart about them.
We decided to disconnect hard instead: upper layers must not submit concurrent
writes. If they do, that's their fault.
Signed-off-by: Sarah Newman <srn@prgmr.com>
Signed-off-by: Lars Ellenberg <lars@linbit.com>
Signed-off-by: Christoph Böhmwalder <christoph.boehmwalder@linbit.com>
---
drivers/block/drbd/drbd_receiver.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
index e5a2e5f7887b..975024cf03c5 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -2500,7 +2500,11 @@ static int handle_write_conflicts(struct drbd_device *device,
peer_req->w.cb = superseded ? e_send_superseded :
e_send_retry_write;
list_add_tail(&peer_req->w.list, &device->done_ee);
- queue_work(connection->ack_sender, &peer_req->peer_device->send_acks_work);
+ /* put is in drbd_send_acks_wf() */
+ kref_get(&device->kref);
+ if (!queue_work(connection->ack_sender,
+ &peer_req->peer_device->send_acks_work))
+ kref_put(&device->kref, drbd_destroy_device);
err = -ENOENT;
goto out;
base-commit: 456ef6804f232f3b2f60147046e05500147b0099
--
2.49.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] drbd: add missing kref_get in handle_write_conflicts
2025-06-27 9:57 [PATCH] drbd: add missing kref_get in handle_write_conflicts Christoph Böhmwalder
@ 2025-07-08 18:00 ` Jens Axboe
0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2025-07-08 18:00 UTC (permalink / raw)
To: Christoph Böhmwalder
Cc: drbd-dev, linux-kernel, Lars Ellenberg, Philipp Reisner,
linux-block, Sarah Newman, Lars Ellenberg
On Fri, 27 Jun 2025 11:57:28 +0200, Christoph Böhmwalder wrote:
> With `two-primaries` enabled, DRBD tries to detect "concurrent" writes
> and handle write conflicts, so that even if you write to the same sector
> simultaneously on both nodes, they end up with the identical data once
> the writes are completed.
>
> In handling "superseeded" writes, we forgot a kref_get,
> resulting in a premature drbd_destroy_device and use after free,
> and further to kernel crashes with symptoms.
>
> [...]
Applied, thanks!
[1/1] drbd: add missing kref_get in handle_write_conflicts
commit: 00c9c9628b49e368d140cfa61d7df9b8922ec2a8
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-07-08 18:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-27 9:57 [PATCH] drbd: add missing kref_get in handle_write_conflicts Christoph Böhmwalder
2025-07-08 18:00 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).