This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

bug in times.c


Hi all,
we are using the glibc 2.13 on a ARM architecture with linux 3.0.40, but the
problem should also be present in the latest glibc.

The attached program terminate with a SEGFAULT. The problem occurs when the
system call return a counter value that is equal to -EFAULT.
In this case a touch of the buffer is done even if the *buf is NULL.

In our setup this happens always 5 minutes after kernel start-up.
In other setup this can happen after >200 days.

times() works correctly if a buffer is provided.

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


int main(int argc, char *argv[])
{
    struct timespec     time_wait;
    struct tms          tms_now;
    clock_t             times_now;

    time_wait.tv_sec  = 0;
    time_wait.tv_nsec = 5*1000*1000;

    times_now = times (NULL);
    printf("times_now=0x%08lx\n", times_now);

    while (1)
    {
        times_now = times (NULL);
        nanosleep (&time_wait, NULL);
    }
   return 0;
}

We think we already found the bug in glibc, but we can't doublecheck this
because we don't have an infrastrucuture to recompile the glibc.

Here is the diff to the current glibc git tree for the proposed solution:

diff --git a/sysdeps/unix/sysv/linux/times.c b/sysdeps/unix/sysv/linux/times.c
index f3b5f01..ba20e5b 100644
--- a/sysdeps/unix/sysv/linux/times.c
+++ b/sysdeps/unix/sysv/linux/times.c
@@ -39,11 +39,12 @@ __times (struct tms *buf)
        asm volatile ("" : "+r" (temp));                                      \
        v = temp;                                                             \
       } while (0)
-      touch (buf->tms_utime);
-      touch (buf->tms_stime);
-      touch (buf->tms_cutime);
-      touch (buf->tms_cstime);
-
+      if (buf != NULL) {
+        touch (buf->tms_utime);
+        touch (buf->tms_stime);
+        touch (buf->tms_cutime);
+        touch (buf->tms_cstime);
+      }
       /* If we come here the memory is valid and the kernel did not
         return an EFAULT error.  Return the value given by the kernel.  */
     }

Any comments on this? should I send a regular git patch?

Regards
Holger


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]