[RFC] removing __NR_clock_gettime / SYS_clock_gettime

Submitted by Rich Felker on Jan. 21, 2020, 6:49 p.m.

Details

Message ID 20200121184950.GT30412@brightrain.aerifal.cx
State New
Series "removing __NR_clock_gettime / SYS_clock_gettime"
Headers show

Commit Message

Rich Felker Jan. 21, 2020, 6:49 p.m.
On Sun, Jan 19, 2020 at 11:36:16AM -0500, Rich Felker wrote:
> Today we discovered that libstdc++ std::chrono is broken because it's
> making direct syscalls to SYS_clock_gettime to work around glibc
> putting clock_gettime in librt. This is exactly the same issue as
> busybox https://bugs.busybox.net/show_bug.cgi?id=12091 and I would not
> be surprised if it exists in more software. It's a silent bug that's
> easy to find and fix if you know what to look for, but very confusing
> and hard to find if you don't, and it can easily slip into software
> that's not well-tested on time64.
> 
> What I'd like to propose doing is removing __NR_clock_gettime and
> SYS_clock_gettime from the public sys/syscall.h (via bits headers) on
> 32-bit archs, and moving SYS_clock_gettime to
> arch/$(ARCH)/syscall_arch.h for musl-internal use. This would make it
> a hard compile-time error for any software attempting to use the
> syscall directly, and in the case of libstdc++ I think it would even
> fix the problem without patching gcc, since they have a configure
> check for the syscall.
> 
> Thoughts? Is this too big a hammer?

Patch attached.

Rich

Patch hide | download patch | download mbox

diff --git a/arch/arm/bits/syscall.h.in b/arch/arm/bits/syscall.h.in
index 8ab5df1d..4d844e57 100644
--- a/arch/arm/bits/syscall.h.in
+++ b/arch/arm/bits/syscall.h.in
@@ -55,7 +55,7 @@ 
 #define __NR_sethostname	74
 #define __NR_setrlimit	75
 #define __NR_getrusage	77
-#define __NR_gettimeofday	78
+#define __NR_gettimeofday_time32	78
 #define __NR_settimeofday	79
 #define __NR_getgroups	80
 #define __NR_setgroups	81
@@ -216,7 +216,7 @@ 
 #define __NR_timer_getoverrun	260
 #define __NR_timer_delete	261
 #define __NR_clock_settime	262
-#define __NR_clock_gettime	263
+#define __NR_clock_gettime32	263
 #define __NR_clock_getres	264
 #define __NR_clock_nanosleep	265
 #define __NR_statfs64	266
diff --git a/arch/i386/bits/syscall.h.in b/arch/i386/bits/syscall.h.in
index bb841677..a96317c0 100644
--- a/arch/i386/bits/syscall.h.in
+++ b/arch/i386/bits/syscall.h.in
@@ -76,7 +76,7 @@ 
 #define __NR_setrlimit		 75
 #define __NR_getrlimit		 76   /* Back compatible 2Gig limited rlimit */
 #define __NR_getrusage		 77
-#define __NR_gettimeofday	 78
+#define __NR_gettimeofday_time32	 78
 #define __NR_settimeofday	 79
 #define __NR_getgroups		 80
 #define __NR_setgroups		 81
@@ -262,7 +262,7 @@ 
 #define __NR_timer_getoverrun	(__NR_timer_create+3)
 #define __NR_timer_delete	(__NR_timer_create+4)
 #define __NR_clock_settime	(__NR_timer_create+5)
-#define __NR_clock_gettime	(__NR_timer_create+6)
+#define __NR_clock_gettime32	(__NR_timer_create+6)
 #define __NR_clock_getres	(__NR_timer_create+7)
 #define __NR_clock_nanosleep	(__NR_timer_create+8)
 #define __NR_statfs64		268
diff --git a/arch/m68k/bits/syscall.h.in b/arch/m68k/bits/syscall.h.in
index e7f71a5d..e70d3472 100644
--- a/arch/m68k/bits/syscall.h.in
+++ b/arch/m68k/bits/syscall.h.in
@@ -67,7 +67,7 @@ 
 #define __NR_setrlimit		 75
 #define __NR_getrlimit		 76
 #define __NR_getrusage		 77
-#define __NR_gettimeofday	 78
+#define __NR_gettimeofday_time32	 78
 #define __NR_settimeofday	 79
 #define __NR_getgroups		 80
 #define __NR_setgroups		 81
@@ -240,7 +240,7 @@ 
 #define __NR_timer_getoverrun	257
 #define __NR_timer_delete	258
 #define __NR_clock_settime	259
-#define __NR_clock_gettime	260
+#define __NR_clock_gettime32	260
 #define __NR_clock_getres	261
 #define __NR_clock_nanosleep	262
 #define __NR_statfs64		263
diff --git a/arch/microblaze/bits/syscall.h.in b/arch/microblaze/bits/syscall.h.in
index afefb354..b23fe6ef 100644
--- a/arch/microblaze/bits/syscall.h.in
+++ b/arch/microblaze/bits/syscall.h.in
@@ -76,7 +76,7 @@ 
 #define __NR_setrlimit 75
 #define __NR_getrlimit 76
 #define __NR_getrusage 77
-#define __NR_gettimeofday 78
+#define __NR_gettimeofday_time32 78
 #define __NR_settimeofday 79
 #define __NR_getgroups 80
 #define __NR_setgroups 81
@@ -260,7 +260,7 @@ 
 #define __NR_timer_getoverrun 262
 #define __NR_timer_delete 263
 #define __NR_clock_settime 264
-#define __NR_clock_gettime 265
+#define __NR_clock_gettime32 265
 #define __NR_clock_getres 266
 #define __NR_clock_nanosleep 267
 #define __NR_statfs64 268
diff --git a/arch/mips/bits/syscall.h.in b/arch/mips/bits/syscall.h.in
index 7f9afaab..e3f2de31 100644
--- a/arch/mips/bits/syscall.h.in
+++ b/arch/mips/bits/syscall.h.in
@@ -76,7 +76,7 @@ 
 #define __NR_setrlimit               4075
 #define __NR_getrlimit               4076
 #define __NR_getrusage               4077
-#define __NR_gettimeofday            4078
+#define __NR_gettimeofday_time32            4078
 #define __NR_settimeofday            4079
 #define __NR_getgroups               4080
 #define __NR_setgroups               4081
@@ -261,7 +261,7 @@ 
 #define __NR_timer_getoverrun        4260
 #define __NR_timer_delete            4261
 #define __NR_clock_settime           4262
-#define __NR_clock_gettime           4263
+#define __NR_clock_gettime32           4263
 #define __NR_clock_getres            4264
 #define __NR_clock_nanosleep         4265
 #define __NR_tgkill                  4266
diff --git a/arch/mipsn32/bits/syscall.h.in b/arch/mipsn32/bits/syscall.h.in
index 134a4f81..d13fda12 100644
--- a/arch/mipsn32/bits/syscall.h.in
+++ b/arch/mipsn32/bits/syscall.h.in
@@ -92,7 +92,7 @@ 
 #define __NR_fchown			6091
 #define __NR_lchown			6092
 #define __NR_umask			6093
-#define __NR_gettimeofday		6094
+#define __NR_gettimeofday_time32		6094
 #define __NR_getrlimit			6095
 #define __NR_getrusage			6096
 #define __NR_sysinfo			6097
@@ -224,7 +224,7 @@ 
 #define __NR_timer_getoverrun		6223
 #define __NR_timer_delete		6224
 #define __NR_clock_settime		6225
-#define __NR_clock_gettime		6226
+#define __NR_clock_gettime32		6226
 #define __NR_clock_getres		6227
 #define __NR_clock_nanosleep		6228
 #define __NR_tgkill			6229
diff --git a/arch/or1k/bits/syscall.h.in b/arch/or1k/bits/syscall.h.in
index eaa1a935..82d94b29 100644
--- a/arch/or1k/bits/syscall.h.in
+++ b/arch/or1k/bits/syscall.h.in
@@ -112,7 +112,7 @@ 
 #define __NR_timer_settime 110
 #define __NR_timer_delete 111
 #define __NR_clock_settime 112
-#define __NR_clock_gettime 113
+#define __NR_clock_gettime32 113
 #define __NR_clock_getres 114
 #define __NR_clock_nanosleep 115
 #define __NR_syslog 116
@@ -168,7 +168,7 @@ 
 #define __NR_umask 166
 #define __NR_prctl 167
 #define __NR_getcpu 168
-#define __NR_gettimeofday 169
+#define __NR_gettimeofday_time32 169
 #define __NR_settimeofday 170
 #define __NR_adjtimex 171
 #define __NR_getpid 172
diff --git a/arch/powerpc/bits/syscall.h.in b/arch/powerpc/bits/syscall.h.in
index d8b6a247..14cf79c6 100644
--- a/arch/powerpc/bits/syscall.h.in
+++ b/arch/powerpc/bits/syscall.h.in
@@ -76,7 +76,7 @@ 
 #define __NR_setrlimit               75
 #define __NR_getrlimit               76
 #define __NR_getrusage               77
-#define __NR_gettimeofday            78
+#define __NR_gettimeofday_time32            78
 #define __NR_settimeofday            79
 #define __NR_getgroups               80
 #define __NR_setgroups               81
@@ -243,7 +243,7 @@ 
 #define __NR_timer_getoverrun       243
 #define __NR_timer_delete           244
 #define __NR_clock_settime          245
-#define __NR_clock_gettime          246
+#define __NR_clock_gettime32          246
 #define __NR_clock_getres           247
 #define __NR_clock_nanosleep        248
 #define __NR_swapcontext            249
diff --git a/arch/sh/bits/syscall.h.in b/arch/sh/bits/syscall.h.in
index 4e9ae2e0..5c24f4a6 100644
--- a/arch/sh/bits/syscall.h.in
+++ b/arch/sh/bits/syscall.h.in
@@ -67,7 +67,7 @@ 
 #define __NR_setrlimit              75
 #define __NR_getrlimit              76
 #define __NR_getrusage              77
-#define __NR_gettimeofday           78
+#define __NR_gettimeofday_time32           78
 #define __NR_settimeofday           79
 #define __NR_getgroups              80
 #define __NR_setgroups              81
@@ -236,7 +236,7 @@ 
 #define __NR_timer_getoverrun       262
 #define __NR_timer_delete           263
 #define __NR_clock_settime          264
-#define __NR_clock_gettime          265
+#define __NR_clock_gettime32          265
 #define __NR_clock_getres           266
 #define __NR_clock_nanosleep        267
 #define __NR_statfs64               268
diff --git a/src/internal/syscall.h b/src/internal/syscall.h
index d768fb64..0b61f34e 100644
--- a/src/internal/syscall.h
+++ b/src/internal/syscall.h
@@ -193,6 +193,13 @@  hidden long __syscall_ret(unsigned long),
 #define SYS_sendfile SYS_sendfile64
 #endif
 
+#ifndef SYS_clock_gettime
+#define SYS_clock_gettime SYS_clock_gettime32
+#endif
+
+#ifndef SYS_gettimeofday
+#define SYS_gettimeofday SYS_gettimeofday_time32
+#endif
 
 /* Ensure that the plain syscall names are defined even for "time64-only"
  * archs. These facilitate callers passing null time arguments, and make