Re:The Linux Kernel Is Now VLA (Variable-Length Array) Free
by drfuchs on Monday October 29, 2018 @09:17AM
(#18327239)
You'd have to get longjmp to understand how to unwind these heap-allocated arrays, not only from the current function's stack frame, but for all the ones in the longjmp'd-over frames. In C-land, longjmp simply overwrites the stack pointer (and all other registers), which implicitly "deallocates" all the VLA arrays, and all alloca() allocations, in one fell swoop. There is no notion of a step-by-step unwinding of the stack, so it would be a big task to try to trap all intermediate VLA arrays.
Re:The Linux Kernel Is Now VLA (Variable-Length Array) Free
by palotasb on Monday October 29, 2018 @08:28AM
(#18326908)
I'd guess because VLA on the heap already existed and it's called malloc. The only difference would be free() being called automatically but that is not something the C standard would do lightly.
Re:The Linux Kernel Is Now VLA (Variable-Length Array) Free
by lstodd on Monday October 29, 2018 @08:18AM
(#18326849)
Because there might not be a heap at all.
Re:The Linux Kernel Is Now VLA (Variable-Length Array) Free
by castratikron on Monday October 29, 2018 @08:18AM
(#18326851)
Stack allocation is easier to implement and faster than heap allocation. The former can be implemented in a single instruction (incrementing the stack pointer).
What I don't understand is: after all these decades of stack smashing vulnerabilities, why would such a shortcut have been taken?
Convenience costs performance, safety costs performance ... at some point you just have to suck it up and pay the performance penalty to make things safer and to improve programmer productivity.