Commit 2f65dd47 authored by John Wright's avatar John Wright Committed by Ingo Molnar

x86: gettimeofday() vDSO: fix segfault when tv == NULL

According to the gettimeofday(2) manual:

       If either tv or tz is NULL, the corresponding structure is not
       set or returned.

Since it is legal to give NULL as the tv argument, the code should make
sure tv is not NULL before trying to dereference it.

This issue manifests itself on x86_64 when vdso=0 is not on the kernel
command-line and libc uses the vDSO for gettimeofday() (e.g. glibc >=
2.7).  A simple reproducer:

  #include <stdio.h>
  #include <sys/time.h>

  int main(void)
  {
      struct timezone tz;

      gettimeofday(NULL, &tz);

      return 0;
  }

See http://bugs.debian.org/466491 for more details.

[ Impact: fix gettimeofday(NULL, &tz) segfault ]
Signed-off-by: default avatarJohn Wright <john.wright@hp.com>
Cc: Andi Kleen <ak@suse.de>
Cc: John Wright <john.wright@hp.com>
LKML-Reference: <1241037121-14805-1-git-send-email-john.wright@hp.com>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 091438dd
...@@ -104,11 +104,13 @@ notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz) ...@@ -104,11 +104,13 @@ notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
{ {
long ret; long ret;
if (likely(gtod->sysctl_enabled && gtod->clock.vread)) { if (likely(gtod->sysctl_enabled && gtod->clock.vread)) {
BUILD_BUG_ON(offsetof(struct timeval, tv_usec) != if (likely(tv != NULL)) {
offsetof(struct timespec, tv_nsec) || BUILD_BUG_ON(offsetof(struct timeval, tv_usec) !=
sizeof(*tv) != sizeof(struct timespec)); offsetof(struct timespec, tv_nsec) ||
do_realtime((struct timespec *)tv); sizeof(*tv) != sizeof(struct timespec));
tv->tv_usec /= 1000; do_realtime((struct timespec *)tv);
tv->tv_usec /= 1000;
}
if (unlikely(tz != NULL)) { if (unlikely(tz != NULL)) {
/* Avoid memcpy. Some old compilers fail to inline it */ /* Avoid memcpy. Some old compilers fail to inline it */
tz->tz_minuteswest = gtod->sys_tz.tz_minuteswest; tz->tz_minuteswest = gtod->sys_tz.tz_minuteswest;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment