Fixed EINVAL on read4/6 from invalid namelen
This commit is contained in:
@@ -216,7 +216,7 @@ impl LinuxUDPReader {
|
||||
let mut control: ControlHeaderV6 = unsafe { mem::MaybeUninit::uninit().assume_init() };
|
||||
let mut hdr = libc::msghdr {
|
||||
msg_name: safe_cast(&mut src),
|
||||
msg_namelen: mem::size_of::<libc::sockaddr_in6> as u32,
|
||||
msg_namelen: mem::size_of::<libc::sockaddr_in6>() as u32,
|
||||
msg_iov: iovs.as_mut_ptr(),
|
||||
msg_iovlen: iovs.len(),
|
||||
msg_control: safe_cast(&mut control),
|
||||
@@ -236,7 +236,7 @@ impl LinuxUDPReader {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::NotConnected,
|
||||
format!(
|
||||
"Failed to receive (len = {}, fd = {}, errno = {})",
|
||||
"failed to receive (len = {}, fd = {}, errno = {})",
|
||||
len,
|
||||
fd,
|
||||
errno()
|
||||
@@ -270,7 +270,7 @@ impl LinuxUDPReader {
|
||||
let mut control: ControlHeaderV4 = unsafe { mem::MaybeUninit::uninit().assume_init() };
|
||||
let mut hdr = libc::msghdr {
|
||||
msg_name: safe_cast(&mut src),
|
||||
msg_namelen: mem::size_of::<libc::sockaddr_in> as u32,
|
||||
msg_namelen: mem::size_of::<libc::sockaddr_in>() as u32,
|
||||
msg_iov: iovs.as_mut_ptr(),
|
||||
msg_iovlen: iovs.len(),
|
||||
msg_control: safe_cast(&mut control),
|
||||
|
||||
@@ -7,8 +7,8 @@ use zerocopy::AsBytes;
|
||||
|
||||
use byteorder::{ByteOrder, LittleEndian};
|
||||
|
||||
use rand::prelude::{CryptoRng, RngCore};
|
||||
use rand::Rng;
|
||||
use rand_core::{CryptoRng, RngCore};
|
||||
|
||||
use clear_on_drop::clear::Clear;
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::time::Instant;
|
||||
|
||||
// DH
|
||||
use x25519_dalek::PublicKey;
|
||||
use x25519_dalek::StaticSecret;
|
||||
@@ -10,9 +12,9 @@ use hmac::Hmac;
|
||||
use aead::{Aead, NewAead, Payload};
|
||||
use chacha20poly1305::ChaCha20Poly1305;
|
||||
|
||||
use rand_core::{CryptoRng, RngCore};
|
||||
use log;
|
||||
|
||||
use log::debug;
|
||||
use rand::prelude::{CryptoRng, RngCore};
|
||||
|
||||
use generic_array::typenum::*;
|
||||
use generic_array::*;
|
||||
@@ -31,8 +33,6 @@ use super::types::*;
|
||||
|
||||
use super::super::types::{Key, KeyPair};
|
||||
|
||||
use std::time::Instant;
|
||||
|
||||
// HMAC hasher (generic construction)
|
||||
|
||||
type HMACBlake2s = Hmac<Blake2s>;
|
||||
@@ -223,7 +223,7 @@ pub(super) fn create_initiation<R: RngCore + CryptoRng, O>(
|
||||
local: u32,
|
||||
msg: &mut NoiseInitiation,
|
||||
) -> Result<(), HandshakeError> {
|
||||
debug!("create initiation");
|
||||
log::debug!("create initiation");
|
||||
clear_stack_on_return(CLEAR_PAGES, || {
|
||||
// initialize state
|
||||
|
||||
@@ -303,7 +303,7 @@ pub(super) fn consume_initiation<'a, O>(
|
||||
keyst: &KeyState,
|
||||
msg: &NoiseInitiation,
|
||||
) -> Result<(&'a Peer<O>, PublicKey, TemporaryState), HandshakeError> {
|
||||
debug!("consume initiation");
|
||||
log::debug!("consume initiation");
|
||||
clear_stack_on_return(CLEAR_PAGES, || {
|
||||
// initialize new state
|
||||
|
||||
@@ -386,7 +386,7 @@ pub(super) fn create_response<R: RngCore + CryptoRng, O>(
|
||||
state: TemporaryState, // state from "consume_initiation"
|
||||
msg: &mut NoiseResponse, // resulting response
|
||||
) -> Result<KeyPair, HandshakeError> {
|
||||
debug!("create response");
|
||||
log::debug!("create response");
|
||||
clear_stack_on_return(CLEAR_PAGES, || {
|
||||
// unpack state
|
||||
|
||||
@@ -471,7 +471,7 @@ pub(super) fn consume_response<'a, O>(
|
||||
keyst: &KeyState,
|
||||
msg: &NoiseResponse,
|
||||
) -> Result<Output<'a, O>, HandshakeError> {
|
||||
debug!("consume response");
|
||||
log::debug!("consume response");
|
||||
clear_stack_on_return(CLEAR_PAGES, || {
|
||||
// retrieve peer and copy initiation state
|
||||
let (peer, _) = device.lookup_id(msg.f_receiver.get())?;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use spin;
|
||||
use std::collections::HashMap;
|
||||
use std::net::IpAddr;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
@@ -6,6 +5,8 @@ use std::sync::{Arc, Condvar, Mutex};
|
||||
use std::thread;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use spin;
|
||||
|
||||
const PACKETS_PER_SECOND: u64 = 20;
|
||||
const PACKETS_BURSTABLE: u64 = 5;
|
||||
const PACKET_COST: u64 = 1_000_000_000 / PACKETS_PER_SECOND;
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
use super::*;
|
||||
use hex;
|
||||
use rand::rngs::OsRng;
|
||||
|
||||
use std::net::SocketAddr;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
use hex;
|
||||
|
||||
use rand::prelude::{CryptoRng, RngCore};
|
||||
use rand::rngs::OsRng;
|
||||
|
||||
use x25519_dalek::PublicKey;
|
||||
use x25519_dalek::StaticSecret;
|
||||
|
||||
Reference in New Issue
Block a user