slirp: Don't crash on packets from 0.0.0.0/8.
PATCH 1/1 slirp: Don't crash on packets from 0.0.0.0/8.
LWIP can generate packets with a source of 0.0.0.0, which triggers an assertion failure in arp_table_add(). Instead of crashing, simply return to avoid adding an invalid ARP table entry.
--- slirp/arp_table.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
slirp/arp_table.c +2 -1
@@ -38,7 +38,8 @@ void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN]) ethaddr[3], ethaddr[4], ethaddr[5]));/* Check 0.0.0.0/8 invalid source-only addresses */ -assert ((ip_addr &htonl (~(0xf <<28 ))) !=0 ); +if ((ip_addr &htonl (~(0xf <<28 ))) ==0 ) +return ;if (ip_addr ==0xffffffff || ip_addr == broadcast_addr) {/* Do not register broadcast addresses */
Signature · 1 line
1.7.10.4
Quoted 3 lines · Nickolai Zeldovich
LWIP can generate packets with a source of 0.0.0.0, which triggers an assertion failure in
arp_table_add(). Instead of crashing, simply return to avoid adding an invalid ARP table entry.
I would prefer to filter out such invalid packets at a different level. Did you analyzed which path it takes through the stack?
Quoted 11 lines
Signed-off-by Nickolai Zeldovich <[email protected]>--- slirp/arp_table.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)slirp/arp_table.c +0
-0
slirp/arp_table.c void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN]) · line 42
Quoted 6 lines
slirp/arp_table.c +2
-1@@ -38,7 +38,8 @@ void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN]) ethaddr[3], ethaddr[4], ethaddr[5]));/* Check 0.0.0.0/8 invalid source-only addresses */ -assert ((ip_addr &htonl (~(0xf <<28 ))) !=0 ); +if ((ip_addr &htonl (~(0xf <<28 ))) ==0 ) +return ;
Please follow our coding style. There is also checkpatch.pl to help you.
slirp/arp_table.c void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN])
Quoted 4 lines
slirp/arp_table.c +0
-0if (ip_addr ==0xffffffff || ip_addr == broadcast_addr) {/* Do not register broadcast addresses */
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE Corporate Competence Center Embedded Linux
Quoted 7 lines · Jan Kiszka
Quoted 3 lines · Nickolai Zeldovich
LWIP can generate packets with a source of 0.0.0.0, which triggers an assertion failure in
arp_table_add(). Instead of crashing, simply return to avoid adding an invalid ARP table entry.I would prefer to filter out such invalid packets at a different level. Did you analyzed which path it takes through the stack?
The particular packet that crashed qemu for me was a gratuitous ARP, though it looks like all three calls to arp_table_add() in arp_input() can trigger this.
Popping up one level, I'm not sure why arp_table_add() and arp_table_search() need a special case for 0.0.0.0/8 in the first place. I couldn't find any other code that assumes the ARP table cannot contain 0.0.0.0/8 entries. Would anything break if the check for 0.0.0.0/8 was removed from arp_table_add() and arp_table_search() altogether?
Nickolai.
Quoted 13 lines · Nickolai Zeldovich
Quoted 7 lines · Jan Kiszka
Quoted 3 lines · Nickolai Zeldovich
LWIP can generate packets with a source of 0.0.0.0, which triggers an assertion failure in
arp_table_add(). Instead of crashing, simply return to avoid adding an invalid ARP table entry.I would prefer to filter out such invalid packets at a different level. Did you analyzed which path it takes through the stack?
The particular packet that crashed qemu for me was a gratuitous ARP, though it looks like all three calls to
arp_table_add()inarp_input()can trigger this.
Quoted 6 lines
Popping up one level, I'm not sure why
arp_table_add()andarp_table_search()need a special case for 0.0.0.0/8 in the first place. I couldn't find any other code that assumes the ARP table cannot contain 0.0.0.0/8 entries. Would anything break if the check for 0.0.0.0/8 was removed fromarp_table_add()andarp_table_search()altogether?
0.0.0.0/8 are source-only, invalid as destination. So they have no place in the ARP table.
OK, let's follow your path and filter them in arp_table_add. Just add the missing braces and resend.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE Corporate Competence Center Embedded Linux