mptcp: only set DATA_FIN when a mapping is present
Subsystems (3)
PATCH v3 1/1 mptcp: only set DATA_FIN when a mapping is present
mptcp_get_options() clears only the status group of struct mptcp_options_received; data_seq, subflow_seq and data_len are filled in by mptcp_parse_option() exclusively inside the DSS mapping block, which runs only when the DSS M (mapping present) bit is set.
A peer can send a DSS option with the DATA_FIN flag set but the mapping bit clear. The parser then records mp_opt->data_fin while leaving data_len and data_seq uninitialized. For a zero-length segment mptcp_incoming_options() evaluates
if (mp_opt.data_fin && mp_opt.data_len == 1 && mptcp_update_rcv_data_fin(msk, mp_opt.data_seq, mp_opt.dsn64))
which reads the uninitialized data_len and data_seq; KMSAN reports an uninit-value in mptcp_incoming_options(). The stale data_seq can also be fed into the receive-side DATA_FIN sequence tracking.
Record the DATA_FIN flag only when the DSS option carries a mapping, so data_fin is never set without data_seq and data_len also being present. data_fin is part of the status group that mptcp_get_options() clears up front, so on the no-map path it stays zero and the zero-length DATA_FIN branch is simply skipped. A DATA_FIN is always transmitted together with a mapping (mptcp_write_data_fin() sets use_map along with data_seq and data_len), so legitimate DATA_FIN handling is unaffected.
Move the pr_debug() that logs the parsed DSS flags below the mapping block, so it reports the final data_fin value instead of the stale one it would otherwise print before the assignment.
---
v3:
- Move the pr_debug() DSS flag log below the mapping block so it prints the final data_fin value (Gang Yan). data_fin is now assigned only inside the use_map block, so logging it earlier would report a stale value. No functional change to the fix.
v2: adopt Paolo Abeni's suggested approach - do not set mp_opt->data_fin
at all unless a mapping is present, rather than gating the consumer in mptcp_incoming_options() (v1). data_fin then defaults to the value mptcp_get_options() already clears it to (0) on the no-map path, so the uninitialized data_len/data_seq are never read.
Link to v1: https://lore.kernel.org/all/[email protected]/
Link to v2: https://lore.kernel.org/all/[email protected]/
net/mptcp/options.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
net/mptcp/options.c +6 -6
@@ -157,17 +157,11 @@ static void mptcp_parse_option(const struct sk_buff *skb, ptr++; flags = (*ptr++) &MPTCP_DSS_FLAG_MASK ; - mp_opt->data_fin = (flags &MPTCP_DSS_DATA_FIN ) !=0 ; mp_opt->dsn64 = (flags &MPTCP_DSS_DSN64 ) !=0 ; mp_opt->use_map = (flags &MPTCP_DSS_HAS_MAP ) !=0 ; mp_opt->ack64 = (flags &MPTCP_DSS_ACK64 ) !=0 ; mp_opt->use_ack = (flags &MPTCP_DSS_HAS_ACK ); -pr_debug ("data_fin=%d dsn64=%d use_map=%d ack64=%d use_ack=%d\n" , - mp_opt->data_fin, mp_opt->dsn64, - mp_opt->use_map, mp_opt->ack64, - mp_opt->use_ack); - expected_opsize =TCPOLEN_MPTCP_DSS_BASE ;if (mp_opt->use_ack) {
@@ -178,12 +172,18 @@ static void mptcp_parse_option(const struct sk_buff *skb, }if (mp_opt->use_map) { + mp_opt->data_fin = (flags &MPTCP_DSS_DATA_FIN ) !=0 ;if (mp_opt->dsn64) expected_opsize +=TCPOLEN_MPTCP_DSS_MAP64 ;else expected_opsize +=TCPOLEN_MPTCP_DSS_MAP32 ; } +pr_debug ("data_fin=%d dsn64=%d use_map=%d ack64=%d use_ack=%d\n" , + mp_opt->data_fin, mp_opt->dsn64, + mp_opt->use_map, mp_opt->ack64, + mp_opt->use_ack); +/* Always parse any csum presence combination, we will enforce * RFC 8684 Section 3.3.0 checks later in subflow_data_ready */
Signature · 1 line
2.53.0
Hi Michael,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal (except selftest_mptcp_join): Success! ✅
- KVM Validation: normal (only selftest_mptcp_join): Success! ✅
- KVM Validation: debug (except selftest_mptcp_join): Success! ✅
- KVM Validation: debug (only selftest_mptcp_join): Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/29045444726
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/4b439011e567
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1124929
If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:
$ cd [kernel source code]
$ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
--pull always mptcp/mptcp-upstream-virtme-docker:latest \
auto-normalFor more details:
https://github.com/multipath-tcp/mptcp-upstream-virtme-docker
Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)
Hi Michael,
Quoted 25 lines · Michael Bommarito
mptcp_get_options()clears only the status group of structmptcp_options_received;data_seq,subflow_seqanddata_lenare filled in bymptcp_parse_option()exclusively inside the DSS mapping block, which runs only when the DSS M (mapping present) bit is set.A peer can send a DSS option with the
DATA_FINflag set but the mapping bit clear. The parser then recordsmp_opt->data_finwhile leavingdata_lenanddata_sequninitialized. For a zero-length segmentmptcp_incoming_options()evaluatesif (mp_opt.data_fin && mp_opt.data_len == 1 && mptcp_update_rcv_data_fin(msk, mp_opt.data_seq, mp_opt.dsn64))which reads the uninitialized
data_lenanddata_seq; KMSAN reports an uninit-value inmptcp_incoming_options(). The staledata_seqcan also be fed into the receive-sideDATA_FINsequence tracking.Record the
DATA_FINflag only when the DSS option carries a mapping, sodata_finis never set withoutdata_seqanddata_lenalso being present.data_finis part of the status group thatmptcp_get_options()clears up front, so on the no-map path it stays zero and the zero-lengthDATA_FINbranch is simply skipped. ADATA_FINis always transmitted together with a mapping (mptcp_write_data_fin()setsuse_mapalong withdata_seqanddata_len), so legitimateDATA_FINhandling is unaffected.
Quoted 3 lines
Move the
pr_debug()that logs the parsed DSS flags below the mapping block, so it reports the finaldata_finvalue instead of the stale one it would otherwise print before the assignment.
Thank you for the v3, it looks good to me:
I tried to reproduce it on my side using packetdrill-mptcp [1], but I was not able to test with KMSAN: my kernel boot, but is stuck when KMSAN is enabled... By chance, if you can try this reproducer on your side, with and without your patched kernel, that would be great :)
[1] https://github.com/multipath-tcp/packetdrill/pull/203
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Quoted 7 lines · Matthieu Baerts
I tried to reproduce it on my side using packetdrill-mptcp [1], but I was not able to test with KMSAN: my kernel boot, but is stuck when KMSAN is enabled... By chance, if you can try this reproducer on your side, with and without your patched kernel, that would be great :)
Can you try with more RAM and make sure that you have these set too?
CONFIG_CRYPTO_USER_API=yCONFIG_CRYPTO_USER_API_HASH=y
I was able to get your PR #203 test to trigger after using -m 8G + AF_ALG under vng
BUG: KMSAN: uninit-value in mptcp_incoming_options+0x1da9 mptcp_incoming_options tcp_data_queue tcp_rcv_established tcp_v4_do_rcv tcp_v4_rcv ip_protocol_deliver_rcu ip_local_deliver_finish ip_local_deliver ip_rcv
Thanks,
Mike
Matthieu Baerts
maintainerQuoted 7 lines · Michael Bommarito
Quoted 6 lines · Matthieu Baerts
I tried to reproduce it on my side using packetdrill-mptcp [1], but I was not able to test with KMSAN: my kernel boot, but is stuck when KMSAN is enabled... By chance, if you can try this reproducer on your side, with and without your patched kernel, that would be great :)
Quoted 6 lines
Quoted 1 line
Can you try with more RAM and make sure that you have these set too?
CONFIG_CRYPTO_USER_API=yCONFIG_CRYPTO_USER_API_HASH=y
Thank you for the suggestion. Yes, I did use more RAM (just tried with 8G just to be sure), and with the CRYPTO_USER_API (needed for packetdrill), but the VM stalls at boot time:
Starting KernelMemorySanitizer
ATTENTION: KMSAN is a debugging tool! Do not use it on production
machines!
I didn't investigate more, but I'm using KMSAN on another similar machine with syzkaller without issues.
Quoted 2 lines
I was able to get your PR #203 test to trigger after using -m 8G +
AF_ALGunder vng
Nice, thank you for having checked that! I guess I can merge this PR then.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
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 11 lines · On Thu, 9 Jul 2026 15:19:25 -0400 you wrote:
mptcp_get_options()clears only the status group of structmptcp_options_received;data_seq,subflow_seqanddata_lenare filled in bymptcp_parse_option()exclusively inside the DSS mapping block, which runs only when the DSS M (mapping present) bit is set.A peer can send a DSS option with the
DATA_FINflag set but the mapping bit clear. The parser then recordsmp_opt->data_finwhile leavingdata_lenanddata_sequninitialized. For a zero-length segmentmptcp_incoming_options()evaluates[...]
Here is the summary with links:
- [net,v3] mptcp: only set DATA_FIN when a mapping is present
https://git.kernel.org/netdev/net/c/b2ff91b752b0
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html