Skip to contentSkip to conversation

sched/core: Fix a potential double fetch bug on attr->size

PATCH In review Meng Xu 2 participants 3 messages Aug 29, 2017 – Sep 25, 2017 1 message not in the archive Scheduler

lore
Share & tools
lore

Meng Xu

author
#0 lore raw

PATCH 1/1 sched/core: Fix a potential double fetch bug on attr->size

From: Meng Xu <[email protected]>

attr->size after the second fetch copy_from_user(attr, uattr, size), can be different from what is initially fetched in and checked get_user(size, &uattr->size) by racing condition in the userspace.

The issue and the patch are both similar to commit f12f42a (in kernel/events/core.c).

---
 kernel/sched/core.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/sched/core.c +2 -0
index 0869b20..c22d2b4 100644
@@ -4349,6 +4349,8 @@ static int sched_copy_attr(struct sched_attr __user *uattr, struct sched_attr *a
 	if (ret)
 		return -EFAULT;
 
+	attr->size = size;
+
 	/*
 	 * 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?
Signature · 1 line
2.7.4

A message that is not in the archive (sent off-list or not yet received): [email protected]

maintainer
#2 lore raw
Quoted 6 lines · Meng Xu

Hi Peter and Ingo,

As a reminder, this is a very similar issue to perf_copy_attr (see following patch)
https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?id=f12f42acdbb577a12eecfcebbbec41c81505c4dc <https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?id=f12f42acdbb577a12eecfcebbbec41c81505c4dc>

Will it be fixed as well?

If someone were to actually send me the patch.. probably.

Quoted 33 lines
Quoted 32 lines · Meng Xu

From: Meng Xu <[email protected]>

attr->size after the second fetch copy_from_user(attr, uattr, size), can be different from what is initially fetched in and checked get_user(size, &uattr->size) by racing condition in the userspace.

The issue and the patch are both similar to commit f12f42a (in kernel/events/core.c).

---
kernel/sched/core.c | 2 ++

1 file changed, 2 insertions(+)
kernel/sched/core.c +2 -0
index 0869b20..c22d2b4 100644
@@ -4349,6 +4349,8 @@ static int sched_copy_attr(struct sched_attr __user *uattr, struct sched_attr *a
 	if (ret)
 		return -EFAULT;
 
+	attr->size = size;
+
 	/*
 	 * 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?
Signature · 1 line
2.7.4
author
#3 lore raw

Hi Peter,

I am sorry, I thought the patch is included in the forwarded email. I just resent the patch. Please check.

Best Regards,
Meng

Quoted 41 lines · Peter Zijlstra
Quoted 6 lines · Meng Xu

Hi Peter and Ingo,

As a reminder, this is a very similar issue to perf_copy_attr (see following patch)
https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?id=f12f42acdbb577a12eecfcebbbec41c81505c4dc <https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?id=f12f42acdbb577a12eecfcebbbec41c81505c4dc>

Will it be fixed as well?

If someone were to actually send me the patch.. probably.

Quoted 32 lines
Quoted 32 lines · Meng Xu

From: Meng Xu <[email protected]>

attr->size after the second fetch copy_from_user(attr, uattr, size), can be different from what is initially fetched in and checked get_user(size, &uattr->size) by racing condition in the userspace.

The issue and the patch are both similar to commit f12f42a (in kernel/events/core.c).

---
kernel/sched/core.c | 2 ++

1 file changed, 2 insertions(+)
kernel/sched/core.c +2 -0
index 0869b20..c22d2b4 100644
@@ -4349,6 +4349,8 @@ static int sched_copy_attr(struct sched_attr __user *uattr, struct sched_attr *a
 	if (ret)
 		return -EFAULT;
 
+	attr->size = size;
+
 	/*
 	 * 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?
Signature · 1 line
2.7.4