Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that we send MRP acks to incoming messages as needed. #19398

Conversation

bzbarsky-apple
Copy link
Contributor

There were two ways we could fail to send an ack to an incoming reliable message:

  1. If we found no matching handler, and hence created an ephemeral exchange to
    handle the message, but the message was unencrypted. In this case our ephemeral
    exchange would return true for IsEncryptionRequired(), because it would default
    to an ApplicationExchangeDispatch, and we would never call into
    ExchangeContext::HandleMessage.

  2. If ExchangeMessageDispatch::MessagePermitted returned false for the message.
    In particular, for an ApplicationExchangeDispatch, this would happen for all the
    handshake messages except StatusReport.

The fix for issue 1 is to ensure we always call into HandleMEssage if we manage
to allocate an exchange. If there is an encryption mismatch, which only matters
when the exchange is non-ephemeral, we close the exchange first to prevent event
delivery to the delegate.

The fix for issue 2 is to move the MRP processing out of ExchangeMessageDispatch
and into ExchangeContext, and to move the MessagePermitted check so the only
thing it prevents is delivery of the message to the delegate, not any other
processing by the exchange.

Fixes #10515

Problem

See above.

Change overview

See above.

Testing

Introduced a 10-second sleep in CASE StatusReport processing, which without these changes caused acks to the resent Sigma3 or Sigma2Resume message to be dropped. Verified that with these changes those acks are sent correctly. That exercises problem 1.

In addition to the above, added StatusReport to the list of disallowed messages in ApplicationExchangeDispatch::MessagePermitted and verified that without the changes to fix problem 2 above acks failed to be sent, but with the changes in this PR acks were sent correctly.

There were two ways we could fail to send an ack to an incoming reliable message:

1) If we found no matching handler, and hence created an ephemeral exchange to
handle the message, but the message was unencrypted.  In this case our ephemeral
exchange would return true for IsEncryptionRequired(), because it would default
to an ApplicationExchangeDispatch, and we would never call into
ExchangeContext::HandleMessage.

2) If ExchangeMessageDispatch::MessagePermitted returned false for the message.
In particular, for an ApplicationExchangeDispatch, this would happen for all the
handshake messages except StatusReport.

The fix for issue 1 is to ensure we always call into HandleMEssage if we manage
to allocate an exchange.  If there is an encryption mismatch, which only matters
when the exchange is non-ephemeral, we close the exchange first to prevent event
delivery to the delegate.

The fix for issue 2 is to move the MRP processing out of ExchangeMessageDispatch
and into ExchangeContext, and to move the MessagePermitted check so the only
thing it prevents is delivery of the message to the delegate, not any other
processing by the exchange.

Fixes project-chip#10515
@bzbarsky-apple bzbarsky-apple force-pushed the fix-encryption-mismatch-acks branch from e7795a8 to fa18784 Compare June 9, 2022 21:01
@github-actions
Copy link

github-actions bot commented Jun 9, 2022

PR #19398: Size comparison from 0adc4f3 to fa18784

Increases (27 builds for cc13x2_26x2, efr32, esp32, k32w, linux, mbed, nrfconnect, p6, telink)
platform target config section 0adc4f3 fa18784 change % change
cc13x2_26x2 all-clusters-app LP_CC2652R7 (read only) 690039 690119 80 0.0
.rodata 112391 112431 40 0.0
.text 577336 577376 40 0.0
all-clusters-minimal-app LP_CC2652R7 (read only) 640687 640759 72 0.0
.rodata 89439 89479 40 0.0
.text 550928 550960 32 0.0
lock-ftd LP_CC2652R7 (read only) 683567 683639 72 0.0
.rodata 98255 98295 40 0.0
.text 584828 584860 32 0.0
lock-mtd LP_CC2652R7 (read only) 632983 633063 80 0.0
.rodata 98143 98183 40 0.0
.text 534348 534388 40 0.0
pump-app LP_CC2652R7 (read only) 664923 664971 48 0.0
.rodata 86363 86403 40 0.0
.text 578076 578084 8 0.0
pump-controller-app LP_CC2652R7 (read only) 655491 655531 40 0.0
.rodata 84251 84291 40 0.0
shell LP_CC2652R7 (read only) 682326 682398 72 0.0
.rodata 108990 109030 40 0.0
.text 573024 573056 32 0.0
efr32 lighting-app BRD4161A (read only) 915032 915136 104 0.0
.text 915024 915128 104 0.0
BRD4161A+rpc (read only) 949236 949356 120 0.0
.text 949228 949348 120 0.0
BRD4161A+rs911x (read only) 790228 790332 104 0.0
.text 790220 790324 104 0.0
lock-app BRD4161A+wf200 (read only) 959324 959412 88 0.0
.text 959316 959404 88 0.0
window-app BRD4161A (read only) 900104 900208 104 0.0
.text 900096 900200 104 0.0
esp32 all-clusters-app c3devkit (read/write) 1481906 1481946 40 0.0
.flash.rodata 212656 212696 40 0.0
m5stack (read/write) 484040 484080 40 0.0
.flash.rodata 243156 243196 40 0.0
k32w light k32w061+release (read/write) 653816 653864 48 0.0
.text 575968 576016 48 0.0
lock k32w061+release (read/write) 715012 715100 88 0.0
.text 636752 636840 88 0.0
linux chip-tool-no-interactive-ipv6only arm64 .rodata 468444 468476 32 0.0
thermostat-no-ble arm64 .rodata 160164 160196 32 0.0
mbed lock-app CY8CPROTO_062_4343W+release (read/write) 2429752 2429784 32 0.0
.text 1392396 1392428 32 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 (read/write) 1192119 1192207 88 0.0
rodata 154712 154752 40 0.0
text 817116 817160 44 0.0
all-clusters-minimal-app nrf52840dk_nrf52840 (read/write) 1139863 1139935 72 0.0
rodata 131208 131248 40 0.0
text 789192 789236 44 0.0
p6 all-clusters-app default (read/write) 2545168 2545272 104 0.0
.text 1503432 1503536 104 0.0
all-clusters-minimal-app default (read/write) 2489976 2490080 104 0.0
.text 1448240 1448344 104 0.0
light-app default (read/write) 2421360 2421464 104 0.0
.text 1379624 1379728 104 0.0
lock-app default (read/write) 2441752 2441856 104 0.0
.text 1400016 1400120 104 0.0
telink light-switch-app tlsr9518adk80d (read/write) 781664 781688 24 0.0
lighting-app tlsr9518adk80d (read/write) 801676 801700 24 0.0
Decreases (14 builds for cc13x2_26x2, cyw30739, esp32, linux, telink)
platform target config section 0adc4f3 fa18784 change % change
cc13x2_26x2 all-clusters-app LP_CC2652R7 (read/write) 161728 161648 -80 -0.0
lock-ftd LP_CC2652R7 (read/write) 159264 159192 -72 -0.0
pump-app LP_CC2652R7 (read/write) 178820 178772 -48 -0.0
pump-controller-app LP_CC2652R7 (read/write) 188356 188316 -40 -0.0
shell LP_CC2652R7 (read/write) 164936 164864 -72 -0.0
cyw30739 light cyw930739m2evb_01 (read/write) 602562 602538 -24 -0.0
.app_xip_area 461508 461484 -24 -0.0
lock cyw930739m2evb_01 (read/write) 599670 599646 -24 -0.0
.app_xip_area 458480 458456 -24 -0.0
ota-requestor-no-progress-logging cyw930739m2evb_01 (read/write) 599446 599438 -8 -0.0
.app_xip_area 459372 459364 -8 -0.0
esp32 all-clusters-app c3devkit (read only) 1007770 1007740 -30 -0.0
.flash.text 1007770 1007740 -30 -0.0
m5stack (read only) 1062555 1062527 -28 -0.0
.flash.text 1057171 1057143 -28 -0.0
linux chip-tool-no-interactive-ipv6only arm64 (read only) 9557484 9557308 -176 -0.0
.text 7513636 7513428 -208 -0.0
thermostat-no-ble arm64 (read only) 2544060 2543884 -176 -0.0
.text 2147040 2146832 -208 -0.0
telink light-switch-app tlsr9518adk80d text 552542 552528 -14 -0.0
lighting-app tlsr9518adk80d text 569264 569246 -18 -0.0
Full report (30 builds for cc13x2_26x2, cyw30739, efr32, esp32, k32w, linux, mbed, nrfconnect, p6, telink)
platform target config section 0adc4f3 fa18784 change % change
cc13x2_26x2 all-clusters-app LP_CC2652R7 (read only) 690039 690119 80 0.0
(read/write) 161728 161648 -80 -0.0
.bss 74660 74660 0 0.0
.data 3392 3392 0 0.0
.rodata 112391 112431 40 0.0
.text 577336 577376 40 0.0
all-clusters-minimal-app LP_CC2652R7 (read only) 640687 640759 72 0.0
(read/write) 158132 158132 0 0.0
.bss 73884 73884 0 0.0
.data 3332 3332 0 0.0
.rodata 89439 89479 40 0.0
.text 550928 550960 32 0.0
lock-ftd LP_CC2652R7 (read only) 683567 683639 72 0.0
(read/write) 159264 159192 -72 -0.0
.bss 72612 72612 0 0.0
.data 3256 3256 0 0.0
.rodata 98255 98295 40 0.0
.text 584828 584860 32 0.0
lock-mtd LP_CC2652R7 (read only) 632983 633063 80 0.0
(read/write) 145720 145720 0 0.0
.bss 68348 68348 0 0.0
.data 3256 3256 0 0.0
.rodata 98143 98183 40 0.0
.text 534348 534388 40 0.0
pump-app LP_CC2652R7 (read only) 664923 664971 48 0.0
(read/write) 178820 178772 -48 -0.0
.bss 72756 72756 0 0.0
.data 3292 3292 0 0.0
.rodata 86363 86403 40 0.0
.text 578076 578084 8 0.0
pump-controller-app LP_CC2652R7 (read only) 655491 655531 40 0.0
(read/write) 188356 188316 -40 -0.0
.bss 72860 72860 0 0.0
.data 3252 3252 0 0.0
.rodata 84251 84291 40 0.0
.text 570756 570756 0 0.0
shell LP_CC2652R7 (read only) 682326 682398 72 0.0
(read/write) 164936 164864 -72 -0.0
.bss 76956 76956 0 0.0
.data 3396 3396 0 0.0
.rodata 108990 109030 40 0.0
.text 573024 573056 32 0.0
cyw30739 light cyw930739m2evb_01 (read/write) 602562 602538 -24 -0.0
.app_xip_area 461508 461484 -24 -0.0
.bss 84008 84008 0 0.0
.data 732 732 0 0.0
.rodata 0 0 0 0.0
.text 112 112 0 0.0
lock cyw930739m2evb_01 (read/write) 599670 599646 -24 -0.0
.app_xip_area 458480 458456 -24 -0.0
.bss 84176 84176 0 0.0
.data 700 700 0 0.0
.rodata 0 0 0 0.0
.text 112 112 0 0.0
ota-requestor-no-progress-logging cyw930739m2evb_01 (read/write) 599446 599438 -8 -0.0
.app_xip_area 459372 459364 -8 -0.0
.bss 83140 83140 0 0.0
.data 616 616 0 0.0
.rodata 0 0 0 0.0
.text 112 112 0 0.0
efr32 lighting-app BRD4161A (read only) 915032 915136 104 0.0
(read/write) 133176 133176 0 0.0
.bss 131088 131088 0 0.0
.data 2088 2088 0 0.0
.text 915024 915128 104 0.0
BRD4161A+rpc (read only) 949236 949356 120 0.0
(read/write) 149868 149868 0 0.0
.bss 147576 147576 0 0.0
.data 2292 2292 0 0.0
.text 949228 949348 120 0.0
BRD4161A+rs911x (read only) 790228 790332 104 0.0
(read/write) 129460 129460 0 0.0
.bss 127364 127364 0 0.0
.data 2096 2096 0 0.0
.text 790220 790324 104 0.0
lock-app BRD4161A+wf200 (read only) 959324 959412 88 0.0
(read/write) 129804 129804 0 0.0
.bss 127740 127740 0 0.0
.data 2064 2064 0 0.0
.text 959316 959404 88 0.0
window-app BRD4161A (read only) 900104 900208 104 0.0
(read/write) 133264 133264 0 0.0
.bss 131176 131176 0 0.0
.data 2084 2084 0 0.0
.text 900096 900200 104 0.0
esp32 all-clusters-app c3devkit (read only) 1007770 1007740 -30 -0.0
(read/write) 1481906 1481946 40 0.0
.dram0.bss 69168 69168 0 0.0
.dram0.data 14656 14656 0 0.0
.flash.rodata 212656 212696 40 0.0
.flash.text 1007770 1007740 -30 -0.0
.iram0.text 62902 62902 0 0.0
m5stack (read only) 1062555 1062527 -28 -0.0
(read/write) 484040 484080 40 0.0
.dram0.bss 74688 74688 0 0.0
.dram0.data 34200 34200 0 0.0
.flash.rodata 243156 243196 40 0.0
.flash.text 1057171 1057143 -28 -0.0
.iram0.text 123267 123267 0 0.0
k32w light k32w061+release (read/write) 653816 653864 48 0.0
.bss 70044 70044 0 0.0
.data 2004 2004 0 0.0
.text 575968 576016 48 0.0
lock k32w061+release (read/write) 715012 715100 88 0.0
.bss 70484 70484 0 0.0
.data 1976 1976 0 0.0
.text 636752 636840 88 0.0
linux chip-tool-no-interactive-ipv6only arm64 (read only) 9557484 9557308 -176 -0.0
(read/write) 689553 689553 0 0.0
.bss 43681 43681 0 0.0
.data 1152 1152 0 0.0
.data.rel.ro 625888 625888 0 0.0
.dynamic 528 528 0 0.0
.got 15032 15032 0 0.0
.init 24 24 0 0.0
.init_array 192 192 0 0.0
.rodata 468444 468476 32 0.0
.text 7513636 7513428 -208 -0.0
thermostat-no-ble arm64 (read only) 2544060 2543884 -176 -0.0
(read/write) 183057 183057 0 0.0
.bss 91409 91409 0 0.0
.data 1512 1512 0 0.0
.data.rel.ro 82120 82120 0 0.0
.dynamic 528 528 0 0.0
.got 4992 4992 0 0.0
.init 24 24 0 0.0
.init_array 400 400 0 0.0
.rodata 160164 160196 32 0.0
.text 2147040 2146832 -208 -0.0
mbed lock-app CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 2429752 2429784 32 0.0
.bss 202692 202692 0 0.0
.data 5872 5872 0 0.0
.text 1392396 1392428 32 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 (read/write) 1192119 1192207 88 0.0
bss 141362 141362 0 0.0
rodata 154712 154752 40 0.0
text 817116 817160 44 0.0
all-clusters-minimal-app nrf52840dk_nrf52840 (read/write) 1139863 1139935 72 0.0
bss 140579 140579 0 0.0
rodata 131208 131248 40 0.0
text 789192 789236 44 0.0
p6 all-clusters-app default (read/write) 2545168 2545272 104 0.0
.bss 137120 137120 0 0.0
.data 2808 2808 0 0.0
.text 1503432 1503536 104 0.0
all-clusters-minimal-app default (read/write) 2489976 2490080 104 0.0
.bss 136328 136328 0 0.0
.data 2752 2752 0 0.0
.text 1448240 1448344 104 0.0
light-app default (read/write) 2421360 2421464 104 0.0
.bss 129432 129432 0 0.0
.data 2600 2600 0 0.0
.text 1379624 1379728 104 0.0
lock-app default (read/write) 2441752 2441856 104 0.0
.bss 129256 129256 0 0.0
.data 2576 2576 0 0.0
.text 1400016 1400120 104 0.0
telink light-switch-app tlsr9518adk80d (read/write) 781664 781688 24 0.0
bss 70636 70636 0 0.0
noinit 40416 40416 0 0.0
text 552542 552528 -14 -0.0
lighting-app tlsr9518adk80d (read/write) 801676 801700 24 0.0
bss 70888 70888 0 0.0
noinit 40416 40416 0 0.0
text 569264 569246 -18 -0.0

@bzbarsky-apple bzbarsky-apple merged commit 10a5389 into project-chip:master Jun 10, 2022
@bzbarsky-apple bzbarsky-apple deleted the fix-encryption-mismatch-acks branch June 10, 2022 06:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Acks to unencrypted messages broken after exchange closure
3 participants