gettimeofday((void *)-1, NULL) implicates core dump on recent FreeBSD 11-CURRENT

Garrett Wollman wollman at hergotha.csail.mit.edu
Tue Jul 7 22:41:57 UTC 2015


In article
<CAPQ4ffuTcN_ytcH7GPY0s6OqWK9qo6MGaVZhOB+0ojWfd=fNCg at mail.gmail.com>
oliver.pinter at hardenedbsd.org writes:

>We discovered that one of the kyua test failing from gettimeofday tests.
>The error is reproducible on recent snapshot from 11-CURRENT:
>ftp://ftp.freebsd.org/pub/FreeBSD/snapshots/amd64/amd64/ISO-IMAGES/11.0/FreeBSD-11.0-CURRENT-amd64-20150630-r284969-disc1.iso
>
>root at freebsd:~ # cat test-gtod.c
>#include <sys/time.h>
>#include <stdio.h>
>
>int
>main(int argc, char **argv)
>{
>
>        return (gettimeofday((void *)-1, NULL));
>}

Undefined behavior here, so the implementation is allowed to do
literally anything at all.  Certainly there's nothing wrong with it
dumping core here, and the test is erroneous if it expects otherwise.
The first argument to gettimeofday() MUST be a valid pointer to struct
timeval, and the implementation does depend on this.

Perhaps the test was (erroneously) written to assume that
gettimeofday() was a system call, and could therefore detect invalid
pointers and return [EFAULT].  This has not been the case for some
time.  (In HEAD, not since r237434, which is three years ago.)

-GAWollman



More information about the freebsd-current mailing list