Linux-Fsdevel Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Changming Liu <charley.ashbringer@gmail.com>
To: keescook@chromium.org
Cc: mcgrof@kernel.org, yzaikin@google.com,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	Changming Liu <charley.ashbringer@gmail.com>
Subject: [PATCH] sysctl: add bound to panic_timeout to prevent overflow
Date: Thu,  9 Jul 2020 23:22:23 -0400	[thread overview]
Message-ID: <1594351343-11811-1-git-send-email-charley.ashbringer@gmail.com> (raw)

Function panic() in kernel/panic.c will use panic_timeout
multiplying 1000 as a loop boundery. So this multiplication
can overflow when panic_timeout is greater than (INT_MAX/1000).
And this results in a zero-delay panic, instead of a huge
timeout as the user intends.

Fix this by adding bound check to make it no bigger than
(INT_MAX/1000).

Signed-off-by: Changming Liu <charley.ashbringer@gmail.com>
---
 kernel/sysctl.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index db1ce7a..e60cf04 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -137,6 +137,9 @@ static int minolduid;
 static int ngroups_max = NGROUPS_MAX;
 static const int cap_last_cap = CAP_LAST_CAP;
 
+/* this is needed for setting boundery for panic_timeout to prevent it from overflow*/
+static int panic_time_max = INT_MAX / 1000;
+
 /*
  * This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
  * and hung_task_check_interval_secs
@@ -1857,7 +1860,8 @@ static struct ctl_table kern_table[] = {
 		.data		= &panic_timeout,
 		.maxlen		= sizeof(int),
 		.mode		= 0644,
-		.proc_handler	= proc_dointvec,
+		.proc_handler	= proc_dointvec_minmax,
+		.extra2		= &panic_time_max,
 	},
 #ifdef CONFIG_COREDUMP
 	{
-- 
2.7.4


             reply	other threads:[~2020-07-10  3:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-10  3:22 Changming Liu [this message]
2020-07-10  3:31 ` Randy Dunlap
2020-07-10 11:28   ` Matthew Wilcox
2020-07-10 22:28     ` charley.ashbringer

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=1594351343-11811-1-git-send-email-charley.ashbringer@gmail.com \
    --to=charley.ashbringer@gmail.com \
    --cc=keescook@chromium.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=yzaikin@google.com \
    --subject='Re: [PATCH] sysctl: add bound to panic_timeout to prevent overflow' \
    /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

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).