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

net/ip: fix input packet filtering criteria #14656

Merged
merged 1 commit into from Mar 20, 2019
Merged

net/ip: fix input packet filtering criteria #14656

merged 1 commit into from Mar 20, 2019

Conversation

ghost
Copy link

@ghost ghost commented Mar 19, 2019

The "is this packet for us?" filter in net_ipv4_input() has a minor
logic error which fails to discard many packets which are.. not for us.

Fixes: #14647

Signed-off-by: Charles E. Youse [email protected]

@ghost ghost requested review from nashif, andyross, jukkar and andrewboie March 19, 2019 03:49
@ghost ghost requested review from pfalcon and tbursztyka as code owners March 19, 2019 03:49
@ghost
Copy link
Author

ghost commented Mar 19, 2019

@dgloeck @jukkar I haven't tested these changes, but I believe they are correct. I'd appreciate it if you could verify.

@codecov-io
Copy link

codecov-io commented Mar 19, 2019

Codecov Report

Merging #14656 into master will increase coverage by <.01%.
The diff coverage is 50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #14656      +/-   ##
==========================================
+ Coverage   51.97%   51.98%   +<.01%     
==========================================
  Files         309      309              
  Lines       45584    45584              
  Branches    10555    10555              
==========================================
+ Hits        23694    23697       +3     
+ Misses      17082    17079       -3     
  Partials     4808     4808
Impacted Files Coverage Δ
subsys/net/ip/ipv4.c 54.19% <50%> (+2.29%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2320973...e82769c. Read the comment docs.

Copy link
Member

@jukkar jukkar left a comment

Choose a reason for hiding this comment

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

We should never get into this function if the network packet destination IPv{4|6} address is not ours. Those things are already checked in ipv4.c:net_ipv4_input() line 211 and ipv6.c:net_ipv6_input() line 462 before the connection.c:net_conn_input() is called.
Could you elaborate how did you see this issue, perhaps attach pcap file that shows what the packet looks like?

Edit: as the bug was about IPv4 broadcast address, then ignore my references for IPv6 above. Anyway, we have a check for broadcast addresses in ipv4.c line 211, could you check what it does wrong in that line?

tbursztyka
tbursztyka previously approved these changes Mar 19, 2019
@tbursztyka tbursztyka dismissed their stale review March 19, 2019 07:33

dismissed

@ghost
Copy link
Author

ghost commented Mar 19, 2019

@jukkar Yes, you're, right, I believe there's a flaw in the logic of that filter there that makes it too permissive. The && at the end of line 212 should be a ||. Basically, there are four criteria checked on the input packet.

  1. It's for a unicast or broadcast address that we care about (my_addr)
  2. It's for a multicast address we care about (addr_mcast)
  3. It's an all-subnet UDP broadcast but we're not doing DHCP
  4. It's a TCP packet that arrived at a broadcast address assigned to the incoming interface

Currently the logic says "drop the packet if it's (not #1 and not #2), and (either #3 or #4).
I think the logic should say "drop the packet if it's (not #1 and not #2), OR (either #3 or #4).

As it stands, any packet that gets through L2 that doesn't violate the case-specific restrictions outlined by #3 and #4 will get passed to the upper layers, if I'm reading this right.

The "is this packet for us?" filter in net_ipv4_input() has a minor
logic error which fails to discard many packets which are.. not for us.

Fixes: #14647

Signed-off-by: Charles E. Youse <[email protected]>
@ghost ghost changed the title net/ip: tighten criteria for generating ICMP unreachables net/ip: fix input packet filtering criteria Mar 19, 2019
@dgloeck
Copy link
Contributor

dgloeck commented Mar 19, 2019

e82769c works, no more bogus ICMP replies

@ghost ghost requested a review from jukkar March 20, 2019 03:36
Copy link
Member

@jukkar jukkar left a comment

Choose a reason for hiding this comment

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

Thanks Charles!

@jukkar jukkar added the bug The issue is a bug, or the PR is fixing a bug label Mar 20, 2019
@jukkar jukkar added this to the v1.14.0 milestone Mar 20, 2019
@galak galak merged commit 8e85d7d into zephyrproject-rtos:master Mar 20, 2019
@ghost ghost deleted the issue-14647 branch March 25, 2019 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Networking bug The issue is a bug, or the PR is fixing a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants