lkml.org 
[lkml]   [2016]   [Jun]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH 1/1] kernel/sysctl.c: avoid overflow
On Tue, Jun 14, 2016 at 1:19 PM, Andrew Morton
<akpm@linux-foundation.org> wrote:
> On Sat, 11 Jun 2016 03:33:08 +0200 Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
>> An undetected overflow may occur in do_proc_dointvec_minmax_conv_param.
>>
>> ...
>>
>> --- a/kernel/sysctl.c
>> +++ b/kernel/sysctl.c
>> @@ -2313,7 +2313,17 @@ static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
>> {
>> struct do_proc_dointvec_minmax_conv_param *param = data;
>> if (write) {
>> - int val = *negp ? -*lvalp : *lvalp;
>> + int val;
>> +
>> + if (*negp) {
>> + if (*lvalp > (unsigned long) INT_MAX + 1)
>> + return -EINVAL;
>> + val = -*lvalp;
>> + } else {
>> + if (*lvalp > (unsigned long) INT_MAX)
>> + return -EINVAL;
>> + val = *lvalp;
>> + }
>> if ((param->min && *param->min > val) ||
>> (param->max && *param->max < val))
>> return -EINVAL;
>
> hm.
>
> What happens if someone does
>
> echo -1 > /proc/foo
>
> expecting to get 0xffffffff? That's a reasonable shorthand, and if we
> change that to spit out EINVAL then people's stuff may break.

If we expect the interface to allow overflows, we should at least add
comments to do_proc_dointvec_minmax_conv_param()...

-Kees

--
Kees Cook
Chrome OS & Brillo Security

\
 
 \ /
  Last update: 2016-06-14 23:21    [W:0.076 / U:0.156 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site