linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Heinrich Schuchardt <xypron.glpk@gmx.de>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Michal Nazarewicz <mina86@mina86.com>,
	Ingo Molnar <mingo@kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Joe Perches <joe@perches.com>, Josh Hunt <johunt@akamai.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Rusty Russell <rusty@rustcorp.com.au>,
	Daniel Walter <dwalter@google.com>,
	David Rientjes <rientjes@google.com>,
	Kees Cook <keescook@chromium.org>,
	"David S. Miller" <davem@davemloft.net>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Aaron Tomlin <atomlin@redhat.com>,
	Prarit Bhargava <prarit@redhat.com>,
	Eric B Munson <emunson@akamai.com>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Sam Ravnborg <sam@ravnborg.org>,
	linux-kernel@vger.kernel.org,
	Alexey Dobriyan <adobriyan@gmail.com>
Subject: Fwd: [PATCH 3/3] sysctl: detect overflows when converting to int
Date: Tue, 31 Mar 2015 19:12:59 +0200	[thread overview]
Message-ID: <551AD59B.8060906@gmx.de> (raw)
In-Reply-To: <1427657309-4344-4-git-send-email-xypron.glpk@gmx.de>

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 <xypron.glpk@gmx.de>
> ---
>  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) {
> 


  reply	other threads:[~2015-03-31 17:13 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-29 19:28 [PATCH 0/3] sysctl: detect overflows when setting integers Heinrich Schuchardt
2015-03-29 19:28 ` [PATCH 1/3] lib/kstrtox.c: functions returning end of string Heinrich Schuchardt
2015-03-29 19:28 ` [PATCH 2/3] sysctl: detect overflows in proc_get_long Heinrich Schuchardt
2015-03-29 19:28 ` [PATCH 3/3] sysctl: detect overflows when converting to int Heinrich Schuchardt
2015-03-31 17:12   ` Heinrich Schuchardt [this message]
2015-03-31 22:45   ` Andrew Morton
2015-04-01 17:31     ` Heinrich Schuchardt
2015-06-08 22:41       ` Kees Cook

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=551AD59B.8060906@gmx.de \
    --to=xypron.glpk@gmx.de \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=atomlin@redhat.com \
    --cc=davem@davemloft.net \
    --cc=dwalter@google.com \
    --cc=emunson@akamai.com \
    --cc=hannes@cmpxchg.org \
    --cc=joe@perches.com \
    --cc=johunt@akamai.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=mina86@mina86.com \
    --cc=mingo@kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=prarit@redhat.com \
    --cc=rientjes@google.com \
    --cc=rostedt@goodmis.org \
    --cc=rusty@rustcorp.com.au \
    --cc=sam@ravnborg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).