Wi-Fi software security bug could leave Android, Windows, Linux open to attack (Ars Technica)
Wi-Fi software security bug could leave Android, Windows, Linux open to attack (Ars Technica)
Posted Apr 26, 2015 9:09 UTC (Sun) by paulj (subscriber, #341)In reply to: Wi-Fi software security bug could leave Android, Windows, Linux open to attack (Ars Technica) by wahern
Parent article: Wi-Fi software security bug could leave Android, Windows, Linux open to attack (Ars Technica)
I'm saying it's inexcusable not to use a bounds-checking abstraction layer. E.g. a simple bound-tracking array/stream abstraction, that tracks state such as the length of valid data and the next position to read from. Trivial to write and use.
So, given:
struct foo {
int len;
void *data;
};
…
instead of something like:
int *buf = <untrusted network input>;
int len = ntohl(buf[0]);
struct foo *foo = malloc (sizeof(struct foo) + len);
foo->len = len;
memcpy (foo->data, buf[1], foo->len);
you instead do something like:
struct barray *buf = barray_new ();
<read network input into the barray>
int len = barray_read4 (buf);
struct foo *foo = malloc (sizeof(struct foo) + len);
foo->len = len;
barray_cpy (foo->data, buf, foo->len);
The former is obviously a giant security hole. The latter way at least can safely abort and turn a remote exploit into (at worst) a DoS, regardless of other problems (e.g. signed length).
This class of bug comes up again, and again, and again (e.g. Heartbleed, this article), yet it's so damn easy to mitigate it. However, it's 2015 and lots of code still isn't doing this. Even if it was originally old, once exploited, the fixes are band-aids and *still* using these generally much more unsafe practices!
It's trivial to add a checked, bounded buffer abstraction when fixing these. Admittedly it's a verbose change to have to make that will touch a good few lines, but you don't need to think much about the changes. Coccinelle could probably handle a lot of the changes!
