Re: [PATCH] sysctl: fix improper indication of integer sysctl parameter

From: Eric W. Biederman
Date: Tue Jul 31 2012 - 10:39:04 EST


David Howells <dhowells@xxxxxxxxxx> writes:

> Mitsuo Hayasaka <mitsuo.hayasaka.hu@xxxxxxxxxxx> wrote:
>
>> When we read the sysctl parameter, they are always treated
>> as signed integer, and are casted into unsigned long type
>> in the current kernel. If we set a value equivalent to
>> (the maximum value in signed integer + 1)
>
> Wouldn't it be better to return EINVAL or EDOM?

Yes we should definitely fail the write in the case where we write an
unsigned value and we can not fit that value in an integer.

There will still remain the bug of reading the integer
where (-val == val) && val < 0. In that case we do want to an
(unsigned int) before storing it in an unsinged long.

The decription of the patch is confusing.

The problem is not the cast to unsigned long, the problem is
the implicit cast to signed long which happens before the cast
to unsigned long. I think this is a case where C's casting rules
get it wrong. If I have an explicit cast why add an implicit
cast to do sign extension. Sigh.

Mitsuo since you are looking at this do you think you could fix the
write side of the problem as well, and check to make cetain the
unsigned value we write will fit in an interger.

Eric
--
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/