Bug 26814 - glibc 2.32 leaks errno in sched_rr_get_interval fallback Edit
Summary: glibc 2.32 leaks errno in sched_rr_get_interval fallback Edit
Status: RESOLVED NOTABUG
Alias: None
Product: glibc
Classification: Unclassified
Component: time (show other bugs)
Version: 2.32
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-10-29 20:02 UTC by Balint Reczey
Modified: 2020-10-30 12:20 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Balint Reczey 2020-10-29 20:02:02 UTC
When sched_rr_get_interval_time64 is not implemented glibc falls back to sched_rr_get_interval syscall but does not clear errno.

This breaks 'unhide quick' and a few other unhide commands giving false positives as a result.

The problem is observed only on armhf in Ubuntu CI.

https://bugs.launchpad.net/ubuntu/+source/glibc/+bug/1896281


test.c:
#include <stdio.h>
#include <errno.h>
#include <sched.h>
int main() {
  struct timespec tp;
  errno = 0;
  sched_rr_get_interval(1, &tp);
  perror("error");
  return 0;
}

strace ./a.out
...
sched_rr_get_interval_time64(1, 0xfff88678) = -1 ENOSYS (Function not implemented)
sched_rr_get_interval(1, {tv_sec=0, tv_nsec=0}) = 0
dup(2) = 3
fcntl64(3, F_GETFL) = 0x402 (flags O_RDWR|O_APPEND)
brk(NULL) = 0x1942000
brk(0x1963000) = 0x1963000
fstat64(3, {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0x3), ...}) = 0
write(3, "error: Function not implemented\n", 32error: Function not implemented
) = 32
...

...
Comment 1 Andreas Schwab 2020-10-29 20:07:41 UTC
errno is only defined if sched_rr_get_interval returns -1.
Comment 2 Balint Reczey 2020-10-29 20:35:09 UTC
root@gg-armhf:~# cat test.c 
#include <stdio.h>
#include <errno.h>
#include <sched.h>
int main() {
  struct timespec tp;
  errno = 0;
  int ret = sched_rr_get_interval(1, &tp);
  printf("ret == %d\n", ret);
  perror("error");
  return 0;
}
root@gg-armhf:~# ./a.out 
ret == 0
error: Function not implemented
root@gg-armhf:~#
Comment 3 Adhemerval Zanella 2020-10-30 12:20:49 UTC
I think this is similar (In reply to Balint Reczey from comment #2)
> root@gg-armhf:~# cat test.c 
> #include <stdio.h>
> #include <errno.h>
> #include <sched.h>
> int main() {
>   struct timespec tp;
>   errno = 0;
>   int ret = sched_rr_get_interval(1, &tp);
>   printf("ret == %d\n", ret);
>   perror("error");
>   return 0;
> }
> root@gg-armhf:~# ./a.out 
> ret == 0
> error: Function not implemented
> root@gg-armhf:~#

The errno value after a successful call does not give you any meaningful information.  But I think this is similar to the recent stat y2038 support where it triggered some invalid used within glibc itself.  I think it would be better to use INTERNAL_SYSCALL_CALL in such cases and only sets the errno in case of failure.