public inbox for glibc-bugs@sourceware.org help / color / mirror / Atom feed
From: "bugdal at aerifal dot cx" <sourceware-bugzilla@sourceware.org> To: glibc-bugs@sourceware.org Subject: [Bug libc/16437] New: struct timespec definition is non-conforming on x32 and perhaps other archs Date: Sat, 11 Jan 2014 17:50:00 -0000 [thread overview] Message-ID: <bug-16437-131@http.sourceware.org/bugzilla/> (raw) https://sourceware.org/bugzilla/show_bug.cgi?id=16437 Bug ID: 16437 Summary: struct timespec definition is non-conforming on x32 and perhaps other archs Product: glibc Version: unspecified Status: NEW Severity: normal Priority: P2 Component: libc Assignee: unassigned at sourceware dot org Reporter: bugdal at aerifal dot cx CC: drepper.fsp at gmail dot com glibc's definition of struct timespec is wrong: it's using __syscall_slong_t rather than long. This violates the requirements of both POSIX and C11. See C11 7.27.1 Components of time, paragraph 4: "The range and precision of times representable in clock_t and time_t are implementation-defined. The timespec structure shall contain at least the following members, in any order. time_t tv_sec; // whole seconds -- >= 0 long tv_nsec; // nanoseconds -- [0, 999999999]" This breaks conforming code such as: struct timespec ts; sscanf("42", "%ld", &ts.tv_nsec); on targets where __syscall_slong_t is not simply long. For example, on x32, after the above sscanf call, the upper bits of ts.tv_nsec will still contain junk. This is just one example of the breakage; there are many others. Unfortunately fixing this is difficult because the kernel is broken too; simply correcting the type will result in userspace failing to zero the upper bits, which the kernel will then wrongly read as part of a 64-bit value. kernel/compat.c should be zeroing the upper bits of tv_nsec when reading timespec from userspace. Unless it does so, workaround code is required in userspace to copy timespec to a temp buffer before passing it to the kernel and to sign-extend the temporary copy into the padding bits which the kernel will wrongly interpret as value bits. I'm not sure if other archs (maybe MIPS n32?) are also affected. -- You are receiving this mail because: You are on the CC list for the bug.
next reply other threads:[~2014-01-11 17:50 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2014-01-11 17:50 bugdal at aerifal dot cx [this message] 2014-01-12 0:46 ` [Bug libc/16437] " joseph at codesourcery dot com 2014-01-12 1:21 ` bugdal at aerifal dot cx 2014-02-07 3:25 ` [Bug libc/16437] [x86_64] " jsm28 at gcc dot gnu.org 2014-06-13 9:00 ` fweimer at redhat dot com 2015-02-11 18:30 ` hjl.tools at gmail dot com 2015-08-27 22:20 ` [Bug time/16437] " jsm28 at gcc dot gnu.org 2021-12-10 19:30 ` adhemerval.zanella at linaro dot org 2021-12-10 20:54 ` bugdal at aerifal dot cx 2022-01-26 6:44 ` sam at gentoo dot org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-16437-131@http.sourceware.org/bugzilla/ \ --to=sourceware-bugzilla@sourceware.org \ --cc=glibc-bugs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).