BUGS-2Lesson 2 of 311 min

Too much input: buffer overflows

A buffer overflow happens when a program copies more data into a buffer than it can hold, and the extra spills into the boxes next to it. This lesson shows what the spill can do.

Writing past the end

Figure BUGS-2.1Ten letters into eight boxes

typing Asha

Asha····
name: 8 boxes
0
is_admin
main
return slip
1/5

The same function. Its programmer copies whatever is typed into the name boxes, without checking the length. A short name, Asha, fits.

Step 1 of 5

What the spill can do

  • Change nearby data, such as a flag that says who is an administrator: an integrity failure.
  • Crash the program by damaging the return slip: an availability failure.
  • Take control, if the attacker can choose what goes into the return slip and the system has no protections.

This is why one simple rule, never trust the length of input, has prevented so much harm. Station WEBA shows the same rule for websites.

Real cases

  • The Morris worm, 1988: one of the first worms to spread across the early internet. One of the ways it spread was a buffer overflow in a common network service. It slowed or stopped thousands of computers.
  • Code Red, 2001: a worm that used a buffer overflow in Microsoft’s web server software and spread to hundreds of thousands of servers in a day.

Lab: the overflow box

Lab BUGS-L1Spill, then protect

Type a short name and run the program. Then try a name longer than 8 letters. Then switch on the protections one at a time and run it again. This is a simulation of the idea, not a real program.

Protections

memory boxes for one function

········
name: 8 boxes
0
is_admin
main
return slip

BUGS-2 counts as completed once you step through the figure to its last step.