The 5.7 kernel is out
The 5.7 kernel is out
Posted Jun 2, 2020 12:21 UTC (Tue) by adobriyan (guest, #30858)In reply to: The 5.7 kernel is out by Wol
Parent article: The 5.7 kernel is out
Given
int f(const char *str, int *val);
int val;
int rv = f(str, &val);
if (rv < 0)
return rv;
[use "val"]
C ABI and single return value forces to allocate data on a stack and a write.
Now top of stack is optimized so it doesn't matter for performance, but the act of writing to [rsp+] has second order effects.
Stack protector sees that function modifies memory and starts placing canaries, bloating code and issuing reads and adding
mandatory branch for stack smashing.
Could this be solved in C? Yes, by using 2-value structure which fully fits into 2x8-byte registers.
C ABI even has provision for this by referring to RDX as a second return value.
Which of course nobody uses because there is no syntax for destructuring.
