-
Notifications
You must be signed in to change notification settings - Fork 26
Open
Description
libpcap in some cases generates "backwards jump" in cbpf, e.g. tcpdump -d ip6 protochain 17:
~ $ tcpdump -d ip6 protochain 17
Warning: assuming Ethernet
(000) ldh [12]
(001) jeq #0x86dd jt 2 jf 35
(002) ldb [20]
(003) ldx #0x28
(004) jeq #0x11 jt 32 jf 5
(005) jeq #0x3b jt 32 jf 6
(006) jeq #0x0 jt 10 jf 7
(007) jeq #0x3c jt 10 jf 8
(008) jeq #0x2b jt 10 jf 9
(009) jeq #0x2c jt 10 jf 19
(010) ldb [x + 14]
(011) st M[0]
(012) ldb [x + 15]
(013) add #1
(014) mul #8
(015) add x
(016) tax
(017) ld M[0]
(018) ja 4
(019) jeq #0x33 jt 20 jf 32
(020) txa
(021) ldb [x + 14]
(022) st M[0]
(023) txa
(024) add #1
(025) tax
(026) ldb [x + 14]
(027) add #2
(028) mul #4
(029) tax
(030) ld M[0]
(031) ja 4
(032) add #0
(033) jeq #0x11 jt 34 jf 35
(034) ret #262144
(035) ret #0
The (018) ja 4 jumps to (004), so called "backwards jump".
Currenly cbpfc has two issues handling backwards jump:
- The
posandskipare of typeuint(uint64 in 64-bit system), leading to wrong jump destination calculation: Fix jump calculation #36 - Even with the Fix jump calculation #36, cbpfc spins in the loop inside
splitBlocksforever:.Line 470 in ff978e9
for len(targets) > 0 {
The libpcap generated backwards jump in my opinion is safe and mustn't cause infinite loop, because reg X gets increased in each loop.
Metadata
Metadata
Assignees
Labels
No labels