|
|
Message-ID: <20261030200457.239804-1-alex@alexrp.com>
Date: Fri, 30 Oct 2026 21:04:57 +0100
From: Alex Rønne Petersen <alex@...xrp.com>
To: musl@...ts.openwall.com
Cc: Alex Rønne Petersen <alex@...xrp.com>
Subject: [PATCH] x32: add times() implementation that avoids buffer overrun
As a general rule, clock_t is a long, but the x32 kABI is the singular
exception where it's a long long. musl always makes clock_t a long, even
on x32, which means that musl expected the kernel to write 16 bytes into
the tms buffer given to times(), but it would actually write 32 bytes.
Rather than change clock_t, this commit fixes the bug by narrowing each
value from an appropriately-sized array in the times() implementation.
---
src/time/x32/times.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
create mode 100644 src/time/x32/times.c
diff --git a/src/time/x32/times.c b/src/time/x32/times.c
new file mode 100644
index 00000000..fcdd4e46
--- /dev/null
+++ b/src/time/x32/times.c
@@ -0,0 +1,15 @@
+#include <sys/times.h>
+#include "syscall.h"
+
+clock_t times(struct tms *tms)
+{
+ long long ktms[4];
+ clock_t r = __syscall(SYS_times, ktms);
+ if (tms) {
+ tms->tms_utime = ktms[0];
+ tms->tms_stime = ktms[1];
+ tms->tms_cutime = ktms[2];
+ tms->tms_cstime = ktms[3];
+ }
+ return r;
+}
--
2.53.0
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.