Re: [PATCH 3/3] sysctl: report EINVAL if value is larger than UINT_MAX for proc_douintvec

From: Eric W. Biederman
Date: Fri Apr 07 2017 - 17:07:00 EST


Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> writes:

> On Fri, Apr 7, 2017 at 8:51 AM, Liping Zhang <zlpnobody@xxxxxxx> wrote:
>> From: Liping Zhang <zlpnobody@xxxxxxxxx>
>>
>> Currently, inputting the following command will succeed but actually the
>> value will be truncated:
>> # echo 0x12ffffffff > /proc/sys/net/ipv4/tcp_notsent_lowat
>>
>> This is not friendly to the user, so instead, we should report error
>> when the value is larger than UINT_MAX.
>
> I applied the two other patches, but I didn't apply this one.
>
> It's entirely possible that people end up doing something like
>
> echo -1 > /proc/sys/some_random_uint
>
> because that's a fairly normal thing to do to set all bits. Making
> that an error seems wrong.

Except that doesn't help in this case. The function do_uintvec_conv
rules already rejects all negative values on write. So -1 is already
rejected.

In fact the function proc_douintvec_conv has always rejected negative
values so this change won't even create a regression.

So it looks perfectly reasonable to reject values that are simply too
large to be written to the uint.

So even today to write all bits set you do have to do:

echo 0xffffffff > /proc/sys/some_random_uint

Eric