From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 792EF352075; Tue, 26 Aug 2025 13:48:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756216108; cv=none; b=A7UqW6rmyT4yjoiRBe7pQ4PGGJhHrxYWAgAOsuqt4wdjkhdUup5atCLfu+yN7wAl78zY84X7RMUjtozP2Ag36V2rbdkAW4vqT/iiRB0cYYd1I+/o/CKDsRSNZSgXlfhtwF+I7Xa7yts7SCrxmNAgfEtPG56HjyhA2InyyV22YzU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756216108; c=relaxed/simple; bh=XKivV2bdw/e+5BQ+J47gdELirbXaM1VgWpME9T+4RCk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jADfdNUGt01X+/Mckqn4BCBqO5Jy3ZhXEWSnPn2+8KlfMY+H7vjQNuNzxUBHM5zfmlkXRNF6Z6t6S1Lh0lQVyF42jcdpe5PnwfyMNgKZxTx/or1dF701P45mVrrumz+6wn2NuirXZw1lbB5Z4KRwN7h6SOvEEx2j3b8+vVoPdng= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=HxV5Lkz2; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="HxV5Lkz2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09DE6C116D0; Tue, 26 Aug 2025 13:48:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1756216108; bh=XKivV2bdw/e+5BQ+J47gdELirbXaM1VgWpME9T+4RCk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HxV5Lkz22WNl/6RyxO3IPZwBrUF6T2oBvos4ceHjK91FrkIoEh5aIgVh8A/F8lmCi NzKM0HStm5YJL3uOEcA2l1K9ycHUSDgY/W3Dx8NX8zTfKlBVrwi8kaST9dIt9/dmVa jVrXC9I079StU/IRROtcHMlDZBZaMaSUKtYFd0+s= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sarah Newman , Lars Ellenberg , =?UTF-8?q?Christoph=20B=C3=B6hmwalder?= , Jens Axboe , Sasha Levin Subject: [PATCH 5.15 287/644] drbd: add missing kref_get in handle_write_conflicts Date: Tue, 26 Aug 2025 13:06:18 +0200 Message-ID: <20250826110953.494470354@linuxfoundation.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250826110946.507083938@linuxfoundation.org> References: <20250826110946.507083938@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sarah Newman [ 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 Signed-off-by: Lars Ellenberg Signed-off-by: Christoph Böhmwalder Link: https://lore.kernel.org/r/20250627095728.800688-1-christoph.boehmwalder@linbit.com Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- 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 0104e101b0d7..ea38dd43c6b0 100644 --- a/drivers/block/drbd/drbd_receiver.c +++ b/drivers/block/drbd/drbd_receiver.c @@ -2532,7 +2532,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; -- 2.39.5