Browse Source

tcp: in SYN_SENT only accept SYNACK, discard everything else.

THis would let FIN packets through, breaking the logic below.

Found with cargo-fuzz.
Dario Nieuwenhuis 3 năm trước cách đây
mục cha
commit
5d31ae01f2
1 tập tin đã thay đổi với 11 bổ sung18 xóa
  1. 11 18
      src/socket/tcp.rs

+ 11 - 18
src/socket/tcp.rs

@@ -1355,24 +1355,6 @@ impl<'a> TcpSocket<'a> {
                 );
                 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);
-            }
             // SYN|ACK in the SYN-SENT state must have the exact ACK number.
             (
                 State::SynSent,
@@ -1392,6 +1374,17 @@ impl<'a> TcpSocket<'a> {
                     return Err(Error::Dropped);
                 }
             }
+            // Anything else in the SYN-SENT state is invalid.
+            (State::SynSent, _) => {
+                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.
             (
                 _,