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

gnrc_ipv6: validates payload size #5033

Merged
merged 1 commit into from
Jun 7, 2016

Conversation

Yonezawa-T2
Copy link
Contributor

This PR adds validation of

  • Payload Size field of IPv6 header,
  • Hdr Ext Len fields of IPv6 extension headers, and
  • actual payload size >= sizeof(icmpv6_hdr_t).

This PR will protect RIOT from malicious packet trying to access outside of the buffer.

This PR depends on #4654 (merged). I will rebase as soon as #4654 is merged.

@Yonezawa-T2 Yonezawa-T2 added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Area: network Area: Networking State: waiting for other PR State: The PR requires another PR to be merged first labels Mar 11, 2016
@miri64 miri64 self-assigned this Mar 11, 2016
@miri64
Copy link
Member

miri64 commented Mar 11, 2016

I'll wait with my review for #4654 to be merged.

@miri64 miri64 added this to the Release 2016.04 milestone Mar 23, 2016
@miri64
Copy link
Member

miri64 commented Mar 26, 2016

Needs rebase.

@miri64 miri64 removed the State: waiting for other PR State: The PR requires another PR to be merged first label Mar 26, 2016
@Yonezawa-T2
Copy link
Contributor Author

Rebased.

@miri64 miri64 added the Community: Hack'n'ACK candidate This PR is a candidate for review and discussion during one of RIOT's monthly Hack'n'ACK parties label Mar 29, 2016
@miri64
Copy link
Member

miri64 commented Mar 29, 2016

Will test at today's Hack'n'ACK

@miri64
Copy link
Member

miri64 commented Mar 31, 2016

Is not working with NHC (without fragmentation) activated. Strong guess (that's why I tested it with NHC): the decompression marks the UDP header already, making pkt->size shorter than hdr->len here (since it is only the UDP payload, not the full IPv6 payload).

@Yonezawa-T2
Copy link
Contributor Author

Fixed. Your advice to promote gnrc_pkt_len_upto to a global function was right. Thank you.

@miri64
Copy link
Member

miri64 commented Apr 1, 2016

Now I have a failed assertion :/

@miri64
Copy link
Member

miri64 commented Apr 1, 2016

Could you try yourself?

USEMODULE=gnrc_sixlowpan_iphc_nhc make -C examples/gnrc_networking/

and using the udp command.

@Yonezawa-T2
Copy link
Contributor Author

I forgot to subtract IPv6 header size. Fixed.

BTW, I met an assertion failure in gnrc_ipv6_demux. I will investigate it if possible.

@miri64
Copy link
Member

miri64 commented Apr 4, 2016

Yes, I'm running into it, too. addr2line reports its at sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c:112, which is confusing, because there is no assert statement in this line.

@Yonezawa-T2
Copy link
Contributor Author

lldb shows it is the assertion below:

        if (!interested) {
            assert(current == pkt);
            /* IPv6 is not interested anymore so `- 1` */
            receiver_num--;
        }

where pkt and current is:

GNRC_NETTYPE_UDP←pkt
↓next
GNRC_NETTYPE_UDP←current
↓next
GNRC_NETTYPE_IPV6

When I wrote that assertion, I assumed that the function receives only IPv6 headers, extension headers, and unparsed payload but it was wrong.

BTW, below line is also wrong:

    pkt->type = gnrc_nettype_from_protnum(nh);

this should be current->type.

@miri64
Copy link
Member

miri64 commented Apr 5, 2016

Are you working on a fix for that or should I look into it?

@Yonezawa-T2
Copy link
Contributor Author

No. Could you look into it? Especially, I'm not sure how to broadcast the packet.

@miri64
Copy link
Member

miri64 commented Apr 9, 2016

Fixed in #5281. The receiver isn't crashing anymore with both PRs merged, but its still not received properly.

@miri64
Copy link
Member

miri64 commented Apr 19, 2016

Since this and #5281 change the behavior of GNRC significantly I would prefer to move this to the next release. I'm not sure I manage to work on #5281 until tonight.

@miri64 miri64 modified the milestones: Release 2016.07, Release 2016.04 Apr 19, 2016
@miri64
Copy link
Member

miri64 commented Apr 27, 2016

#5281 was merged, please rebase.

@Yonezawa-T2
Copy link
Contributor Author

Rebased.

@miri64 miri64 added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label May 31, 2016
@miri64
Copy link
Member

miri64 commented May 31, 2016

ACK, please squash.

@miri64 miri64 removed the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label May 31, 2016
@miri64
Copy link
Member

miri64 commented May 31, 2016

Wait, does not work, when payload size is >99 (fragmentation threshold).

@miri64
Copy link
Member

miri64 commented May 31, 2016

(I merged current master)

@Yonezawa-T2
Copy link
Contributor Author

Yonezawa-T2 commented Jun 1, 2016

Could you provide some details? tests/gnrc_ipv6_ext modified to use 100 bytes UDP payload seems to be working. (tested on validate_ipv6_size branch rebased on the master (a10151d))

@miri64
Copy link
Member

miri64 commented Jun 1, 2016

I used gnrc_networking on a board with an IEEE 802.15.4 capable radio (samr21-xpro and iotlab-m3 in this case) and used ping6 <dest> 100. On master this is working, not so on this branch (edit: with master merged in).

@Yonezawa-T2
Copy link
Contributor Author

Fixed. I also made a 6LoWPAN test with header compression and fragmentation: #5502.

@@ -885,6 +886,14 @@ static void _receive(gnrc_pktsnip_t *pkt)
if (byteorder_ntohs(hdr->len) < pkt->size) {
gnrc_pktbuf_realloc_data(pkt, byteorder_ntohs(hdr->len));
}
else if (byteorder_ntohs(hdr->len) >
(gnrc_pkt_len_upto(pkt, GNRC_NETTYPE_IPV6) - sizeof(ipv6_hdr_t))) {
DEBUG("ipv6: invalid payload length: %d, acutal: %d, dropping packet\n",
Copy link
Member

Choose a reason for hiding this comment

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

"actual"

@miri64 miri64 added the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label Jun 6, 2016
@miri64
Copy link
Member

miri64 commented Jun 6, 2016

Apart from the typo: ACK, please squash.

@Yonezawa-T2 Yonezawa-T2 force-pushed the validate_ipv6_size branch from db09c1c to 0de34c9 Compare June 7, 2016 01:03
@Yonezawa-T2
Copy link
Contributor Author

Fixed typo, squashed.

@miri64 miri64 added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Jun 7, 2016
@miri64 miri64 merged commit e9bbd54 into RIOT-OS:master Jun 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: network Area: Networking CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Community: Hack'n'ACK candidate This PR is a candidate for review and discussion during one of RIOT's monthly Hack'n'ACK parties Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants