stateless-connect: send response end packet
Currently, remote-curl acts as a proxy and blindly forwards packets between an HTTP server and fetch-pack. In the case of a stateless RPC connection where the connection is terminated before the transaction is complete, remote-curl will blindly forward the packets before waiting on more input from fetch-pack. Meanwhile, fetch-pack will read the transaction and continue reading, expecting more input to continue the transaction. This results in a deadlock between the two processes. This can be seen in the following command which does not terminate: $ git -c protocol.version=2 clone https://github.com/git/git.git --shallow-since=20151012 Cloning into 'git'... whereas the v1 version does terminate as expected: $ git -c protocol.version=1 clone https://github.com/git/git.git --shallow-since=20151012 Cloning into 'git'... fatal: the remote end hung up unexpectedly Instead of blindly forwarding packets, make remote-curl insert a response end packet after proxying the responses from the remote server when using stateless_connect(). On the RPC client side, ensure that each response ends as described. A separate control packet is chosen because we need to be able to differentiate between what the remote server sends and remote-curl's control packets. By ensuring in the remote-curl code that a server cannot send response end packets, we prevent a malicious server from being able to perform a denial of service attack in which they spoof a response end packet and cause the described deadlock to happen. Reported-by: Force Charlie <charlieio@outlook.com> Helped-by: Jeff King <peff@peff.net> Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
0181b600a6
commit
b0df0c16ea
@ -405,7 +405,9 @@ Supported if the helper has the "connect" capability.
|
||||
trying to fall back). After line feed terminating the positive
|
||||
(empty) response, the output of the service starts. Messages
|
||||
(both request and response) must consist of zero or more
|
||||
PKT-LINEs, terminating in a flush packet. The client must not
|
||||
PKT-LINEs, terminating in a flush packet. Response messages will
|
||||
then have a response end packet after the flush packet to
|
||||
indicate the end of a response. The client must not
|
||||
expect the server to store any state in between request-response
|
||||
pairs. After the connection ends, the remote helper exits.
|
||||
+
|
||||
|
@ -33,6 +33,8 @@ In protocol v2 these special packets will have the following semantics:
|
||||
|
||||
* '0000' Flush Packet (flush-pkt) - indicates the end of a message
|
||||
* '0001' Delimiter Packet (delim-pkt) - separates sections of a message
|
||||
* '0002' Message Packet (response-end-pkt) - indicates the end of a response
|
||||
for stateless connections
|
||||
|
||||
Initial Client Request
|
||||
----------------------
|
||||
|
Reference in New Issue
Block a user