ArticleslgStudy

computer science

SYN cookies

SYN cookies is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand SYN cookies rather than just read about it. In short: SYN cookie is a technique used to resist SYN flood attacks. The technique's primary inventor Daniel J.

Key takeaways

  • SYN cookies belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect SYN cookies to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of SYN cookies from memory before moving on to harder problems.

Reference excerpt

SYN cookie is a technique used to resist SYN flood attacks. The technique's primary inventor Daniel J. Bernstein defines SYN cookies as "particular choices of initial TCP sequence numbers by TCP servers." In particular, the use of SYN cookies allows a server to avoid dropping connections when the SYN queue fills up. Instead of storing additional connections, a SYN queue entry is encoded into the sequence number sent in the SYN+ACK response. If the server then receives a subsequent ACK response from the client with the incremented sequence number, the server is able to reconstruct the SYN queue entry using information encoded in the TCP sequence number and proceed as usual with the connection.

Implementation

To initiate a TCP connection, the client sends a TCP SYN packet to the server. The server responds with a TCP SYN+ACK packet, which includes a sequence number used by TCP to reassemble the data stream. According to the TCP specification, the initial sequence number sent by an endpoint can be any value chosen by that endpoint. Since this sequence number is chosen by the sender, returned by the recipient, and has no predefined internal structure, it can be overloaded to carry additional data. The following outlines one possible implementation, though there is no public standard, so the order, length, and semantics of the fields may vary between SYN cookie implementations. SYN cookies are initial sequence numbers that are carefully constructed according to the following rules:

let t be a slowly incrementing timestamp (typically time() logically right-shifted 6 positions, which gives a resolution of 64 seconds) let m be the maximum segment size (MSS) value that the server would have stored in the SYN queue entry let s be the result of a cryptographic hash function computed over the server IP address and port number, the client IP address and port number, and the value t. The returned value s must be a 24-bit value. The initial TCP sequence number, i.e. the SYN cookie, is computed as follows:

Top 5 bits: t mod 32 Middle 3 bits: an encoded value representing m Bottom 24 bits: s

(Note: since m must be encoded using 3 bits, the server is restricted to sending up to 8 unique values for m when SYN cookies are in use.) When a client sends back a TCP ACK packet to the server in response to the server's SYN+ACK packet, the client must (according to the TCP spec) use n+1 in the packet's Acknowledgement number, where n is the initial sequence number sent by the server. The server then subtracts 1 from the acknowledgement number to reveal the SYN cookie sent to the client. The server then performs the following operations.

Checks the value t against the current time to see if the connection has expired. Recomputes s to determine whether this is, indeed, a valid SYN cookie. Decodes the value m from the 3-bit encoding in the SYN cookie, which it then can use to reconstruct the SYN queue entry. From this point forward, the connection proceeds as normal.

Security considerations Simple firewalls that are configured to allow all outgoing connections but to restrict which ports an incoming connection can reach (for example, allow incoming connections to a Web server on port 80 but restrict all other ports), work by blocking only incoming SYN requests to unwanted ports. If SYN cookies are in operation, care should be taken to ensure an attacker is not able to bypass such a firewall by forging ACKs instead, trying random sequence numbers until one is accepted. SYN cookies should be switched on and off on a per-port basis, so that SYN cookies being enabled on a public port does not cause them to be recognised on a non-public port. The original Linux kernel implementation misunderstood this part of Bernstein's description and used a single global variable to switch on SYN cookies for all ports; this was pointed out by a research student and subsequently fixed in CVE-2001-0851.

History The technique was created by Daniel J. Bernstein and Eric Schenk in September 1996. The first implementation (for SunOS) was released by Jeff Weisberg a month later, and Eric Schenk released his Linux implementation in February 1997. FreeBSD implements syncookies since FreeBSD 4.5 (January 2002).

See also SYN flood IP Spoofing TCP Cookie Transactions

References

External links D. J. Bernstein's own explanation of SYN cookies RFC 4987 Appendix A Outdated syncookies implementation for Linux kernel

Worked examples

Example 1 — a first encounter with SYN cookies

Start with the simplest possible case. Write down what SYN cookies claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to SYN cookies before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about SYN cookies ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of SYN cookies

In research
SYN cookies appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses SYN cookies in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
SYN cookies is common in secondary-school and first-year university syllabi. It links to neighbouring topics Computer network security, Transmission Control Protocol, so understanding it makes those chapters shorter.
In everyday life
Look for SYN cookies outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “SYN cookies” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study SYN cookies in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what SYN cookies means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain SYN cookies out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is SYN cookies in simple terms?

SYN cookie is a technique used to resist SYN flood attacks. The technique's primary inventor Daniel J.

Why does SYN cookies matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study SYN cookies?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on SYN cookies.

Tags

  • Computer network security
  • Transmission Control Protocol

Keep exploring