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

[ip6] filter host originated multicast packets #9735

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sunytt
Copy link
Contributor

@sunytt sunytt commented Dec 20, 2023

This PR adds the possibility to filter multicast packets sent from host directly to its thread TUN interface with following rules:

  • packets to link-local and realm-local scope multicast addresses are dropped
  • packets to > realm-local scope addresses are sent to Thread network only if the multicast group address is in the BBR multicast listener table

This is to avoid potential multicast flooding into the low power and low data rate Thread network by malicious application on the device.

This feature can be enabled with OPENTHREAD_CONFIG_FILTER_LOCAL_ORIGINATED_MULTICAST_PACKETS. It's disabled by default, and should be enabled on open environment, e.g. Android.

Note that when this feature is enabled, ping command from host to Thread network link-local/realm-local multicast addresses will not work, to test connectivity the ot cli ping command can be used to reach Thread multicast addresses.

Copy link

size-report bot commented Dec 20, 2023

Size Report of OpenThread

Merging #9735 into main(3f99b11).

name branch text data bss total
ot-cli-ftd main 464048 760 66244 531052
#9735 464048 760 66244 531052
+/- 0 0 0 0
ot-ncp-ftd main 434364 760 61464 496588
#9735 434364 760 61464 496588
+/- 0 0 0 0
libopenthread-ftd.a main 233552 0 40198 273750
#9735 233552 0 40198 273750
+/- 0 0 0 0
libopenthread-cli-ftd.a main 56611 0 8067 64678
#9735 56611 0 8067 64678
+/- 0 0 0 0
libopenthread-ncp-ftd.a main 31841 0 5916 37757
#9735 31841 0 5916 37757
+/- 0 0 0 0
ot-cli-mtd main 363176 760 51132 415068
#9735 363176 760 51132 415068
+/- 0 0 0 0
ot-ncp-mtd main 346076 760 46376 393212
#9735 346076 760 46376 393212
+/- 0 0 0 0
libopenthread-mtd.a main 156910 0 25110 182020
#9735 156910 0 25110 182020
+/- 0 0 0 0
libopenthread-cli-mtd.a main 39472 0 8043 47515
#9735 39472 0 8043 47515
+/- 0 0 0 0
libopenthread-ncp-mtd.a main 24721 0 5916 30637
#9735 24721 0 5916 30637
+/- 0 0 0 0
ot-cli-ftd-br main 532176 768 130916 663860
#9735 532176 768 130916 663860
+/- 0 0 0 0
libopenthread-ftd-br.a main 296451 5 104846 401302
#9735 296501 5 104846 401352
+/- +50 0 0 +50
libopenthread-cli-ftd-br.a main 70131 0 8091 78222
#9735 70131 0 8091 78222
+/- 0 0 0 0
ot-rcp main 62168 564 20604 83336
#9735 62168 564 20604 83336
+/- 0 0 0 0
libopenthread-rcp.a main 9522 0 5052 14574
#9735 9522 0 5052 14574
+/- 0 0 0 0
libopenthread-radio.a main 18811 0 214 19025
#9735 18811 0 214 19025
+/- 0 0 0 0

Copy link
Member

@wgtdkp wgtdkp left a comment

Choose a reason for hiding this comment

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

LGTM. 👍

src/core/backbone_router/multicast_listeners_table.cpp Outdated Show resolved Hide resolved
src/core/net/ip6.cpp Outdated Show resolved Hide resolved
Comment on lines 1079 to 1081
VerifyOrExit((header.GetDestination().IsMulticastLargerThanRealmLocal() &&
Get<BackboneRouter::MulticastListenersTable>().HasListener(header.GetDestination())),
error = kErrorDrop);
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems dropping all multicast packets within realm local scope. Is this desired behavior? My understanding is that the filter should only apply to packets destined to multicast scope greater than realm local.

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 think when untrusted source is sending to multicast scope <= realm-local, then we should filter it so misbehaving applications can't flood the thread network. The application can still communicate with Thread network with subscribed multicast addresses, similar to the other devices on the backbone interface, their packet sent to multicast address <= realm-local scope are not forwarded to Thread network.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm inclined not to dropping such packets. If such packets are dropped, that means we cannot run ping command targeting ff02::1 on Thread interface on a Linux based BR. That's kind of confusing to me.

Copy link

codecov bot commented Dec 20, 2023

Codecov Report

Attention: 10 lines in your changes are missing coverage. Please review.

Comparison is base (12af023) 85.68% compared to head (0b17b23) 85.70%.
Report is 24 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9735      +/-   ##
==========================================
+ Coverage   85.68%   85.70%   +0.01%     
==========================================
  Files         555      556       +1     
  Lines       73829    73969     +140     
==========================================
+ Hits        63262    63395     +133     
- Misses      10567    10574       +7     
Files Coverage Δ
...core/backbone_router/multicast_listeners_table.hpp 100.00% <ø> (ø)
src/core/net/ip6.cpp 76.84% <71.42%> (-0.05%) ⬇️
...core/backbone_router/multicast_listeners_table.cpp 89.28% <0.00%> (-5.42%) ⬇️

... and 30 files with indirect coverage changes

Copy link
Member

@abtink abtink left a comment

Choose a reason for hiding this comment

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

Thanks for submitting the PR and also adding a detailed PR description. 👍

Some smaller comments/questions below:

src/core/backbone_router/multicast_listeners_table.cpp Outdated Show resolved Hide resolved
src/core/backbone_router/multicast_listeners_table.hpp Outdated Show resolved Hide resolved
src/core/backbone_router/multicast_listeners_table.hpp Outdated Show resolved Hide resolved
src/core/net/ip6.cpp Outdated Show resolved Hide resolved
src/core/net/ip6.cpp Outdated Show resolved Hide resolved
@sunytt sunytt force-pushed the filter-multicast-from-host branch 2 times, most recently from 6b3c0ec to e0f1686 Compare December 28, 2023 08:23
@@ -1068,6 +1072,26 @@ Error Ip6::SendRaw(OwnedPtr<Message> aMessagePtr)

if (header.GetDestination().IsMulticast())
{
#if OPENTHREAD_CONFIG_FILTER_LOCAL_ORIGINATED_MULTICAST_PACKETS
Copy link
Member

Choose a reason for hiding this comment

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

Should we add a new API to control the behavior at runtime? I think this is a security feature, and should be controlled by upper layer.

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'll update this PR to add API control for it.

Copy link
Contributor

@superwhd superwhd left a comment

Choose a reason for hiding this comment

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

LGTM 👍

VerifyOrExit(forwardThread, error = kErrorDrop);
}
#endif

Copy link
Member

@abtink abtink Jan 4, 2024

Choose a reason for hiding this comment

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

With this feature we can decide not to forward this message over the thread mesh (to other nodes) which sounds reasonable. But the VerifyOrExit() check here, we also disallow it to be received by the device itself (since we skip calling HandleDatagram()).

What if this device itself is subscribed to the destination of the multicast message? Do we need to receive/process this multicast? Or should we drop it here as the desired behavior? (I don't have any answer/suggestion myself, just raising it so we consider and think about this situation)

Related to this, we have otMessageSetMulticastLoopEnabled() which allows caller to inidcate whether we want to allow multicast loops.

If the goal is to only disallow forwarding over thread mesh, we can consider moving this new code block to HandleDatagram() method instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Letting otMessageSetMulticastLoopEnabled() decide if multicast loops are allowed for host originated packets sounds good to me, I'll update this PR to move the code to HandleDatagram().

@jwhui jwhui requested review from abtink and bukepo February 1, 2024 00:23
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.

None yet

6 participants