Safety of typecasting in execv

(David Robert Olsen) #1

In order to get execv working with my particular design, I have to typecast the args into a usable type from const_userptr_t , do some operations, and typecast back to const_userptr_t to copy into kernel space.

Is it possible for a design like this to work, or is it too hacky/a dead end? I am leaning towards dead end, as no matter what I do, I am not successfully copying anything into my kernel buffer using this approach.

Expanding on this, does it make sense to try to keep the arguments passed in by the user in the same *arg[index] format with char ** pointer in the kernel?

(Geoffrey Challen) #2

I’m not sure exactly what you’re trying to do.

Typecasting to userptr_t (and the constant variants) is a safety mechanism. Doing so will help the compiler help you make sure that you aren’t doing anything unsafe with pointers that came in from user land.

That said, sometimes you know better than the compiler. So feel free to recast as needed, as long as you can convince yourself that you aren’t doing anything unsafe. At the end of the day, it’s C, and it’s all just bytes.

(David Robert Olsen) #3

That makes sense.

Quick syntax question though - if I kmalloc a block of memory to be used by a char ** array, I am only allocating memory for the pointers themselves, not the strings they eventually point to, right?

(Geoffrey Challen) #4

That’s correct. You’ll eventually need space for both the array and the strings themselves.