udhcpc[6]: check minimum packet size after reducing it to ip.tot_len
For DHCPv6, also require that all fields up until option array exist in the packet. I did not find a definitive info that DHCPv6 requires at least one option to be present, and the code appears to handle empty option array correctly. function old new delta d6_recv_raw_packet 228 230 +2 d4_recv_raw_packet 500 501 +1 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 3/0) Total: 3 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
1 parent
b67f7b7d14
commit
56e9d36bb6
2 files changed
+18
-14
No files matched your search
@@ -969,11 +969,6 @@ static NOINLINE int d6_recv_raw_packet(struct in6_addr *peer_ipv6, struct d6_pac
|
||||
return bytes; /* returns -1 */
|
||||
}
|
||||
|
||||
if (bytes < (int) (sizeof(packet.ip6) + sizeof(packet.udp))) {
|
||||
log1s("packet is too short, ignoring");
|
||||
return -2;
|
||||
}
|
||||
|
||||
if (bytes < sizeof(packet.ip6) + ntohs(packet.ip6.ip6_plen)) {
|
||||
/* packet is bigger than sizeof(packet), we did partial read */
|
||||
log1s("oversized packet, ignoring");
|
||||
@@ -983,6 +978,15 @@ static NOINLINE int d6_recv_raw_packet(struct in6_addr *peer_ipv6, struct d6_pac
|
||||
/* ignore any extra garbage bytes */
|
||||
bytes = sizeof(packet.ip6) + ntohs(packet.ip6.ip6_plen);
|
||||
|
||||
if (bytes < (int) (
|
||||
sizeof(packet.ip6) + sizeof(packet.udp)
|
||||
+ offsetof(struct d6_packet, d6_options)
|
||||
/* + 4 - does DHCPv6 require that at least one option is present? */
|
||||
)) {
|
||||
log1s("packet is too short, ignoring");
|
||||
return -2;
|
||||
}
|
||||
|
||||
/* make sure its the right packet for us, and that it passes sanity checks */
|
||||
if (packet.ip6.ip6_nxt != IPPROTO_UDP
|
||||
|| (packet.ip6.ip6_vfc >> 4) != 6
|
||||
|
||||
@@ -900,6 +900,15 @@ static NOINLINE int d4_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd)
|
||||
break;
|
||||
}
|
||||
|
||||
if (bytes < ntohs(packet.ip.tot_len)) {
|
||||
/* packet is bigger than sizeof(packet), we did partial read */
|
||||
log1s("oversized packet, ignoring");
|
||||
return -2;
|
||||
}
|
||||
|
||||
/* ignore any extra garbage bytes */
|
||||
bytes = ntohs(packet.ip.tot_len);
|
||||
|
||||
if (bytes < (int) (
|
||||
sizeof(packet.ip) + sizeof(packet.udp)
|
||||
+ offsetof(struct dhcp_packet, options)
|
||||
@@ -910,15 +919,6 @@ static NOINLINE int d4_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd)
|
||||
return -2;
|
||||
}
|
||||
|
||||
if (bytes < ntohs(packet.ip.tot_len)) {
|
||||
/* packet is bigger than sizeof(packet), we did partial read */
|
||||
log1s("oversized packet, ignoring");
|
||||
return -2;
|
||||
}
|
||||
|
||||
/* ignore any extra garbage bytes */
|
||||
bytes = ntohs(packet.ip.tot_len);
|
||||
|
||||
/* make sure its the right packet for us, and that it passes sanity checks */
|
||||
if (packet.ip.protocol != IPPROTO_UDP
|
||||
|| packet.ip.version != IPVERSION
|
||||
|
||||
Reference in new issue
Block a user