Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erlang: binary_to_atom filling up atom table space security issue

Tags:

erlang

I heard that an atom table can fill up in Erlang, leaving the system open for DDoS unless you increase the number of atoms that can be created. It looks like binary_to_existing_atom/2 is the solution to this.

Can anyone explain exactly how binary_to_atom/2 is a security implication and how binary_to_existing_atom/2 solves this problem?

like image 996
randombits Avatar asked Jul 22 '11 21:07

randombits


1 Answers

When an atom is first used it is given an internal number and put in an array in the VM. This array is allocated statically and can fill up if enough different atoms are used. binary_to_existing_atom will only convert a binary string to an atom which already exists in the array, if it does not exist the call will fail.

If you are converting input data directly to atoms without doing any sanity checks it would be possible for an external client to send <<"a">> and <<"b">> until the array is full at which point the vm will crash.

Another way to avoid this is to simply not use binary_to_atom and instead pattern match on different binaries and return the desired atom.

like image 101
Lukas Avatar answered Oct 31 '22 18:10

Lukas