tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: alloca() in kernel code
Le 12/10/2019 à 02:01, Emmanuel Dreyfus a écrit :
Hello
I recently encountered a situation where I had to deal with variable
length structure at a time where kernel dynamic allocator was not
initialized.
Using alloca() to have the data allocated on stack seemed attractive,
but unfortunately kernel build infrastructure ban that:
For good reasons.
error: stack protector not protecting local variables: variable length
buffer [-Werror=stack-protector]
As a result, I have to rely on a fixed-size buffer big enough so that I
can hope data will fit, and miserabily fail otherwise.
Is it possible to relax the protection on some code section?
No. The kernel stack is rather small, we should not start allocating
variable-sized stuff on it.
Or is there an alternative way of dealing with that?
You didn't say what exactly you wanted to allocate memory for, so it's hard to
tell. The rare legitimate cases where I've had to do that, I picked buffers
big enough.
In all cases, we should never allocate variable-sized buffers on the stack in
the kernel.
Home |
Main Index |
Thread Index |
Old Index