Skip to content

Commit

Permalink
[windows_kext] Block all fragment packets
Browse files Browse the repository at this point in the history
  • Loading branch information
vlabo committed Nov 7, 2024
1 parent d1d61c8 commit 71205fa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
7 changes: 7 additions & 0 deletions windows_kext/driver/src/packet_callouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ fn ip_packet_layer(
interface_index: u32,
sub_interface_index: u32,
) {
// Block all fragment data. No easy way to keep track of the origin and they are rarely used.
if data.is_fragment_data() {
data.action_block();
crate::err!("blocked fragment packet");
return;
}

let Some(device) = crate::entry::get_device() else {
return;
};
Expand Down
4 changes: 4 additions & 0 deletions windows_kext/wdk/src/filter_engine/callout_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ impl<'a> CalloutData<'a> {
}
}

pub fn is_fragment_data(&self) -> bool {
unsafe { (*self.metadata).is_fragment_data() }
}

pub fn pend_operation(
&mut self,
packet_list: Option<TransportPacketList>,
Expand Down
14 changes: 11 additions & 3 deletions windows_kext/wdk/src/filter_engine/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use windows_sys::Win32::{
NetworkManagement::{
IpHelper::IP_ADDRESS_PREFIX,
WindowsFilteringPlatform::{
FWPS_METADATA_FIELD_COMPLETION_HANDLE, FWPS_METADATA_FIELD_PROCESS_ID,
FWPS_METADATA_FIELD_PROCESS_PATH, FWPS_METADATA_FIELD_REMOTE_SCOPE_ID,
FWPS_METADATA_FIELD_TRANSPORT_CONTROL_DATA,
FWPS_METADATA_FIELD_COMPLETION_HANDLE, FWPS_METADATA_FIELD_FRAGMENT_DATA,
FWPS_METADATA_FIELD_PROCESS_ID, FWPS_METADATA_FIELD_PROCESS_PATH,
FWPS_METADATA_FIELD_REMOTE_SCOPE_ID, FWPS_METADATA_FIELD_TRANSPORT_CONTROL_DATA,
FWPS_METADATA_FIELD_TRANSPORT_ENDPOINT_HANDLE, FWP_BYTE_BLOB, FWP_DIRECTION,
},
},
Expand Down Expand Up @@ -137,6 +137,14 @@ impl FwpsIncomingMetadataValues {
None
}

pub(crate) fn is_fragment_data(&self) -> bool {
if self.has_field(FWPS_METADATA_FIELD_FRAGMENT_DATA) {
return self.fragment_metadata.fragment_offset != 0;
}

false
}

pub(crate) unsafe fn get_control_data(&self) -> Option<NonNull<[u8]>> {
if self.has_field(FWPS_METADATA_FIELD_TRANSPORT_CONTROL_DATA) {
if self.control_data.is_null() || self.control_data_length == 0 {
Expand Down

0 comments on commit 71205fa

Please sign in to comment.