Skip to content

Commit

Permalink
Return RST to unexpected ACK in SYN-SENT state.
Browse files Browse the repository at this point in the history
Before this commit, the socket got stuck in an unusable state.
  • Loading branch information
ryan-summers committed Aug 17, 2020
1 parent 7948edc commit bdfa442
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/socket/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,15 @@ impl<'a> TcpSocket<'a> {
self.meta.handle, self.local_endpoint, self.remote_endpoint);
return Err(Error::Dropped)
}
// Any ACK in the SYN-SENT state must have the SYN flag set.
(State::SynSent, &TcpRepr {
control: TcpControl::None, ack_number: Some(_), ..
}) => {
net_debug!("{}:{}:{}: expecting a SYN|ACK",
self.meta.handle, self.local_endpoint, self.remote_endpoint);
self.abort();
return Err(Error::Dropped)
}
// Every acknowledgement must be for transmitted but unacknowledged data.
(_, &TcpRepr { ack_number: Some(ack_number), .. }) => {
let unacknowledged = self.tx_buffer.len() + control_len;
Expand Down Expand Up @@ -2490,6 +2499,17 @@ mod test {
assert_eq!(s.state, State::SynSent);
}

#[test]
fn test_syn_sent_bad_ack() {
let mut s = socket_syn_sent();
send!(s, TcpRepr {
control: TcpControl::None,
ack_number: Some(TcpSeqNumber(1)),
..SEND_TEMPL
}, Err(Error::Dropped));
assert_eq!(s.state, State::Closed);
}

#[test]
fn test_syn_sent_close() {
let mut s = socket();
Expand Down

0 comments on commit bdfa442

Please sign in to comment.