Re: [PATCH] lib: introduce strdup_from_user

From: Alexey Dobriyan
Date: Fri Jun 03 2011 - 15:12:44 EST


On Fri, Jun 3, 2011 at 9:53 PM, Scott Wood <scottwood@xxxxxxxxxxxxx> wrote:
> On Fri, 3 Jun 2011 21:39:28 +0300
> Alexey Dobriyan <adobriyan@xxxxxxxxx> wrote:
>
>> On Fri, Jun 3, 2011 at 9:34 PM, Timur Tabi <timur@xxxxxxxxxxxxx> wrote:
>> > Would it be better if I did this:
>>
>> The point is data should cross kernelspace/userspace boundary only once.
>>
>
> Why does it matter, as long as it doesn't hurt the kernel if userspace
> plays games (i.e. take care of the NUL termination), and it's not a
> performance problem?

Because now you're lucky C strings are NUL-terminated.
If this "idiom" applies to some other case like "validate + copy",
we have a bug.

We copy data to kernelspace THEN validate or copy or whatever.
This is obviously correct and safe.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/