tcp: do not accept ACK of bytes we never sent
Subsystems (3)
PATCH 1/1 tcp: do not accept ACK of bytes we never sent
This patch is based on a detailed report and ideas from Yepeng Pan and Christian Rossow.
ACK seq validation is currently following RFC 5961 5.2 guidelines:
The ACK value is considered acceptable only if
it is in the range of ((SND.UNA - MAX.SND.WND) <= SEG.ACK <= SND.NXT). All incoming segments whose ACK value doesn't satisfy the above condition MUST be discarded and an ACK sent back. It needs to be noted that RFC 793 on page 72 (fifth check) says: "If the ACK is a duplicate (SEG.ACK < SND.UNA), it can be ignored. If the ACK acknowledges something not yet sent (SEG.ACK > SND.NXT) then send an ACK, drop the segment, and return". The "ignored" above implies that the processing of the incoming data segment continues, which means the ACK value is treated as acceptable. This mitigation makes the ACK check more stringent since any ACK < SND.UNA wouldn't be accepted, instead only ACKs that are in the range ((SND.UNA - MAX.SND.WND) <= SEG.ACK <= SND.NXT) get through.
This can be refined for new (and possibly spoofed) flows, by not accepting ACK for bytes that were never sent.
This greatly improves TCP security at a little cost.
I added a Fixes: tag to make sure this patch will reach stable trees, even if the 'blamed' patch was adhering to the RFC.
tp->bytes_acked was added in linux-4.2
Following packetdrill test (courtesy of Yepeng Pan) shows the issue at hand:
0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3 +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0 +0 bind(3, ..., ...) = 0
+0 listen(3, 1024) = 0
// ---------------- Handshake ------------------- //
// when window scale is set to 14 the window size can be extended to // 65535 * (2^14) = 1073725440. Linux would accept an ACK packet // with ack number in (Server_ISN+1-1073725440. Server_ISN+1) // ,though this ack number acknowledges some data never // sent by the server.
+0 < S 0:0(0) win 65535 <mss 1400,nop,wscale 14>
+0 > S. 0:0(0) ack 1 <...>
+0 < . 1:1(0) ack 1 win 65535
+0 accept(3, ..., ...) = 4
// For the established connection, we send an ACK packet, // the ack packet uses ack number 1 - 1073725300 + 2^32, // where 2^32 is used to wrap around.
// Note: we used 1073725300 instead of 1073725440 to avoid possible // edge cases.
// 1 - 1073725300 + 2^32 = 3221241997
// Oops, old kernels happily accept this packet.
+0 < . 1:1001(1000) ack 3221241997 win 65535
// After the kernel fix the following will be replaced by a challenge ACK, // and prior malicious frame would be dropped.
+0 > . 1:1(0) ack 1001
--- net/ipv4/tcp_input.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/ipv4/tcp_input.c +5 -1
@@ -3871,8 +3871,12 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)* then we can probably ignore it. */ if (before (ack, prior_snd_una)) { +u32 max_window; + +/* do not accept ACK for bytes we never sent. */ + max_window =min_t (u64, tp->max_window, tp->bytes_acked);/* RFC 5961 5.2 [Blind Data Injection Attack].[Mitigation] */ -if (before (ack, prior_snd_una - tp->max_window)) { +if (before (ack, prior_snd_una - max_window)) {if (!(flag &FLAG_NO_CHALLENGE_ACK ))tcp_send_challenge_ack (sk);return -SKB_DROP_REASON_TCP_TOO_OLD_ACK ;
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
Quoted 6 lines · Eric Dumazet
This patch is based on a detailed report and ideas from Yepeng Pan and Christian Rossow.
ACK seq validation is currently following RFC 5961 5.2 guidelines:
Quoted 13 lines
The ACK value is considered acceptable only if
it is in the range of ((SND.UNA - MAX.SND.WND) <= SEG.ACK <= SND.NXT). All incoming segments whose ACK value doesn't satisfy the above condition MUST be discarded and an ACK sent back. It needs to be noted that RFC 793 on page 72 (fifth check) says: "If the ACK is a duplicate (SEG.ACK < SND.UNA), it can be ignored. If the ACK acknowledges something not yet sent (SEG.ACK > SND.NXT) then send an ACK, drop the segment, and return". The "ignored" above implies that the processing of the incoming data segment continues, which means the ACK value is treated as acceptable. This mitigation makes the ACK check more stringent since any ACK < SND.UNA wouldn't be accepted, instead only ACKs that are in the range ((SND.UNA - MAX.SND.WND) <= SEG.ACK <= SND.NXT) get through.
Thank you Eric for the fix. It appears the newer RFC
https://www.rfc-editor.org/rfc/rfc9293.html also has this issue that needs a revision?
Quoted 75 lines
This can be refined for new (and possibly spoofed) flows, by not accepting ACK for bytes that were never sent.
This greatly improves TCP security at a little cost.
I added a Fixes: tag to make sure this patch will reach stable trees, even if the 'blamed' patch was adhering to the RFC.
tp->bytes_ackedwas added in linux-4.2Following packetdrill test (courtesy of Yepeng Pan) shows the issue at hand:
0
socket(..., SOCK_STREAM, IPPROTO_TCP)= 3 +0setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4)= 0 +0bind(3, ..., ...)= 0
+0listen(3, 1024)= 0// ---------------- Handshake ------------------- //
// when window scale is set to 14 the window size can be extended to // 65535 * (2^14) = 1073725440. Linux would accept an ACK packet // with ack number in (Server_ISN+1-1073725440. Server_ISN+1) // ,though this ack number acknowledges some data never // sent by the server.
+0 < S 0:0(0) win 65535 <mss 1400,nop,wscale 14>
+0 > S. 0:0(0) ack 1 <...>
+0 < . 1:1(0) ack 1 win 65535
+0accept(3, ..., ...)= 4// For the established connection, we send an ACK packet, // the ack packet uses ack number 1 - 1073725300 + 2^32, // where 2^32 is used to wrap around.
// Note: we used 1073725300 instead of 1073725440 to avoid possible // edge cases.
// 1 - 1073725300 + 2^32 = 3221241997// Oops, old kernels happily accept this packet.
+0 < . 1:1001(1000) ack 3221241997 win 65535// After the kernel fix the following will be replaced by a challenge ACK, // and prior malicious frame would be dropped.
+0 > . 1:1(0) ack 1001Fixes 354e4aa391ed ("tcp: RFC 5961 5.2 Blind Data Injection Attack Mitigation")Signed-off-by Eric Dumazet <[email protected]>Reported-by Yepeng Pan <[email protected]>Reported-by Christian Rossow <[email protected]>--- net/ipv4/tcp_input.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)net/ipv4/tcp_input.c +5
-2@@ -3871,8 +3871,12 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)* then we can probably ignore it. */ if (before (ack, prior_snd_una)) { +u32 max_window; + +/* do not accept ACK for bytes we never sent. */ + max_window =min_t (u64, tp->max_window, tp->bytes_acked);/* RFC 5961 5.2 [Blind Data Injection Attack].[Mitigation] */ -if (before (ack, prior_snd_una - tp->max_window)) { +if (before (ack, prior_snd_una - max_window)) {if (!(flag &FLAG_NO_CHALLENGE_ACK ))tcp_send_challenge_ack (sk);return -SKB_DROP_REASON_TCP_TOO_OLD_ACK ; --2.43.0.rc2.451.g8631bc7472-goog
Quoted 3 lines · Yuchung Cheng
Thank you Eric for the fix. It appears the newer RFC
https://www.rfc-editor.org/rfc/rfc9293.html also has this issue that needs a revision?
I do not think RFC 9293 made any refinement about RFC 5961 guidelines.
Perhaps Yepeng Pan and Christian Rossow have plans to bring this issue to IETF.
Quoted 1 line
Perhaps Yepeng Pan and Christian Rossow have plans to bring this issue to IETF.
We already brought this up to the IETF TCP WG chairs a few weeks ago. It's still unclear if the TCP WG wants to work on an Internet Draft that mitigates "ghost ACKs". We'll follow up with them.
Cheers,
Christian
Quoted 82 lines · Eric Dumazet
This patch is based on a detailed report and ideas from Yepeng Pan and Christian Rossow.
ACK seq validation is currently following RFC 5961 5.2 guidelines:
The ACK value is considered acceptable only if
it is in the range of ((SND.UNA - MAX.SND.WND) <= SEG.ACK <= SND.NXT). All incoming segments whose ACK value doesn't satisfy the above condition MUST be discarded and an ACK sent back. It needs to be noted that RFC 793 on page 72 (fifth check) says: "If the ACK is a duplicate (SEG.ACK < SND.UNA), it can be ignored. If the ACK acknowledges something not yet sent (SEG.ACK > SND.NXT) then send an ACK, drop the segment, and return". The "ignored" above implies that the processing of the incoming data segment continues, which means the ACK value is treated as acceptable. This mitigation makes the ACK check more stringent since any ACK < SND.UNA wouldn't be accepted, instead only ACKs that are in the range ((SND.UNA - MAX.SND.WND) <= SEG.ACK <= SND.NXT) get through.This can be refined for new (and possibly spoofed) flows, by not accepting ACK for bytes that were never sent.
This greatly improves TCP security at a little cost.
I added a Fixes: tag to make sure this patch will reach stable trees, even if the 'blamed' patch was adhering to the RFC.
tp->bytes_ackedwas added in linux-4.2Following packetdrill test (courtesy of Yepeng Pan) shows the issue at hand:
0
socket(..., SOCK_STREAM, IPPROTO_TCP)= 3 +0setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4)= 0 +0bind(3, ..., ...)= 0
+0listen(3, 1024)= 0// ---------------- Handshake ------------------- //
// when window scale is set to 14 the window size can be extended to // 65535 * (2^14) = 1073725440. Linux would accept an ACK packet // with ack number in (Server_ISN+1-1073725440. Server_ISN+1) // ,though this ack number acknowledges some data never // sent by the server.
+0 < S 0:0(0) win 65535 <mss 1400,nop,wscale 14>
+0 > S. 0:0(0) ack 1 <...>
+0 < . 1:1(0) ack 1 win 65535
+0accept(3, ..., ...)= 4// For the established connection, we send an ACK packet, // the ack packet uses ack number 1 - 1073725300 + 2^32, // where 2^32 is used to wrap around.
// Note: we used 1073725300 instead of 1073725440 to avoid possible // edge cases.
// 1 - 1073725300 + 2^32 = 3221241997// Oops, old kernels happily accept this packet.
+0 < . 1:1001(1000) ack 3221241997 win 65535// After the kernel fix the following will be replaced by a challenge ACK, // and prior malicious frame would be dropped.
+0 > . 1:1(0) ack 1001Fixes 354e4aa391ed ("tcp: RFC 5961 5.2 Blind Data Injection Attack Mitigation")Signed-off-by Eric Dumazet <[email protected]>Reported-by Yepeng Pan <[email protected]>Reported-by Christian Rossow <[email protected]>--- net/ipv4/tcp_input.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)net/ipv4/tcp_input.c +1
-0@@ -3871,8 +3871,12 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)* then we can probably ignore it. */ if (before (ack, prior_snd_una)) { +u32 max_window;
net/ipv4/tcp_input.c static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)
Quoted 10 lines
net/ipv4/tcp_input.c +4
-2+ +/* do not accept ACK for bytes we never sent. */ + max_window =min_t (u64, tp->max_window, tp->bytes_acked);/* RFC 5961 5.2 [Blind Data Injection Attack].[Mitigation] */ -if (before (ack, prior_snd_una - tp->max_window)) { +if (before (ack, prior_snd_una - max_window)) {if (!(flag &FLAG_NO_CHALLENGE_ACK ))tcp_send_challenge_ack (sk);return -SKB_DROP_REASON_TCP_TOO_OLD_ACK ; --
Thanks, Eric!
neal
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 19 lines · On Tue, 5 Dec 2023 16:18:41 +0000 you wrote:
This patch is based on a detailed report and ideas from Yepeng Pan and Christian Rossow.
ACK seq validation is currently following RFC 5961 5.2 guidelines:
The ACK value is considered acceptable only if
it is in the range of ((SND.UNA - MAX.SND.WND) <= SEG.ACK <= SND.NXT). All incoming segments whose ACK value doesn't satisfy the above condition MUST be discarded and an ACK sent back. It needs to be noted that RFC 793 on page 72 (fifth check) says: "If the ACK is a duplicate (SEG.ACK < SND.UNA), it can be ignored. If the ACK acknowledges something not yet sent (SEG.ACK > SND.NXT) then send an ACK, drop the segment, and return". The "ignored" above implies that the processing of the incoming data segment continues, which means the ACK value is treated as acceptable. This mitigation makes the ACK check more stringent since any ACK < SND.UNA wouldn't be accepted, instead only ACKs that are in the range ((SND.UNA - MAX.SND.WND) <= SEG.ACK <= SND.NXT) get through.
Quoted 1 line
[...]
Here is the summary with links:
- [net] tcp: do not accept ACK of bytes we never sent
https://git.kernel.org/netdev/net/c/3d501dd326fb
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html