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

Fix the dnssd code that browses on both the local and srp domains #32675

Conversation

nivi-apple
Copy link
Contributor

Fixes: #32668

- Fixes the UAF issue with the timer

- Resolves critical comments from PR project-chip#32631
Copy link

github-actions bot commented Mar 21, 2024

PR #32675: Size comparison from 1f2aff4 to d5ca8db

Full report (41 builds for cc13x4_26x4, cc32xx, cyw30739, k32w, nrfconnect, psoc6, qpg, stm32, telink)
platform target config section 1f2aff4 d5ca8db change % change
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 (read only) 774332 774332 0 0.0
(read/write) 168640 168640 0 0.0
.bss 90628 90628 0 0.0
.data 3568 3568 0 0.0
.rodata 81852 81852 0 0.0
.text 692212 692212 0 0.0
lock-ftd LP_EM_CC1354P10_6 (read only) 790748 790748 0 0.0
(read/write) 178888 178888 0 0.0
.bss 100876 100876 0 0.0
.data 3568 3568 0 0.0
.rodata 76028 76028 0 0.0
.text 714452 714452 0 0.0
lock-mtd LP_EM_CC1354P10_6 (read only) 779396 779396 0 0.0
(read/write) 173328 173328 0 0.0
.bss 95316 95316 0 0.0
.data 3568 3568 0 0.0
.rodata 102788 102788 0 0.0
.text 676340 676340 0 0.0
pump-app LP_EM_CC1354P10_6 (read only) 731668 731668 0 0.0
(read/write) 167608 167608 0 0.0
.bss 89360 89360 0 0.0
.data 3560 3560 0 0.0
.rodata 77516 77516 0 0.0
.text 653884 653884 0 0.0
pump-controller-app LP_EM_CC1354P10_6 (read only) 717180 717180 0 0.0
(read/write) 167816 167816 0 0.0
.bss 89584 89584 0 0.0
.data 3552 3552 0 0.0
.rodata 73292 73292 0 0.0
.text 643620 643620 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL (read only) 583818 583818 0 0.0
(read/write) 208000 208000 0 0.0
.bss 201228 201228 0 0.0
.data 1648 1648 0 0.0
.rodata 86666 86666 0 0.0
.text 495032 495032 0 0.0
lock CC3235SF_LAUNCHXL (read only) 629090 629090 0 0.0
(read/write) 208344 208344 0 0.0
.bss 201720 201720 0 0.0
.data 1504 1504 0 0.0
.rodata 107122 107122 0 0.0
.text 519848 519848 0 0.0
cyw30739 light cyw930739m2evb_01 (read/write) 569483 569483 0 0.0
.app_xip_area 459229 459229 0 0.0
.bss 65080 65080 0 0.0
.data 752 752 0 0.0
.rodata 0 0 0 0.0
.text 112 112 0 0.0
lock cyw930739m2evb_01 (read/write) 552139 552139 0 0.0
.app_xip_area 437125 437125 0 0.0
.bss 69832 69832 0 0.0
.data 760 760 0 0.0
.rodata 0 0 0 0.0
.text 112 112 0 0.0
ota-requestor cyw930739m2evb_01 (read/write) 572267 572267 0 0.0
.app_xip_area 463517 463517 0 0.0
.bss 63616 63616 0 0.0
.data 712 712 0 0.0
.rodata 0 0 0 0.0
.text 112 112 0 0.0
switch cyw930739m2evb_01 (read/write) 565195 565195 0 0.0
.app_xip_area 453165 453165 0 0.0
.bss 66816 66816 0 0.0
.data 792 792 0 0.0
.rodata 0 0 0 0.0
.text 112 112 0 0.0
k32w contact k32w0+release (read only) 605184 605184 0 0.0
(read/write) 79472 79472 0 0.0
.bss 67300 67300 0 0.0
.data 2188 2188 0 0.0
.text 604648 604648 0 0.0
k32w1+release (read only) 1024 1024 0 0.0
(read/write) 700044 700044 0 0.0
.bss 71148 71148 0 0.0
.data 2856 2856 0 0.0
.text 586656 586656 0 0.0
light k32w0+release (read only) 607144 607144 0 0.0
(read/write) 79332 79332 0 0.0
.bss 67156 67156 0 0.0
.data 2192 2192 0 0.0
.text 606608 606608 0 0.0
k32w1+release (read only) 1024 1024 0 0.0
(read/write) 791480 791480 0 0.0
.bss 80628 80628 0 0.0
.data 2056 2056 0 0.0
.text 669432 669432 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 (read only) 4 4 0 0.0
(read/write) 1062772 1062772 0 0.0
bss 133111 133111 0 0.0
rodata 102612 102612 0 0.0
text 779828 779828 0 0.0
nrf7002dk_nrf5340_cpuapp (read only) 4 4 0 0.0
(read/write) 1224196 1224196 0 0.0
bss 127147 127147 0 0.0
rodata 151200 151200 0 0.0
text 795824 795824 0 0.0
all-clusters-minimal-app nrf52840dk_nrf52840 (read only) 4 4 0 0.0
(read/write) 1010348 1010348 0 0.0
bss 131969 131969 0 0.0
rodata 89876 89876 0 0.0
text 741164 741164 0 0.0
psoc6 all-clusters cy8ckit_062s2_43012 (read only) 834424 834424 0 0.0
(read/write) 1797284 1797284 0 0.0
.bss 196236 196236 0 0.0
.data 2680 2680 0 0.0
.text 1589980 1589980 0 0.0
all-clusters-minimal cy8ckit_062s2_43012 (read only) 837576 837576 0 0.0
(read/write) 1719324 1719324 0 0.0
.bss 193116 193116 0 0.0
.data 2648 2648 0 0.0
.text 1515172 1515172 0 0.0
light cy8ckit_062s2_43012 (read only) 844304 844304 0 0.0
(read/write) 1638444 1638444 0 0.0
.bss 186580 186580 0 0.0
.data 2456 2456 0 0.0
.text 1441020 1441020 0 0.0
lock cy8ckit_062s2_43012 (read only) 817144 817144 0 0.0
(read/write) 1668100 1668100 0 0.0
.bss 213740 213740 0 0.0
.data 2456 2456 0 0.0
.text 1443516 1443516 0 0.0
qpg lighting-app qpg6105+debug (read/write) 1130296 1130296 0 0.0
.bss 102480 102480 0 0.0
.data 836 836 0 0.0
.text 642680 642680 0 0.0
lock-app qpg6105+debug (read/write) 1090272 1090272 0 0.0
.bss 97224 97224 0 0.0
.data 856 856 0 0.0
.text 602652 602652 0 0.0
stm32 light STM32WB5MM-DK (read/write) 601509 601509 0 0.0
.bss 128344 128344 0 0.0
.data 676 676 0 0.0
.rodata 79732 79732 0 0.0
.text 383024 383024 0 0.0
telink air-quality-sensor-app tlsr9528a_retention (read only) 51774 51774 0 0.0
(read/write) 824278 824278 0 0.0
bss 49684 49684 0 0.0
text 617038 617038 0 0.0
all-clusters-app tlsr9518adk80d (read only) 29042 29042 0 0.0
(read/write) 1093132 1093132 0 0.0
bss 101804 101804 0 0.0
text 794152 794152 0 0.0
all-clusters-minimal-app tlsr9528a (read only) 47960 47960 0 0.0
(read/write) 1050604 1050604 0 0.0
bss 110108 110108 0 0.0
text 765474 765474 0 0.0
bridge-app tlsr9518adk80d (read only) 29042 29042 0 0.0
(read/write) 911316 911316 0 0.0
bss 93140 93140 0 0.0
text 652950 652950 0 0.0
contact-sensor-app tlsr9528a_retention (read only) 51774 51774 0 0.0
(read/write) 825910 825910 0 0.0
bss 49732 49732 0 0.0
text 618728 618728 0 0.0
light-switch-app-ota-shell-factory-data tlsr9528a (read only) 51584 51584 0 0.0
(read/write) 931628 931628 0 0.0
bss 77732 77732 0 0.0
text 698878 698878 0 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d (read only) 29122 29122 0 0.0
(read/write) 1074488 1074488 0 0.0
bss 100220 100220 0 0.0
text 778334 778334 0 0.0
lock-app-dfu tlsr9528a (read only) 51584 51584 0 0.0
(read/write) 904020 904020 0 0.0
bss 69196 69196 0 0.0
text 654142 654142 0 0.0
ota-requestor-app tlsr9518adk80d (read only) 29042 29042 0 0.0
(read/write) 930288 930288 0 0.0
bss 92720 92720 0 0.0
text 672028 672028 0 0.0
pump-app tlsr9258a_retention (read only) 51774 51774 0 0.0
(read/write) 828642 828642 0 0.0
bss 49840 49840 0 0.0
text 621790 621790 0 0.0
pump-controller-app tlsr9518adk80d (read only) 31872 31872 0 0.0
(read/write) 792208 792208 0 0.0
bss 56040 56040 0 0.0
text 592468 592468 0 0.0
shell tlsr9518adk80d (read only) 29042 29042 0 0.0
(read/write) 677312 677312 0 0.0
bss 73672 73672 0 0.0
text 462570 462570 0 0.0
smoke_co_alarm-app tlsr9528a_retention (read only) 51774 51774 0 0.0
(read/write) 833446 833446 0 0.0
bss 51364 51364 0 0.0
text 625098 625098 0 0.0
temperature-measurement-app-mars-ota tlsr9518adk80d (read only) 32220 32220 0 0.0
(read/write) 852177 852177 0 0.0
bss 59516 59516 0 0.0
text 637178 637178 0 0.0
thermostat tlsr9518adk80d (read only) 31872 31872 0 0.0
(read/write) 817864 817864 0 0.0
bss 56328 56328 0 0.0
text 612152 612152 0 0.0
window-covering tlsr9258a (read only) 51584 51584 0 0.0
(read/write) 835956 835956 0 0.0
bss 68104 68104 0 0.0
text 627410 627410 0 0.0

@woody-apple woody-apple merged commit 88afa33 into project-chip:master Mar 21, 2024
51 of 67 checks passed
protocol = GetProtocol(cbAddressType);
instanceName = instanceNameToResolve;
consumerCounter = std::move(consumerCounterToUse);
hasSrpTimerStarted = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this not default-initialized in the class decl, so you don't have to do it in both constructors?

I know other members were doing things this way; that's not a reason to copy the bad pattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this after Karsten's comment. i already have it defaulting to false in the class decl.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i already have it defaulting to false in the class decl.

Then we shouldn't touch it in the constructor.

Comment on lines +558 to +559
auto interfaceId = interface.first.first;
if (TryReportingResultsForInterfaceIndex(interfaceId))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will "over-report" if we have multiple domain responses for the same interface, right? That seems pretty undesirable..... We really do want a TryReportingResultsForInterfaceIndex that takes both args, and then the single-arg version needs to make multiple calls to it for all the matching entries or something.

But before you start changing this around, we need to figure out what actually needs to be stored as part of keys here, and what needs to be stored as part of values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I couldn't add the domain here is because there are hardcoded interfaces to prioritize that do not have a domain and I have no idea what domains to use here. we need to discuss this more for me to fix this properly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point is that the "prioritize" bits indeed can only pass in the interface id (and then walk through all the matches and call the two-arg version for each one), but the bit here should pass in both pieces.

// Some interface may not have any ips, just ignore them.
if (ips.size() == 0)
{
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a continue? Returning here looks wrong to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't modify this code. :) but yes I see we need to continue to the other interfaces

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't modify this code.

You changed the context around it, though. Before, when there was only map entry the code was dealing with, return was correct. Now that it's trying to work with multiple map entries, returning is not correct.

So not modifying this code is the bug.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup. got that after i closley inspected the changes. it is a bug and i fixed it locally.

*/
void CancelSrpTimer(ResolveContext * ctx)
{
DeviceLayer::SystemLayer().CancelTimer(SrpTimerExpiredCallback, reinterpret_cast<void *>(ctx));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need the cast here? Just passing ctx as the second arg should work. Same in StartTimer....

@@ -307,25 +309,37 @@ static void OnGetAddrInfo(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t i
{
VerifyOrReturn(sdCtx->HasAddress(), sdCtx->Finalize(kDNSServiceErr_BadState));

if (domainName.compare(kOpenThreadDot) == 0)
if (domainName.compare(kSrpDot) == 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is broken. You can get multiple SRP results, then a non-SRP result with !kDNSServiceFlagsMoreComing, and this code will end up sitting and waiting for 250ms when it shouldn't. I think there's some confusion here about what kDNSServiceFlagsMoreComing means. Which is understandable, because it can be confusing. If set, all it means is "something on this same connection has more data to deliver right now". In our case, it could be either of the two resolves, any of the GetAddrInfo those kicked off, etc. In particular, it does not mean "no more data coming for the args that got passed here"; it means "no more stuff I know about right this second for anything that is using this connection".

ChipLogProgress(Discovery, "Mdns: Resolve completed on the open thread domain.");
ChipLogProgress(Discovery, "Mdns: Resolve completed on the srp domain.");

// Cancel the timer if one has been started
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why bother? The Finalize will destroy the context which cancels the timer, no?

// Schedule a timer to allow the resolve on Srp domain to complete.
CHIP_ERROR error = StartSrpTimer(kSrpTimeoutInMsec, sdCtx);

// If the timer fails to start, finalize the context and return.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment should explain why, not what. The "what" (finalize and return) is obvious from the code below. The question is: why is that the right thing to do? (It is, but the comment should explain why.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Fix outstanding comments for https://github.com/project-chip/connectedhomeip/pull/32631
5 participants