From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752936AbcFNUTJ (ORCPT ); Tue, 14 Jun 2016 16:19:09 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:53427 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751833AbcFNUTH (ORCPT ); Tue, 14 Jun 2016 16:19:07 -0400 Date: Tue, 14 Jun 2016 13:19:06 -0700 From: Andrew Morton To: Heinrich Schuchardt Cc: Arnaldo Carvalho de Melo , Kees Cook , Don Zickus , Al Viro , Dave Young , Hugh Dickins , Thomas Gleixner , Daniel Cashman , Willy Tarreau , Alexei Starovoitov , "Eric W. Biederman" , Ilya Dryomov , linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/1] kernel/sysctl.c: avoid overflow Message-Id: <20160614131906.4a5a9db55946735fbd57c4f5@linux-foundation.org> In-Reply-To: <1465608788-4813-1-git-send-email-xypron.glpk@gmx.de> References: <1465608788-4813-1-git-send-email-xypron.glpk@gmx.de> X-Mailer: Sylpheed 3.4.1 (GTK+ 2.24.23; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.