This is the Analogy I Used to Understand Buffer Overflow
A buffer is a space of physical storage memory used to store temporary data while moving from one place to another.
Buffers usually reside in RAM.
Computers often use buffers to improve performance. For example, buffers are often used during online video streaming to prevent interference. When a video is streamed, the video player simultaneously downloads and stores 20% of the video in a buffer and then streams from that buffer.
Therefore, a small reduction in connection speed or rapid service interruption does not affect the performance of the video streaming.
Since I’m a cybersecurity policy writer and not a programmer you can forget about all the technical talk that you would get from someone who eats and sleeps programming.
I am a storyteller and this is the way I understand Buffer Overflow.
Imagine you work at a daycare center as the lead teacher in a pre-school class.
In your class there are two cubbies assigned to each student. One cubby (the top cubby) is for their shoes and the other cubby (the bottom) is for the backpack and/or jacket they bring from home.
Each student, has two cubbies.
As the children arrive in the morning, you instruct them to put their shoes, and backpack and jacket into their assigned cubbies.
When Henry arrives, you greet him and his Dad, then say, “Henry, we are playing on the trampoline today so please place your shoes and your backpack and jacket in your assigned cubbies”.
Henry is one of your mischevious students so, of course, he places his shoes and backpack in his assigned cubbies…but he also removes items from his backpack and stuffs the next 4 cubbies with his toys, extra clothes, pull-ups and sippy cups. Henry’s cubby holes are numbers 1 and 2 , Sally’s are numbers 3 and 4 and Pepper’s are numbers 5 and 6.
Henry fills his 2 cubbies, then overflows his defined limit and fills Sally and Pepper’s cubbies as well.
|Cubby 1: Henry’s Shoes| Cubby 3: Henry’s item| Cubby 5: Henry’s item|
|Cubby 2: Henry’s backpack| Cubby 4: Henry’s item| Cubby 6: Henry’s item|
Because you are busy greeting parents and caring for other preschoolers you do not enforce any protections or place controls on the defined limit for using cubbies the way they have been assigned.
For this reason, Henry is able to easily exceed his storage space by overflowing into Sally and Pepper’s storage space.
Now, when Sally and Pepper arrive, they have no place to store their shoes, backpacks and jackets. Henry has invaded and occupied their assigned space.
Sally and Pepper are DEVASTATED!
But, Henry doesn’t care. He’s happily jumping on the trampoline.
Henry input 6 items where it is administratively defined that he should only put in 2, this is how a buffer overflow works at a high level. Someone is using storage that has not been assigned to them. Then, when that storage is read it’s not what you were expecting to read.
Sally and Pepper would have had storage space if you, the teacher, would have placed physical and/or technical controls in place to ensure that Henry only used the cubbies he was assigned.
Now For the More Technical Explanation:
Situations that enable (or make easier), a buffer overflow arise when developers do not perform validation checks on variables before allowing assignment of data.
Memory manipulation functions in C and C++ do not perform bounds checking and can easily overwrite the allocated bounds of the buffers they operate upon.
If the data is too large for the variable definition, an “overflow” occurs that allows a change agent to inject code in adjacent memory space granting root access or remote code execution. (OWASP)