From e08e6679fcaf5ce8b91db628309ed530e58a4133 Mon Sep 17 00:00:00 2001 From: Gegy Date: Mon, 26 Aug 2024 19:53:28 +0200 Subject: [PATCH] Fix: synchronise sending chat to client with updating message signature cache (#11332) In the case where multiple messages from different players are being processed in parallel, there was a potential race condition where the messages would be sent to the client in a different order than the message signature cache was updated. However, the cache relies on the fact that the client and server get the exact same updates in the same order. This race condition would cause the caches to become corrupted, and any future message received by the client would fail to validate. This also applies to the last seen state of the server, which becomes inconsistent in the same way as the message signature cache and would cause any messages sent to be rejected by the server too. --- ...sending-chat-to-client-with-updating.patch | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 patches/server/1055-Fix-synchronise-sending-chat-to-client-with-updating.patch diff --git a/patches/server/1055-Fix-synchronise-sending-chat-to-client-with-updating.patch b/patches/server/1055-Fix-synchronise-sending-chat-to-client-with-updating.patch new file mode 100644 index 0000000000..3ed1a7f75a --- /dev/null +++ b/patches/server/1055-Fix-synchronise-sending-chat-to-client-with-updating.patch @@ -0,0 +1,27 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Gegy +Date: Mon, 26 Aug 2024 19:45:07 +0200 +Subject: [PATCH] Fix: synchronise sending chat to client with updating message + signature cache + +In the case where multiple messages from different players are being processed in parallel, there was a potential race condition where the messages would be sent to the client in a different order than the message signature cache was updated. However, the cache relies on the fact that the client and server get the exact same updates in the same order. This race condition would cause the caches to become corrupted, and any future message received by the client would fail to validate. + +This also applies to the last seen state of the server, which becomes inconsistent in the same way as the message signature cache and would cause any messages sent to be rejected by the server too. + +diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java +index b13057c0792067cc6b0abdf0d64a9be2cc9389a4..1eb56c606712a84a96d1d678ce9070b3d46e5c01 100644 +--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java ++++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java +@@ -2715,8 +2715,12 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl + return; + } + // CraftBukkit end ++ // Paper start - Ensure that client receives chat packets in the same order that we add into the message signature cache ++ synchronized (this.messageSignatureCache) { + this.send(new ClientboundPlayerChatPacket(message.link().sender(), message.link().index(), message.signature(), message.signedBody().pack(this.messageSignatureCache), message.unsignedContent(), message.filterMask(), params)); + this.addPendingMessage(message); ++ } ++ // Paper end - Ensure that client receives chat packets in the same order that we add into the message signature cache + } + + public void sendDisguisedChatMessage(Component message, ChatType.Bound params) {