FBSD 5.5 broke nanosleep in libc_r

Michael Scheidell scheidell at secnap.net
Tue Jul 25 19:58:40 UTC 2006

>Submitter-Id:	current-users
>Originator:	Michael Scheidel
>Organization:	SECNAP Network Security
>Synopsis:	FBSD 5.5 broke nanosleep in libc_r
>Severity:	serious
>Priority:	medium
>Category:	threads
>Class:		sw-bug
>Release:	FreeBSD 5.5-RELEASE-p2 i386
System: FreeBSD audit18.hackertrap.net 5.5-RELEASE-p2 FreeBSD 5.5-RELEASE-p2 #6: Tue Jul 25 10:34:16 EDT 2006     admin at audit18.hackertrap.net:/usr/obj/usr/src/sys/HACKERTRAP_305  i386

	nanosleep returns after time+delta if wallclock changed with libc_r
        5.4 works, not including libc_r in 5.5 works
        Given this POC:
        int main( int argc, char **argv )
char execs1[256] = "/bin/date +A%Y%m%d%H%M.%S";
char execs2[256] = "/bin/date +B%Y%m%d%H%M.%S";
int a;
  while ( 1) {
    system( execs1 );
     usleep( 500*1000);
    system( execs2 );

  return 0;
}  /* main */

compile with: 
cc -g  -c nanotest.c
cc -g  -o nanotest nanotest.o -lc_r

run it, set clock back 45 seconds, observe 45 second delay

compile with:
cc -g  -c nanotest.c
cc -g  -o nanotest nanotest.o

or compile on 5.4 system.
(I have only tried compiling and running on 5.4 system.
I have not yet tried compiling on 5.4 and running on 5.5 or visa versa)

I used ntpdate -su to change clock.
(I have an internal system that is 45 seconds behind, just for this test)

output with 5.4 or without libc_r
shows wallclock 'stepping' when you change time
no delay in display.

5.5 with libc_r shows stepping if moving clock head, but if you move
wallclock back 45 seconds, display stops for 45 seconds.

More information about the freebsd-hackers mailing list