mptcp: zero opts->ext_copy in mptcp_established_options_dss()
Subsystems (3)
PATCH 1/1 mptcp: zero opts->ext_copy in mptcp_established_options_dss()
syzbot reported a KMSAN uninit-value in mptcp_write_data_fin() reached via tcp_send_ack() from the subflow shutdown path:
BUG: KMSAN: uninit-value in mptcp_write_data_fin net/mptcp/options.c:542 mptcp_established_options_dss net/mptcp/options.c:590 mptcp_established_options net/mptcp/options.c:874 tcp_established_options net/ipv4/tcp_output.c:1192 __tcp_transmit_skb net/ipv4/tcp_output.c:1575 __tcp_send_ack net/ipv4/tcp_output.c:4499 tcp_send_ack net/ipv4/tcp_output.c:4505 mptcp_subflow_shutdown net/mptcp/protocol.c:3137 mptcp_check_send_data_fin net/mptcp/protocol.c:3218 __mptcp_wr_shutdown net/mptcp/protocol.c:3234 __mptcp_close net/mptcp/protocol.c:3313
Local variable opts created at:
__tcp_transmit_skb net/ipv4/tcp_output.c:1536
__tcp_transmit_skb() partially clears its on-stack tcp_out_options via "memset(&opts.cleared, ...)" which does not cover opts.mptcp, so MPTCP is responsible for initializing opts->ext_copy before use.
mptcp_established_options_dss() only writes opts->ext_copy when an MPTCP extension is attached to the skb ("opts->ext_copy = *mpext"). When tcp_send_ack() builds a fresh pure-ACK skb during subflow shutdown, the skb has no extension and that assignment is skipped, but the function still calls mptcp_write_data_fin(&opts->ext_copy) because snd_data_fin_enable is set. mptcp_write_data_fin() then reads ext->use_map to choose between writing a synthetic DATA_FIN mapping or extending an existing one, and that read hits uninitialized stack memory.
Zero opts->ext_copy at the top of mptcp_established_options_dss() so mptcp_write_data_fin() takes its synthetic-mapping branch on clean memory.
--- net/mptcp/options.c | 1 + 1 file changed, 1 insertion(+)
net/mptcp/options.c +1 -0
@@ -572,6 +572,7 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,bool ret = false;u64 ack_seq; +memset (&opts->ext_copy,0 ,sizeof (opts->ext_copy)); opts->csum_reqd =READ_ONCE (msk->csum_enabled); mpext = skb ?mptcp_get_ext (skb) :NULL ;
Signature · 1 line
2.43.0
Hi Deepanshu,
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/25295668463
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/3318919851c0
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1089047
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)
Matthieu Baerts
maintainerHi Deepanshu,
Quoted 32 lines · Deepanshu Kartikey
syzbot reported a KMSAN uninit-value in
mptcp_write_data_fin()reached viatcp_send_ack()from the subflow shutdown path:BUG: KMSAN: uninit-value in mptcp_write_data_fin net/mptcp/options.c:542 mptcp_established_options_dss net/mptcp/options.c:590 mptcp_established_options net/mptcp/options.c:874 tcp_established_options net/ipv4/tcp_output.c:1192 __tcp_transmit_skb net/ipv4/tcp_output.c:1575 __tcp_send_ack net/ipv4/tcp_output.c:4499 tcp_send_ack net/ipv4/tcp_output.c:4505 mptcp_subflow_shutdown net/mptcp/protocol.c:3137 mptcp_check_send_data_fin net/mptcp/protocol.c:3218 __mptcp_wr_shutdown net/mptcp/protocol.c:3234 __mptcp_close net/mptcp/protocol.c:3313Local variable opts created at:
__tcp_transmit_skb net/ipv4/tcp_output.c:1536
__tcp_transmit_skb()partially clears its on-stacktcp_out_optionsvia "memset(&opts.cleared, ...)" which does not cover opts.mptcp, so MPTCP is responsible for initializingopts->ext_copybefore use.
mptcp_established_options_dss()only writesopts->ext_copywhen an MPTCP extension is attached to the skb ("opts->ext_copy= *mpext"). Whentcp_send_ack()builds a fresh pure-ACK skb during subflow shutdown, the skb has no extension and that assignment is skipped, but the function still callsmptcp_write_data_fin(&opts->ext_copy)becausesnd_data_fin_enableis set.mptcp_write_data_fin()then readsext->use_mapto choose between writing a syntheticDATA_FINmapping or extending an existing one, and that read hits uninitialized stack memory.
Quoted 3 lines
Zero
opts->ext_copyat the top ofmptcp_established_options_dss()somptcp_write_data_fin()takes its synthetic-mapping branch on clean memory.
Thank you for sharing this patch!
Kuniyuki already shared the same patch on the MPTCP ML a few days ago:
https://lore.kernel.org/mptcp/[email protected]/T/#u
A v2 has been shared a few hours ago:
https://lore.kernel.org/mptcp/[email protected]/T/#u
(and apparently, a v3 will be needed)
Cheers,
Matt
Signature · 2 lines
pw-bot: Rejected Sponsored by the NGI0 Core fund.