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

Endless loop when parsing packets #130

Open
mfrlin opened this issue Jan 31, 2021 · 0 comments
Open

Endless loop when parsing packets #130

mfrlin opened this issue Jan 31, 2021 · 0 comments

Comments

@mfrlin
Copy link

mfrlin commented Jan 31, 2021

I see issues have been open. Copying my email from the sourceforge mailing list here.

https://github.com/osrg/ryu/blob/master/ryu/lib/packet/packet.py#L76

If rest_data returned is the same size as it was when passed to cls.parse(rest_data) this will loop endlessly because parser does not consume any data.

Real world example:
In InPacket message we receive a TCP packet on port 6653 that is NOT OpenFlow or corrupted OF packet. We pass data from InPacket message to packet.Packet(msg.data). Ethernet layer gets parsed correctly, IP layer gets parsed correctly, TCP layer gets parsed correctly but because TCP is on port 6653, OpenFlow parser gets called.
But because this is not OF message or message is corrupted, there is a chance that msg_length is 0. OpenFlow parser returns UnparsableMsg and rest_data[msg_length:].
https://github.com/osrg/ryu/blob/master/ryu/lib/packet/openflow.py#L67

Because of this parser enters an endless loop since rest_data is never consumed. This in turn hangs the whole ryu process.

My suggestion is that if rest_data is not consumed the loop must be broken:

try:
    proto, cls, unused_data = cls.parser(rest_data)
    if len(unused_data) == len(rest_data):
        break
    else: 
        rest_data = unused_data
except struct.error:
    break
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

No branches or pull requests

1 participant