Bug 187808

Summary: Pointer validation gone missing for __vdso_gettimeofday()
Product: Base System Reporter: Peter Holm <pho>
Component: amd64Assignee: freebsd-amd64 (Nobody) <amd64>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   

Description Peter Holm freebsd_committer freebsd_triage 2014-03-21 09:30:00 UTC
If first argument to gettimeofday() is an invalid pointer the call does not return EFAULT.

How-To-Repeat: $ cat -n gettimeofday.c
     1  #include <err.h>
     2  #include <stdio.h>
     3  #include <sys/time.h>
     4  #include <sys/syscall.h>
     5  #include <unistd.h>
     6
     7  int
     8  main(void)
     9  {
    10          if (syscall(SYS_gettimeofday, (void *)-1, NULL) == -1)
    11                  warn("syscall()");
    12
    13          /* broken by r237434 */
    14          if (gettimeofday((void *)-1, NULL) == -1)
    15                  warn("gettimeofday()");
    16
    17          return (0);
    18  }
$ cc -o gettimeofday -Wall -Wextra -O2 -g gettimeofday.c
$ ./gettimeofday                                        
gettimeofday: syscall(): Bad address
Segmentation fault (core dumped)
$
Comment 1 Kostik Belousov 2014-03-21 12:30:44 UTC
Nothing in the SUSvX requires the pointer to the struct timeval to be
validated, or rather, if pointer is not valid, the behaviour is undefined.

It is impossible to 'fix' this in reliable manner for userspace function.
The expectations are the same as for other functions, e.g. strcmp(3).
Comment 2 Peter Holm 2014-03-21 12:56:46 UTC
Thank you for the explanation.

- Peter
Comment 3 Peter Holm freebsd_committer freebsd_triage 2014-03-22 05:56:31 UTC
State Changed
From-To: open->closed

Issue nicely explained by kib@.