From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755850AbbCaRNy (ORCPT ); Tue, 31 Mar 2015 13:13:54 -0400 Received: from mout.gmx.net ([212.227.17.22]:54706 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753619AbbCaRNt (ORCPT ); Tue, 31 Mar 2015 13:13:49 -0400 Message-ID: <551AD59B.8060906@gmx.de> Date: Tue, 31 Mar 2015 19:12:59 +0200 From: Heinrich Schuchardt User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.5.0 MIME-Version: 1.0 To: Andrew Morton CC: Michal Nazarewicz , Ingo Molnar , Steven Rostedt , Peter Zijlstra , Joe Perches , Josh Hunt , Rasmus Villemoes , Rusty Russell , Daniel Walter , David Rientjes , Kees Cook , "David S. Miller" , Johannes Weiner , Aaron Tomlin , Prarit Bhargava , Eric B Munson , "Paul E. McKenney" , Sam Ravnborg , linux-kernel@vger.kernel.org, Alexey Dobriyan Subject: Fwd: [PATCH 3/3] sysctl: detect overflows when converting to int References: <1427657309-4344-1-git-send-email-xypron.glpk@gmx.de> <1427657309-4344-4-git-send-email-xypron.glpk@gmx.de> In-Reply-To: <1427657309-4344-4-git-send-email-xypron.glpk@gmx.de> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K0:TjSJ0XMMdeZyMj1LRXqm3EOgAQlFMlb559jP/K9ib3JsAvUX7KK RbYd5E581RZrC8xhykMQlyt1kQCiVmk3bMaHT417TXMGO6RVcUlaVA261HEhggEzluFAT97 XOkvb/ywcBuuCY22h7CWbWXS3m3syDeR2YpU5OzbD10XCZWhPdQw7mv/Abduk9oavAgFTTz FAbxz99pm6XmuSNAE9byQ== X-UI-Out-Filterresults: notjunk:1; Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Andrew, could you, please, propagate the patch in https://lkml.org/lkml/2015/3/29/189 to the MM tree. It is independent of the other two patches in the patch series. Rework for the other patches was requested by Alexey Dobriyan in https://lkml.org/lkml/2015/3/31/251 Best regards Heinrich Schuchardt On 29.03.2015 21:28, Heinrich Schuchardt wrote: > When converting unsigned long to int overflows may occur. > These currently are not detected when writing to the sysctl > file system. > > E.g. on a system where int has 32 bits and long has 64 bits > echo 0x800001234 > /proc/sys/kernel/threads-max > has the same effect as > echo 0x1234 > /proc/sys/kernel/threads-max > > The patch adds the missing check in do_proc_dointvec_conv. > > With the patch an overflow will result in an error EINVAL when > writing to the the sysctl file system. > > Signed-off-by: Heinrich Schuchardt > --- > kernel/sysctl.c | 10 +++++++++- > 1 file changed, 9 insertions(+), 1 deletion(-) > > diff --git a/kernel/sysctl.c b/kernel/sysctl.c > index 4d9d139..2fd6b82 100644 > --- a/kernel/sysctl.c > +++ b/kernel/sysctl.c > @@ -1953,7 +1953,15 @@ static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp, > int write, void *data) > { > if (write) { > - *valp = *negp ? -*lvalp : *lvalp; > + if (*negp) { > + if (*lvalp > (unsigned long) INT_MAX + 1) > + return -EINVAL; > + *valp = -*lvalp; > + } else { > + if (*lvalp > (unsigned long) INT_MAX) > + return -EINVAL; > + *valp = *lvalp; > + } > } else { > int val = *valp; > if (val < 0) { >