Skip to content

Commit 2e38e88

Browse files
Sarah Newmanjfvogel
authored andcommitted
drbd: add missing kref_get in handle_write_conflicts
[ Upstream commit 00c9c9628b49e368d140cfa61d7df9b8922ec2a8 ] 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 <[email protected]> Signed-off-by: Lars Ellenberg <[email protected]> Signed-off-by: Christoph Böhmwalder <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]> Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit 7d483ad300fc0a06f69b019dda8f74970714baf8) Signed-off-by: Jack Vogel <[email protected]>
1 parent 42712f0 commit 2e38e88

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

drivers/block/drbd/drbd_receiver.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2500,7 +2500,11 @@ static int handle_write_conflicts(struct drbd_device *device,
25002500
peer_req->w.cb = superseded ? e_send_superseded :
25012501
e_send_retry_write;
25022502
list_add_tail(&peer_req->w.list, &device->done_ee);
2503-
queue_work(connection->ack_sender, &peer_req->peer_device->send_acks_work);
2503+
/* put is in drbd_send_acks_wf() */
2504+
kref_get(&device->kref);
2505+
if (!queue_work(connection->ack_sender,
2506+
&peer_req->peer_device->send_acks_work))
2507+
kref_put(&device->kref, drbd_destroy_device);
25042508

25052509
err = -ENOENT;
25062510
goto out;

0 commit comments

Comments
 (0)