Skip to contentSkip to conversation

tcp: fix authentication bypass via unsupported TCP auth options

PATCH Applied Jérémy Jean 5 participants 5 messages Nov 7 – Nov 11

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 tcp: fix authentication bypass via unsupported TCP auth options

tcp_inbound_hash() parses both TCP-MD5 and TCP-AO options when at least one of the two features is enabled. With TCP_MD5SIG=y and TCP_AO=n, a packet carrying an AO option reaches the disabled tcp_inbound_ao_hash() stub. That stub returns success, so sockets configured to require MD5 authentication end up accepting unauthenticated data. A forged AO option skips the unsigned fast path, which is the only place where tcp_inbound_hash() can return SKB_DROP_REASON_TCP_MD5NOTFOUND.

The inverse configuration with TCP_MD5SIG=n and TCP_AO=y has the same problem for an MD5 option on AO sockets.

Note that TCP-AO depends on 64BIT: therefore, every 32-bit kernel with TCP_MD5SIG=y is in the vulnerable configuration.

Make the disabled stubs reject options for the unsupported authentication scheme. This matches the real helpers' behavior for sockets without keys. It also means that kernels with TCP_MD5SIG=n and TCP_AO=y now drop segments carrying an MD5 option on unkeyed sockets, as kernels configured with TCP_MD5SIG=y already do.

Fixes 0a3a809089eb ("net/tcp: Verify inbound TCP-AO signed segments")

---
Changes in v2, upon review by Eric Dumazet:
- Explain how an AO option skips the unsigned MD5 check.
- Mention that TCP_AO depends on 64BIT.
- Count rejected unsupported auth options.

v1: https://lore.kernel.org/all/[email protected]/

 include/net/tcp_ao.h | 3 ++-
 net/ipv4/tcp.c       | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
include/net/tcp_ao.h +2 -1
index 9a2333e62e994..edf4c9bc5ef5d 100644
@@ -303,7 +303,8 @@ static inline enum skb_drop_reason tcp_inbound_ao_hash(struct sock *sk,
 		const struct request_sock *req, int l3index,
 		const struct tcp_ao_hdr *aoh)
 {
-	return SKB_NOT_DROPPED_YET;
+	NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPAOKEYNOTFOUND);
+	return SKB_DROP_REASON_TCP_AOUNEXPECTED;
 }
 
 static inline struct tcp_ao_key *tcp_ao_do_lookup(const struct sock *sk,
net/ipv4/tcp.c +2 -1
index 87ef6d5cbfeba..bf8aef32846b3 100644
@@ -4962,7 +4962,8 @@ tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,
 		     const void *saddr, const void *daddr,
 		     int family, int l3index, const __u8 *hash_location)
 {
-	return SKB_NOT_DROPPED_YET;
+	NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMD5UNEXPECTED);
+	return SKB_DROP_REASON_TCP_MD5UNEXPECTED;
 }
 
 #endif
Signature · 1 line
2.47.3
#1 lore raw
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

- Whether the issue was actually triggered, or is only theoretical (e.g. found by code inspection). If it was triggered please include the symptoms, like the stack trace or error messages.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.

The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.

reviewer Reviewed-by on v2 1/1
#2 lore raw
In reply to Jérémy Jean
Quoted 21 lines · Jérémy Jean

tcp_inbound_hash() parses both TCP-MD5 and TCP-AO options when at least one of the two features is enabled. With TCP_MD5SIG=y and TCP_AO=n, a packet carrying an AO option reaches the disabled tcp_inbound_ao_hash() stub. That stub returns success, so sockets configured to require MD5 authentication end up accepting unauthenticated data. A forged AO option skips the unsigned fast path, which is the only place where tcp_inbound_hash() can return SKB_DROP_REASON_TCP_MD5NOTFOUND.

The inverse configuration with TCP_MD5SIG=n and TCP_AO=y has the same problem for an MD5 option on AO sockets.

Note that TCP-AO depends on 64BIT: therefore, every 32-bit kernel with TCP_MD5SIG=y is in the vulnerable configuration.

Make the disabled stubs reject options for the unsupported authentication scheme. This matches the real helpers' behavior for sockets without keys. It also means that kernels with TCP_MD5SIG=n and TCP_AO=y now drop segments carrying an MD5 option on unkeyed sockets, as kernels configured with TCP_MD5SIG=y already do.

Quoted 3 lines
Fixes 0a3a809089eb ("net/tcp: Verify inbound TCP-AO signed segments")
Acked-by on v2 1/1
#3 lore raw
In reply to Jérémy Jean
Quoted 22 lines · Jérémy Jean

tcp_inbound_hash() parses both TCP-MD5 and TCP-AO options when at least one of the two features is enabled. With TCP_MD5SIG=y and TCP_AO=n, a packet carrying an AO option reaches the disabled tcp_inbound_ao_hash() stub. That stub returns success, so sockets configured to require MD5 authentication end up accepting unauthenticated data. A forged AO option skips the unsigned fast path, which is the only place where tcp_inbound_hash() can return SKB_DROP_REASON_TCP_MD5NOTFOUND.

The inverse configuration with TCP_MD5SIG=n and TCP_AO=y has the same problem for an MD5 option on AO sockets.

Note that TCP-AO depends on 64BIT: therefore, every 32-bit kernel with TCP_MD5SIG=y is in the vulnerable configuration.

Make the disabled stubs reject options for the unsupported authentication scheme. This matches the real helpers' behavior for sockets without keys. It also means that kernels with TCP_MD5SIG=n and TCP_AO=y now drop segments carrying an MD5 option on unkeyed sockets, as kernels configured with TCP_MD5SIG=y already do.

Quoted 3 lines
Fixes 0a3a809089eb ("net/tcp: Verify inbound TCP-AO signed segments")

Thanks! Nice find.

I think TCP-AO patches tried to preserve accepting MD5-signed segments on !CONFIG_TCP_MD5SIG kernels and AO segments on !CONFIG_TCP_AO ones. That's why the default stub was to accept the segments.

And I prefer we don't add prematurely ifdeffery to tcp_inbound_hash() as long as no-one complains on this changed behaviour under kernels with disabled auth options.

Thanks,
Dmitry

#4 lore raw
In reply to Jérémy Jean
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 10 lines · On Sat, 7 Nov 2026 22:47:33 +0000 you wrote:

tcp_inbound_hash() parses both TCP-MD5 and TCP-AO options when at least one of the two features is enabled. With TCP_MD5SIG=y and TCP_AO=n, a packet carrying an AO option reaches the disabled tcp_inbound_ao_hash() stub. That stub returns success, so sockets configured to require MD5 authentication end up accepting unauthenticated data. A forged AO option skips the unsigned fast path, which is the only place where tcp_inbound_hash() can return SKB_DROP_REASON_TCP_MD5NOTFOUND.

[...]

Here is the summary with links:
- [net,v2] tcp: fix authentication bypass via unsupported TCP auth options

    https://git.kernel.org/netdev/net/c/7cc235fb1251

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html