Skip to content

Commit

Permalink
btmon: fix segfault caused by buffer over-read
Browse files Browse the repository at this point in the history
Fix segmentation fault caused by buffer over-read in packet_ctrl_open().

Fix is to check that ident_len is not bigger than size.

This bug was found by fuzzing btmon with AFL.

Program received signal SIGSEGV, Segmentation fault.
0x0000000000419e88 in packet_hexdump (buf=0x7fffffffda7e "22", len=<optimized out>) at monitor/packet.c:3813
3813			str[((i % 16) * 3) + 1] = hexdigits[buf[i] & 0xf];
(gdb) bt
 #0  0x0000000000419e88 in packet_hexdump (buf=0x7fffffffda7e "22", len=<optimized out>) at monitor/packet.c:3813
 #1  0x000000000041eda4 in packet_ctrl_open (tv=<optimized out>, cred=<optimized out>, index=<optimized out>, data=0x7fffffffda7e, size=<optimized out>) at monitor/packet.c:10286
 #2  0x000000000041b193 in packet_monitor (tv=0x7fffffffda50, cred=<optimized out>, index=65535, opcode=<optimized out>, data=0x7fffffffda60, size=14) at monitor/packet.c:3957
 #3  0x000000000040e177 in control_reader (path=<optimized out>, pager=true) at monitor/control.c:1462
 #4  0x0000000000403b00 in main (argc=<optimized out>, argv=<optimized out>) at monitor/main.c:243
(gdb)
  • Loading branch information
mkarhumaa authored and Johan Hedberg committed Oct 18, 2018
1 parent ab14539 commit c3d4ca7
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions monitor/packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -10273,6 +10273,12 @@ void packet_ctrl_open(struct timeval *tv, struct ucred *cred, uint16_t index,
flags = get_le32(data + 3);
ident_len = get_u8(data + 7);

if (ident_len > size) {
print_packet(tv, cred, '*', index, NULL, COLOR_ERROR,
"Malformed Control Open packet", NULL, NULL);
return;
}

data += 8;
size -= 8;

Expand Down

0 comments on commit c3d4ca7

Please sign in to comment.