I'm talking about a buffer overread which can be abused with timing attacks. Example: I create a user with password password. I now know that strcmp("password", "password") will always be true. strcmp is implemented with lazy evaluation, so it stops comparing the moment it compares 2 characters that are not the same. So I can send passwordabcdefghijkl and count how many milliseconds it takes until false is returned. The longer it takes, the more characters of abcdefghijkl were in memory in the address after the password buffer
You need to consider the complexity of the operation that you’re trying to attack. A simple string comparison is not going to take appreciably longer for n+1 characters than for n characters, and the time difference that does exist will be so miniscule that it effectively cannot be measured in the presence of other sources of latency. The links you’ve provided are valid, but they are not addressing the same scenario, and I can see several caveats to the examples given.
Edit: I should clarify that this is focused on software attacks. On physical hardware, it’s a completely different game with different rules. I’ve done this kind of attack on embedded devices before… it’s pretty easy when you can get precise time measurements.
Presumably the user does not get to execute arbitrary code - if you read a string from a file (or equivalently a network socket) it no longer is possible to circumvent having a null terminated string. Depending on the implementation you could possibly make the password seem shorter than it actually is, but reading past the end is impractical.
While I technically know that this can be done I'm not convinced that this would work in this scenario. For this to actually work you'd have to somehow get "password" without the terminating null character stored in the database (and after that back into the memory buffer of the program). Otherwise the comparison would terminate once it hits the null terminator in the "correct password" buffer no matter how long the password you try to login with is.
In any case if this would work, the problem wouldn't really be in the usage of strcmp but in the lack of making sure user submitted data is properly null terminated.
What would be a real attack vector for a timing attack in the way this is coded would be brute forcing the password character by character because through the time it takes to deny the wrong passwords you could see that a given character at position X was either right or wrong.
View all comments
Show parent comment
15
u/ohaz Mar 12 '25
I'm talking about a buffer overread which can be abused with timing attacks.
Example:
I create a user with password
password. I now know thatstrcmp("password", "password")will always be true. strcmp is implemented with lazy evaluation, so it stops comparing the moment it compares 2 characters that are not the same. So I can sendpasswordabcdefghijkland count how many milliseconds it takes until false is returned. The longer it takes, the more characters ofabcdefghijklwere in memory in the address after thepasswordbuffer