Skip to content

Commit e2b75e3

Browse files
authored
Merge pull request #1058 from jnkr-ifx/tcp-rst-fix
tcp: Don't accept RST packets on listening sockets
2 parents 242e02c + e73621d commit e2b75e3

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/socket/tcp.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,10 +1513,12 @@ impl<'a> Socket<'a> {
15131513
return false;
15141514
}
15151515

1516-
// If we're still listening for SYNs and the packet has an ACK, it cannot
1517-
// be destined to this socket, but another one may well listen on the same
1518-
// local endpoint.
1519-
if self.state == State::Listen && repr.ack_number.is_some() {
1516+
// If we're still listening for SYNs and the packet has an ACK or a RST,
1517+
// it cannot be destined to this socket, but another one may well listen
1518+
// on the same local endpoint.
1519+
if self.state == State::Listen
1520+
&& (repr.ack_number.is_some() || repr.control == TcpControl::Rst)
1521+
{
15201522
return false;
15211523
}
15221524

@@ -3284,15 +3286,13 @@ mod test {
32843286
#[test]
32853287
fn test_listen_rst() {
32863288
let mut s = socket_listen();
3287-
send!(
3288-
s,
3289-
TcpRepr {
3290-
control: TcpControl::Rst,
3291-
seq_number: REMOTE_SEQ,
3292-
ack_number: None,
3293-
..SEND_TEMPL
3294-
}
3295-
);
3289+
let tcp_repr = TcpRepr {
3290+
control: TcpControl::Rst,
3291+
seq_number: REMOTE_SEQ,
3292+
ack_number: None,
3293+
..SEND_TEMPL
3294+
};
3295+
assert!(!s.socket.accepts(&mut s.cx, &SEND_IP_TEMPL, &tcp_repr));
32963296
assert_eq!(s.state, State::Listen);
32973297
}
32983298

0 commit comments

Comments
 (0)