From: Kangjie Lu <kjlu@umn.edu>
To: kjlu@umn.edu
Cc: pakki001@umn.edu, Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
linux-kernel@vger.kernel.org
Subject: [PATCH] sched: fix a potential double-fetch bug in sched_copy_attr
Date: Tue, 25 Dec 2018 16:16:47 -0600 [thread overview]
Message-ID: <20181225221648.70069-1-kjlu@umn.edu> (raw)
"uattr->size" is copied in from user space and checked. However, it is
copied in again after the security check. A malicious user may race to
change it. The fix checks if uattr->size is ever changed after the
check.
Signed-off-by: Kangjie Lu <kjlu@umn.edu>
---
kernel/sched/core.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 6fedf3a98581..0a55bdce9a42 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -4447,7 +4447,7 @@ do_sched_setscheduler(pid_t pid, int policy, struct sched_param __user *param)
*/
static int sched_copy_attr(struct sched_attr __user *uattr, struct sched_attr *attr)
{
- u32 size;
+ u32 size, size_cp;
int ret;
if (!access_ok(VERIFY_WRITE, uattr, SCHED_ATTR_SIZE_VER0))
@@ -4460,15 +4460,17 @@ static int sched_copy_attr(struct sched_attr __user *uattr, struct sched_attr *a
if (ret)
return ret;
+ size_cp = size;
+
/* Bail out on silly large: */
if (size > PAGE_SIZE)
goto err_size;
/* ABI compatibility quirk: */
if (!size)
- size = SCHED_ATTR_SIZE_VER0;
+ size_cp = SCHED_ATTR_SIZE_VER0;
- if (size < SCHED_ATTR_SIZE_VER0)
+ else if (size < SCHED_ATTR_SIZE_VER0)
goto err_size;
/*
@@ -4483,7 +4485,7 @@ static int sched_copy_attr(struct sched_attr __user *uattr, struct sched_attr *a
unsigned char val;
addr = (void __user *)uattr + sizeof(*attr);
- end = (void __user *)uattr + size;
+ end = (void __user *)uattr + size_cp;
for (; addr < end; addr++) {
ret = get_user(val, addr);
@@ -4492,13 +4494,17 @@ static int sched_copy_attr(struct sched_attr __user *uattr, struct sched_attr *a
if (val)
goto err_size;
}
- size = sizeof(*attr);
+ size_cp = sizeof(*attr);
}
- ret = copy_from_user(attr, uattr, size);
+ ret = copy_from_user(attr, uattr, size_cp);
if (ret)
return -EFAULT;
+ /* Sanity check if size was changed in user space */
+ if (attr->size != size)
+ return -EINVAL;
+
/*
* XXX: Do we want to be lenient like existing syscalls; or do we want
* to be strict and return an error on out-of-bounds values?
--
2.17.2 (Apple Git-113)
next reply other threads:[~2018-12-25 22:17 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-25 22:16 Kangjie Lu [this message]
2019-01-07 17:11 ` [PATCH] sched: fix a potential double-fetch bug in sched_copy_attr Peter Zijlstra
2019-01-09 7:45 ` [PATCH v2] " Kangjie Lu
2019-01-21 11:32 ` [tip:sched/core] sched/core: Fix a potential double-fetch bug in sched_copy_attr() tip-bot for Kangjie Lu
2019-01-27 11:04 ` Thomas Gleixner
2019-01-27 11:28 ` Ingo Molnar
2019-01-28 7:58 ` Peter Zijlstra
2019-01-28 13:15 ` Thomas Gleixner
2019-03-10 10:09 ` Thomas Gleixner
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=20181225221648.70069-1-kjlu@umn.edu \
--to=kjlu@umn.edu \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pakki001@umn.edu \
--cc=peterz@infradead.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).