mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05:00
Kernel: Do some basic sanity checking on IPv4 packet headers
Ignore packets that are too small, or not as large as they claim to be.
This commit is contained in:
parent
04603237da
commit
9e2a00248e
1 changed files with 16 additions and 2 deletions
|
@ -72,8 +72,8 @@ void NetworkTask_main()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto& packet = packet_maybe_null.value();
|
auto& packet = packet_maybe_null.value();
|
||||||
if (packet.size() < (int)(sizeof(EthernetFrameHeader))) {
|
if (packet.size() < sizeof(EthernetFrameHeader)) {
|
||||||
kprintf("NetworkTask: Packet is too small to be an Ethernet packet! (%d)\n", packet.size());
|
kprintf("NetworkTask: Packet is too small to be an Ethernet packet! (%zu)\n", packet.size());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto& eth = *(const EthernetFrameHeader*)packet.data();
|
auto& eth = *(const EthernetFrameHeader*)packet.data();
|
||||||
|
@ -185,10 +185,24 @@ void handle_ipv4(const EthernetFrameHeader& eth, int frame_size)
|
||||||
constexpr int minimum_ipv4_frame_size = sizeof(EthernetFrameHeader) + sizeof(IPv4Packet);
|
constexpr int minimum_ipv4_frame_size = sizeof(EthernetFrameHeader) + sizeof(IPv4Packet);
|
||||||
if (frame_size < minimum_ipv4_frame_size) {
|
if (frame_size < minimum_ipv4_frame_size) {
|
||||||
kprintf("handle_ipv4: Frame too small (%d, need %d)\n", frame_size, minimum_ipv4_frame_size);
|
kprintf("handle_ipv4: Frame too small (%d, need %d)\n", frame_size, minimum_ipv4_frame_size);
|
||||||
|
hang();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto& packet = *static_cast<const IPv4Packet*>(eth.payload());
|
auto& packet = *static_cast<const IPv4Packet*>(eth.payload());
|
||||||
|
|
||||||
|
if (packet.length() < sizeof(IPv4Packet)) {
|
||||||
|
kprintf("handle_ipv4: IPv4 packet too short (%u, need %u)\n", packet.length(), sizeof(IPv4Packet));
|
||||||
|
hang();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t actual_ipv4_packet_length = frame_size - sizeof(EthernetFrameHeader);
|
||||||
|
if (packet.length() > actual_ipv4_packet_length) {
|
||||||
|
kprintf("handle_ipv4: IPv4 packet claims to be longer than it is (%u, actually %zu)\n", packet.length(), actual_ipv4_packet_length);
|
||||||
|
hang();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef IPV4_DEBUG
|
#ifdef IPV4_DEBUG
|
||||||
kprintf("handle_ipv4: source=%s, target=%s\n",
|
kprintf("handle_ipv4: source=%s, target=%s\n",
|
||||||
packet.source().to_string().characters(),
|
packet.source().to_string().characters(),
|
||||||
|
|
Loading…
Add table
Reference in a new issue