8000 ip: enhance ip header validation by maxime-leroy · Pull Request #177 · DPDK/grout · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

ip: enhance ip header validation #177

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

Merged
merged 1 commit into from
Mar 13, 2025

Conversation

maxime-leroy
Copy link
Contributor

The current code assumes that the hardware performs the following checks:

  • The packet length is sufficient to accommodate the minimum length of the IP header.
  • The IP version is set to 4.
  • The IP header length field is large enough to accommodate the minimum legal IP datagram length.

However, these assumptions are incorrect, at least with the tap driver. The following packets can be created using Scapy:

p_badversion = Ether(dst='f0:0d:ac:dc:00:00', src='ba:d0:ca:ca:00:00')/IP(version=5, src='172.16.0.2', dst='172.16.1.2')
p_badihl = Ether(dst='f0:0d:ac:dc:00:00', src='ba:d0:ca:ca:00:00')/IP(src='172.16.0.2', dst='172.16.1.2', ihl=3)
p_truncated = Ether(dst='f0:0d:ac:dc:00:00', src='ba:d0:ca:ca:00:00')/IP(src='172.16.0.2', dst='172.16.1.2')[:14+10]

If the correct routes are configured, grout will forward these packets instead of discarding them, in violation of RFC1812.

The DPDK driver can provide hardware information about the checksum (which is already used to validate the IP checksum) and packet type. There are two packet types for IPv4:

  • RTE_PTYPE_L3_IPV4: Ethernet type 0x0800, version 4, and IHL of 5.
  • RTE_PTYPE_L3_IPV4_EXT: Ethernet type 0x0800, version 4, IHL in the range of 6–15, with options.

When one of these flags is set, it indicates that the IHL and version of the packet are valid. Otherwise, software validation is necessary.

As for the packet length requirement to accommodate the minimum legal IP datagram length (20 bytes), there is no guarantee that the hardware will validate it. Therefore, this validation must be performed in software.

Fixes: 5f5de2c ("ip4_lookup: comply with rfc1812")

Copy link
Collaborator
@rjarry rjarry left a comment

Choose a reason for hiding this comment

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

Hi Maxime,

welcome to the project :)

I only have a couple of minor remarks. Please see below.

@maxime-leroy maxime-leroy force-pushed the ip_header_validation branch from 986f1b0 to cb4bb6c Compare March 10, 2025 20:21
@maxime-leroy maxime-leroy requested a review from rjarry March 10, 2025 20:25
@maxime-leroy maxime-leroy force-pushed the ip_header_validation branch 2 times, most recently from f6605fa to 014e671 Compare March 13, 2025 16:24
The current code assumes that the hardware performs the following checks:
- The packet length is sufficient to accommodate the minimum length of the
  IP header.
- The IP version is set to 4.
- The IP header length field is large enough to accommodate the minimum
  legal IP datagram length.

However, these assumptions are incorrect, at least with the tap driver. The
following packets can be created using scapy:

> p_badversion = Ether(dst='f0:0d:ac:dc:00:00', src='ba:d0:ca:ca:00:00')/IP(version=5, src='172.16.0.2', dst='172.16.1.2')
> p_badihl = Ether(dst='f0:0d:ac:dc:00:00', src='ba:d0:ca:ca:00:00')/IP(src='172.16.0.2', dst='172.16.1.2', ihl=3)
> p_truncated = Ether(dst='f0:0d:ac:dc:00:00', src='ba:d0:ca:ca:00:00')/IP(src='172.16.0.2', dst='172.16.1.2')[:14+10]

If the correct routes are configured, grout will forward these packets instead of discarding them,
in violation of RFC1812.

So software validation is required for these fields.

The next commit will use packet type to not checking check IP version and IHL.

Fixes: 5f5de2c ("ip4_lookup: comply with rfc1812")
Signed-off-by: Maxime Leroy <maxime@leroys.fr>
@maxime-leroy maxime-leroy force-pushed the ip_header_validation branch from 014e671 to 5c9d980 Compare March 13, 2025 16:36
Copy link
Collaborator
@rjarry rjarry left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍

@rjarry rjarry merged commit d739477 into DPDK:main Mar 13, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0