netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: gfree.wind@foxmail.com
To: davem@davemloft.net, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, gfree.wind@foxmail.com
Cc: Gao Feng <fgao@ikuai8.com>
Subject: [PATCH net 1/1] proc/sysctl: Fix the int overflow for jiffies conversion
Date: Thu, 30 Mar 2017 08:39:44 +0800	[thread overview]
Message-ID: <1490834384-8833-1-git-send-email-gfree.wind@foxmail.com> (raw)

From: Gao Feng <fgao@ikuai8.com>

The function do_proc_dointvec_jiffies_conv uses LONG_MX/HZ as the
max value to avoid overflow. But actually the *valp is int type, so
it still causes overflow.

For example,
echo 2147483647 > ./sys/net/ipv4/tcp_keepalive_time
Then,
cat ./sys/net/ipv4/tcp_keepalive_time
The output is "-1", it is not expected.

Now use INT_MAX/HZ as the max value instead LONG_MAX/HZ to fix it.

Signed-off-by: Gao Feng <fgao@ikuai8.com>
---
 kernel/sysctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index acf0a5a..60474df 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2571,7 +2571,7 @@ static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
 					 int write, void *data)
 {
 	if (write) {
-		if (*lvalp > LONG_MAX / HZ)
+		if (*lvalp > INT_MAX / HZ)
 			return 1;
 		*valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
 	} else {
-- 
1.9.1

                 reply	other threads:[~2017-03-30  0:40 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1490834384-8833-1-git-send-email-gfree.wind@foxmail.com \
    --to=gfree.wind@foxmail.com \
    --cc=davem@davemloft.net \
    --cc=fgao@ikuai8.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.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).