This code is there not for performance
This code is there not for performance
Posted Feb 16, 2008 11:28 UTC (Sat) by ernest (guest, #2355)In reply to: This code is there not for performance by ms
Parent article: vmsplice(): the making of a local root exploit
It is unfortunate that the CPU cannot enforce signedness and size types. Anybody programming in assembly can bypass any higher level language type checks you have in mind. This is true even if the users has the best intentions. Ernest.
Posted Feb 17, 2008 19:50 UTC (Sun)
by giraffedata (guest, #1954)
[Link] (3 responses)
The unfortunateness is at a lower level than that. It's unfortunate that a CPU can't do ordinary integer math, where 2 + 2 = 4. I understand why the very first CPUs wrapped around integers -- it happens naturally with the simplest implementations. But I don't get why no CPU today provides even the option of trapping on an arithmetic overflow instead of wrapping around silently. They do it for floating point, but not for integers.
Posted Feb 23, 2008 21:45 UTC (Sat)
by anton (subscriber, #25547)
[Link] (2 responses)
The existence of INTO has not helped against this security hole, though.
Posted Feb 23, 2008 22:24 UTC (Sat)
by giraffedata (guest, #1954)
[Link] (1 responses)
Nice. Do you know if there is any way to make GCC (or any other C compiler) generate such instructions?
I can understand people resisting adding instructions to handle overflow, but if I could declare in my C program "no arithmetic in here is supposed to wrap around" and get signalled to death if it does, I'd do it a lot.
Posted Feb 28, 2008 21:23 UTC (Thu)
by anton (subscriber, #25547)
[Link]
Concerning "no arithmetic in here is supposed to wrap around",
unsigned arithmetic is supposed to wrap around in standard C, only
signed arithmetic is allowed to trap (or do anything else) on
overflow.
This code is there not for performance
It is unfortunate that the CPU cannot enforce signedness and size types.
Trapping on overflow
But I don't get why no CPU today provides even the option
of trapping on an arithmetic overflow.
MIPS and Alpha have separate arithmetic instructions that trap on
signed overflow (e.g., ADD on MIPS and ADDV on Alpha). IA-32 has INTO
which traps if OF is set. Apparently this instruction was so rarely
used by programmers, that AMD64 removed it in order to free up some
opcode space, and did not even bother to allocate another (multi-byte)
opcode for it; but you can still implement the functionality by
combining JO (or JNO) with INT.
Trapping on overflow
MIPS and Alpha have separate arithmetic instructions that trap on signed overflow ...
Apart from asm statements and modifying gcc I don't know of a way to
get gcc or other compilers to use the trapping instructions for C
code.
Trapping on overflow