Skip to contentSkip to conversation

sched_getattr.2: update to include changed size semantics

PATCH In review Aleksa Sarai 3 participants 9 messages Nov 28, 2019 – Sep 30, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched_getattr.2: update to include changed size semantics

Due to a userspace breakage, commit 1251201c0d34 ("sched/core: Fix uclamp ABI bug, clean up and robustify sched_read_attr() ABI logic and code") changed the semantics of sched_getattr(2) when the userspace struct is smaller than the kernel struct. Now, any trailing non-zero data in the kernel structure is ignored when copying to userspace.

Ref: 1251201c0d34 ("sched/core: Fix uclamp ABI bug, clean up and
robustify sched_read_attr() ABI logic and code")

---
 man2/sched_setattr.2 | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
man2/sched_setattr.2 +2 -4
index 76ffa14eba85..fbb67b8eb98b 100644
@@ -284,10 +284,8 @@ structure,
 the additional bytes in the user-space structure are not touched.
 If the caller-provided structure is smaller than the kernel
 .I sched_attr
-structure and the kernel needs to return values outside the provided space,
-.BR sched_getattr ()
-fails with the error
-.BR E2BIG .
+structure, the kernel will silently not return any values which would be stored
+outside the provided space.
 As with
 .BR sched_setattr (),
 these semantics allow for future extensibility of the interface.
Signature · 1 line
2.24.0
#1 lore raw
Quoted 33 lines · Aleksa Sarai

Due to a userspace breakage, commit 1251201c0d34 ("sched/core: Fix uclamp ABI bug, clean up and robustify sched_read_attr() ABI logic and code") changed the semantics of sched_getattr(2) when the userspace struct is smaller than the kernel struct. Now, any trailing non-zero data in the kernel structure is ignored when copying to userspace.

Ref: 1251201c0d34 ("sched/core: Fix uclamp ABI bug, clean up and
robustify sched_read_attr() ABI logic and code")

---
 man2/sched_setattr.2 | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
man2/sched_setattr.2 +2 -4
index 76ffa14eba85..fbb67b8eb98b 100644
@@ -284,10 +284,8 @@ structure,
 the additional bytes in the user-space structure are not touched.
 If the caller-provided structure is smaller than the kernel
 .I sched_attr
-structure and the kernel needs to return values outside the provided space,
-.BR sched_getattr ()
-fails with the error
-.BR E2BIG .
+structure, the kernel will silently not return any values which would be stored
+outside the provided space.
 As with
 .BR sched_setattr (),
 these semantics allow for future extensibility of the interface.
Signature · 1 line
2.24.0

I was thinking about documenting the difference in behavior of older kernels, before uclamp support.

However, in practice, for sched_getattr, the kernel never returned E2BIG (the code uses EFBIG incorrectly, in fact). It does, however, return EINVAL for sizes smaller than SCHED_ATTR_SIZE_VER0.

The EINVAL return is already well documented in the manpage.

However, E2BIG is still mentioned below as a possible return value for sched_getattr. Can you remove that too?

Thanks.
Cascardo.

#2 lore raw
Quoted 38 lines · Thadeu Lima de Souza Cascardo
Quoted 33 lines · Aleksa Sarai

Due to a userspace breakage, commit 1251201c0d34 ("sched/core: Fix uclamp ABI bug, clean up and robustify sched_read_attr() ABI logic and code") changed the semantics of sched_getattr(2) when the userspace struct is smaller than the kernel struct. Now, any trailing non-zero data in the kernel structure is ignored when copying to userspace.

Ref: 1251201c0d34 ("sched/core: Fix uclamp ABI bug, clean up and
robustify sched_read_attr() ABI logic and code")

---
 man2/sched_setattr.2 | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
man2/sched_setattr.2 +2 -4
index 76ffa14eba85..fbb67b8eb98b 100644
@@ -284,10 +284,8 @@ structure,
 the additional bytes in the user-space structure are not touched.
 If the caller-provided structure is smaller than the kernel
 .I sched_attr
-structure and the kernel needs to return values outside the provided space,
-.BR sched_getattr ()
-fails with the error
-.BR E2BIG .
+structure, the kernel will silently not return any values which would be stored
+outside the provided space.
 As with
 .BR sched_setattr (),
 these semantics allow for future extensibility of the interface.
Signature · 1 line
2.24.0

I was thinking about documenting the difference in behavior of older kernels, before uclamp support.

Quoted 3 lines

However, in practice, for sched_getattr, the kernel never returned E2BIG (the code uses EFBIG incorrectly, in fact). It does, however, return EINVAL for sizes smaller than SCHED_ATTR_SIZE_VER0.

I've been told the EFBIG was actually a typo and it was always meant to be E2BIG. But yes, the precise problem with the old semantics was that they weren't tested "in the wild" with a proper struct upgrade -- hence all of the headaches.

If we ever do implement a copy_struct_to_user() we are almost certainly going to implement it with the new sched_getattr() semantics. To be honest, I'm not sure I can imagine a case where an old userspace program would benefit from being given an error saying that the kernel has some properties that it doesn't understand. (sched_getattr() is also weird for other reasons, such as the fact it takes a separate size argument.)

Quoted 2 lines

However, E2BIG is still mentioned below as a possible return value for sched_getattr. Can you remove that too?

Will do.

Signature · 4 lines
Aleksa Sarai
Senior Software Engineer (Containers)
SUSE Linux GmbH
<https://www.cyphar.com/>
#3 lore raw

Hi Aleksa,

I don't think there was ever a follow-up to this patch. Would you be willing to send one?

Thanks,

Michael

Quoted 66 lines · Aleksa Sarai
Quoted 38 lines · Thadeu Lima de Souza Cascardo
Quoted 31 lines · Aleksa Sarai

Due to a userspace breakage, commit 1251201c0d34 ("sched/core: Fix uclamp ABI bug, clean up and robustify sched_read_attr() ABI logic and code") changed the semantics of sched_getattr(2) when the userspace struct is smaller than the kernel struct. Now, any trailing non-zero data in the kernel structure is ignored when copying to userspace.

Ref: 1251201c0d34 ("sched/core: Fix uclamp ABI bug, clean up and
robustify sched_read_attr() ABI logic and code")

---
 man2/sched_setattr.2 | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
man2/sched_setattr.2 +2 -5
index 76ffa14eba85..fbb67b8eb98b 100644
@@ -284,10 +284,8 @@ structure,
 the additional bytes in the user-space structure are not touched.
 If the caller-provided structure is smaller than the kernel
 .I sched_attr
-structure and the kernel needs to return values outside the provided space,
-.BR sched_getattr ()
-fails with the error
-.BR E2BIG .
+structure, the kernel will silently not return any values which would be stored
+outside the provided space.
 As with
 .BR sched_setattr (),
 these semantics allow for future extensibility of the interface.
--
Quoted 2 lines

2.24.0

I was thinking about documenting the difference in behavior of older kernels, before uclamp support.

Quoted 3 lines

However, in practice, for sched_getattr, the kernel never returned E2BIG (the code uses EFBIG incorrectly, in fact). It does, however, return EINVAL for sizes smaller than SCHED_ATTR_SIZE_VER0.

I've been told the EFBIG was actually a typo and it was always meant to be E2BIG. But yes, the precise problem with the old semantics was that they weren't tested "in the wild" with a proper struct upgrade -- hence all of the headaches.

If we ever do implement a copy_struct_to_user() we are almost certainly going to implement it with the new sched_getattr() semantics. To be honest, I'm not sure I can imagine a case where an old userspace program would benefit from being given an error saying that the kernel has some properties that it doesn't understand. (sched_getattr() is also weird for other reasons, such as the fact it takes a separate size argument.)

Quoted 2 lines

However, E2BIG is still mentioned below as a possible return value for sched_getattr. Can you remove that too?

Will do.

--
Aleksa Sarai
Senior Software Engineer (Containers)
SUSE Linux GmbH
<https://www.cyphar.com/>

Signature · 3 lines
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
#4 lore raw

Hi Aleksa,

A ping also on this :-).

Cheers,

Michael

Quoted 84 lines · Michael Kerrisk (man-pages)

Hi Aleksa,

I don't think there was ever a follow-up to this patch. Would you be willing to send one?

Thanks,

Michael

Quoted 59 lines · Aleksa Sarai
Quoted 38 lines · Thadeu Lima de Souza Cascardo
Quoted 31 lines · Aleksa Sarai

Due to a userspace breakage, commit 1251201c0d34 ("sched/core: Fix uclamp ABI bug, clean up and robustify sched_read_attr() ABI logic and code") changed the semantics of sched_getattr(2) when the userspace struct is smaller than the kernel struct. Now, any trailing non-zero data in the kernel structure is ignored when copying to userspace.

Ref: 1251201c0d34 ("sched/core: Fix uclamp ABI bug, clean up and
robustify sched_read_attr() ABI logic and code")

---
 man2/sched_setattr.2 | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
man2/sched_setattr.2 +2 -5
index 76ffa14eba85..fbb67b8eb98b 100644
@@ -284,10 +284,8 @@ structure,
 the additional bytes in the user-space structure are not touched.
 If the caller-provided structure is smaller than the kernel
 .I sched_attr
-structure and the kernel needs to return values outside the provided space,
-.BR sched_getattr ()
-fails with the error
-.BR E2BIG .
+structure, the kernel will silently not return any values which would be stored
+outside the provided space.
 As with
 .BR sched_setattr (),
 these semantics allow for future extensibility of the interface.
--
Quoted 2 lines

2.24.0

I was thinking about documenting the difference in behavior of older kernels, before uclamp support.

Quoted 3 lines

However, in practice, for sched_getattr, the kernel never returned E2BIG (the code uses EFBIG incorrectly, in fact). It does, however, return EINVAL for sizes smaller than SCHED_ATTR_SIZE_VER0.

I've been told the EFBIG was actually a typo and it was always meant to be E2BIG. But yes, the precise problem with the old semantics was that they weren't tested "in the wild" with a proper struct upgrade -- hence all of the headaches.

If we ever do implement a copy_struct_to_user() we are almost certainly going to implement it with the new sched_getattr() semantics. To be honest, I'm not sure I can imagine a case where an old userspace program would benefit from being given an error saying that the kernel has some properties that it doesn't understand. (sched_getattr() is also weird for other reasons, such as the fact it takes a separate size argument.)

Quoted 2 lines

However, E2BIG is still mentioned below as a possible return value for sched_getattr. Can you remove that too?

Quoted 7 lines

Will do.

--
Aleksa Sarai
Senior Software Engineer (Containers)
SUSE Linux GmbH
<https://www.cyphar.com/>

--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/

Signature · 3 lines
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
#5 lore raw

PATCH 1/2 sched_getattr.2: update to include changed size semantics

Due to a userspace breakage, commit 1251201c0d34 ("sched/core: Fix uclamp ABI bug, clean up and robustify sched_read_attr() ABI logic and code") changed the semantics of sched_getattr(2) when the userspace struct is smaller than the kernel struct. Now, any trailing non-zero data in the kernel structure is ignored when copying to userspace. We also document the original error code correctly (it was EFBIG not E2BIG) in the BUGS section.

Ref: 1251201c0d34 ("sched/core: Fix uclamp ABI bug, clean up and
robustify sched_read_attr() ABI logic and code")

---
 man2/sched_setattr.2 | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
man2/sched_setattr.2 +12 -4
index 2592a761a086..da0972a6a86d 100644
@@ -286,10 +286,8 @@ structure,
 the additional bytes in the user-space structure are not touched.
 If the caller-provided structure is smaller than the kernel
 .I sched_attr
-structure and the kernel needs to return values outside the provided space,
-.BR sched_getattr ()
-fails with the error
-.BR E2BIG .
+structure, the kernel will silently not return any values which would be stored
+outside the provided space.
 As with
 .BR sched_setattr (),
 these semantics allow for future extensibility of the interface.
@@ -416,6 +414,16 @@ failed with the error
 instead of
 .BR E2BIG
 for the case described in ERRORS.
+.PP
+In Linux versions up to 5.3,
+.BR sched_getattr ()
+failed with the error
+.BR EFBIG
+if the in-kernel
+.IR sched_attr
+structure was larger than the
+.IR size
+passed by user space.
 .\" In Linux versions up to up 3.15,
 .\" FIXME . patch from Peter Zijlstra pending
 .\" .BR sched_setattr ()
Signature · 1 line
2.28.0
#6 lore raw

PATCH 2/2 openat2.2: fix minor reference typo

---
 man2/openat2.2 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
man2/openat2.2 +1 -1
index 29b716d97ac4..53056ee6d292 100644
@@ -493,7 +493,7 @@ acting as an implicit version number.
 (Because new extension fields will always
 be appended, the structure size will always increase.)
 This extensibility design is very similar to other system calls such as
-.BR perf_setattr (2),
+.BR sched_setattr (2),
 .BR perf_event_open (2),
 and
 .BR clone3 (2).
Signature · 1 line
2.28.0
#7 lore raw

Re: [PATCH 2/2] openat2.2: fix minor reference typo

Quoted 1 line · Aleksa Sarai

Thanks, Aleksa. Patch applied.

Cheers,

Michael

Quoted 18 lines
---
 man2/openat2.2 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
man2/openat2.2 +1 -1
index 29b716d97ac4..53056ee6d292 100644
@@ -493,7 +493,7 @@ acting as an implicit version number.
 (Because new extension fields will always
 be appended, the structure size will always increase.)
 This extensibility design is very similar to other system calls such as
-.BR perf_setattr (2),
+.BR sched_setattr (2),
 .BR perf_event_open (2),
 and
 .BR clone3 (2).
Signature · 3 lines
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
#8 lore raw
In reply to Aleksa Sarai
Quoted 7 lines · Aleksa Sarai

Due to a userspace breakage, commit 1251201c0d34 ("sched/core: Fix uclamp ABI bug, clean up and robustify sched_read_attr() ABI logic and code") changed the semantics of sched_getattr(2) when the userspace struct is smaller than the kernel struct. Now, any trailing non-zero data in the kernel structure is ignored when copying to userspace. We also document the original error code correctly (it was EFBIG not E2BIG) in the BUGS section.

Thanks, Aleksa. Patch applied.

Cheers,

Michael

Quoted 42 lines

Ref: 1251201c0d34 ("sched/core: Fix uclamp ABI bug, clean up and
robustify sched_read_attr() ABI logic and code")

---
 man2/sched_setattr.2 | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
man2/sched_setattr.2 +12 -4
index 2592a761a086..da0972a6a86d 100644
@@ -286,10 +286,8 @@ structure,
 the additional bytes in the user-space structure are not touched.
 If the caller-provided structure is smaller than the kernel
 .I sched_attr
-structure and the kernel needs to return values outside the provided space,
-.BR sched_getattr ()
-fails with the error
-.BR E2BIG .
+structure, the kernel will silently not return any values which would be stored
+outside the provided space.
 As with
 .BR sched_setattr (),
 these semantics allow for future extensibility of the interface.
@@ -416,6 +414,16 @@ failed with the error
 instead of
 .BR E2BIG
 for the case described in ERRORS.
+.PP
+In Linux versions up to 5.3,
+.BR sched_getattr ()
+failed with the error
+.BR EFBIG
+if the in-kernel
+.IR sched_attr
+structure was larger than the
+.IR size
+passed by user space.
 .\" In Linux versions up to up 3.15,
 .\" FIXME . patch from Peter Zijlstra pending
 .\" .BR sched_setattr ()
Signature · 3 lines
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/