diff options
| author | David Lönnhager <david.l@mullvad.net> | 2020-10-20 17:35:57 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2021-07-02 09:54:19 +0200 |
| commit | 3ddb42d4c8e27e071789210a168137f5281b0899 (patch) | |
| tree | 592b58492cbc519031eb7f116d7247d3f74cd380 | |
| parent | 3d9d90c586bb6e19fe4401ca32c964d65664211f (diff) | |
| download | mullvadvpn-3ddb42d4c8e27e071789210a168137f5281b0899.tar.xz mullvadvpn-3ddb42d4c8e27e071789210a168137f5281b0899.zip | |
Add timeout for split tunnel driver I/O
| -rw-r--r-- | talpid-core/src/split_tunnel/windows/driver.rs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/talpid-core/src/split_tunnel/windows/driver.rs b/talpid-core/src/split_tunnel/windows/driver.rs index a539c84e3c..92eee527da 100644 --- a/talpid-core/src/split_tunnel/windows/driver.rs +++ b/talpid-core/src/split_tunnel/windows/driver.rs @@ -16,6 +16,7 @@ use std::{ io::{AsRawHandle, RawHandle}, }, ptr, + time::Duration, }; use winapi::{ shared::{ @@ -26,7 +27,7 @@ use winapi::{ }, um::{ handleapi::CloseHandle, - ioapiset::{DeviceIoControl, GetOverlappedResult}, + ioapiset::{DeviceIoControl, GetOverlappedResultEx}, minwinbase::OVERLAPPED, synchapi::CreateEventW, tlhelp32::TH32CS_SNAPPROCESS, @@ -38,6 +39,8 @@ use winapi::{ const DRIVER_SYMBOLIC_NAME: &str = "\\\\.\\MULLVADSPLITTUNNEL"; const ST_DEVICE_TYPE: u32 = 0x8000; +const DRIVER_IO_TIMEOUT: Duration = Duration::from_secs(3); + const fn ctl_code(device_type: u32, function: u32, method: u32, access: u32) -> u32 { device_type << 16 | access << 14 | function << 2 | method } @@ -702,8 +705,15 @@ pub fn device_io_control_buffer( return Err(last_error); } - let result = - unsafe { GetOverlappedResult(device as *mut _, overlapped, &mut returned_bytes, TRUE) }; + let result = unsafe { + GetOverlappedResultEx( + device as *mut _, + overlapped, + &mut returned_bytes, + DRIVER_IO_TIMEOUT.as_millis() as u32, + FALSE, + ) + }; if result == 0 { return Err(io::Error::last_os_error()); |
