From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932185AbcFNUmF (ORCPT ); Tue, 14 Jun 2016 16:42:05 -0400 Received: from wtarreau.pck.nerim.net ([62.212.114.60]:49806 "EHLO 1wt.eu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751597AbcFNUmD (ORCPT ); Tue, 14 Jun 2016 16:42:03 -0400 Date: Tue, 14 Jun 2016 22:41:49 +0200 From: Willy Tarreau To: Andrew Morton Cc: Heinrich Schuchardt , Arnaldo Carvalho de Melo , Kees Cook , Don Zickus , Al Viro , Dave Young , Hugh Dickins , Thomas Gleixner , Daniel Cashman , Alexei Starovoitov , "Eric W. Biederman" , Ilya Dryomov , linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/1] kernel/sysctl.c: avoid overflow Message-ID: <20160614204149.GA2723@1wt.eu> References: <1465608788-4813-1-git-send-email-xypron.glpk@gmx.de> <20160614131906.4a5a9db55946735fbd57c4f5@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160614131906.4a5a9db55946735fbd57c4f5@linux-foundation.org> User-Agent: Mutt/1.6.0 (2016-04-01) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 14, 2016 at 01:19:06PM -0700, Andrew Morton wrote: > On Sat, 11 Jun 2016 03:33:08 +0200 Heinrich Schuchardt 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. I'd go even further, I don't see anymore how it becomes possible to actually *write* 0xffffffff at all! This function is used by proc_dointvec_minmax() which is used with extra1=&zero and extra2 not set with some unsigned ints to allow the full range to be configured (eg: dirty_expire_interval is the first I found by a quick random look). So for me this change is bogus. Willy