Skip to contentSkip to conversation

syscalls: Check for time64 unsafe syscalls before using them

PATCH Superseded Khem Raj 2 participants 2 messages Feb 20, 2020 Library code

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Khem Raj

author
#0 lore raw

PATCH v2 1/1 syscalls: Check for time64 unsafe syscalls before using them

musl is using 64bit time_t now on 32bit architectures and these syscalls no longer exist, therefore its better to check for them being available before using them

---
 lib/tst_clocks.c                                        | 9 +++++----
 testcases/kernel/syscalls/gettimeofday/gettimeofday01.c | 6 ++----
 testcases/kernel/syscalls/gettimeofday/gettimeofday02.c | 8 +++-----
 3 files changed, 10 insertions(+), 13 deletions(-)
lib/tst_clocks.c +5 -4
index 5195da38f3..f4f8b2846b 100644
@@ -10,21 +10,22 @@
 #define _GNU_SOURCE
 #include <unistd.h>
 #include <time.h>
-#include <sys/syscall.h>
 
+#include "test.h"
 #include "tst_clocks.h"
+#include "lapi/syscalls.h"
 
 int tst_clock_getres(clockid_t clk_id, struct timespec *res)
 {
-	return syscall(SYS_clock_getres, clk_id, res);
+	return ltp_syscall(__NR_clock_getres, clk_id, res);
 }
 
 int tst_clock_gettime(clockid_t clk_id, struct timespec *ts)
 {
-	return syscall(SYS_clock_gettime, clk_id, ts);
+	return ltp_syscall(__NR_clock_gettime, clk_id, ts);
 }
 
 int tst_clock_settime(clockid_t clk_id, struct timespec *ts)
 {
-	return syscall(SYS_clock_settime, clk_id, ts);
+	return ltp_syscall(__NR_clock_settime, clk_id, ts);
 }
testcases/kernel/syscalls/gettimeofday/gettimeofday01.c +2 -4
index 583d8f7b9b..08ea1673ad 100644
@@ -38,10 +38,8 @@
 #include <sys/time.h>
 #include <errno.h>
 #include "test.h"
-#include <sys/syscall.h>
 #include <unistd.h>
-
-#define gettimeofday(a,b)  syscall(__NR_gettimeofday,a,b)
+#include "lapi/syscalls.h"
 
 char *TCID = "gettimeofday01";
 int TST_TOTAL = 1;
@@ -63,7 +61,7 @@ int main(int ac, char **av)
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		tst_count = 0;
 
-		TEST(gettimeofday((void *)-1, (void *)-1));
+		TEST(ltp_syscall(__NR_gettimeofday, (void *)-1, (void *)-1));
 
 		/* gettimeofday returns an int, so we need to turn the long
 		 * TEST_RETURN into an int to test with */
testcases/kernel/syscalls/gettimeofday/gettimeofday02.c +3 -5
index 1d60f448e8..5170ad2f78 100644
@@ -16,14 +16,12 @@
 #include <stdint.h>
 #include <sys/time.h>
 #include <stdlib.h>
-#include <sys/syscall.h>
 #include <unistd.h>
 #include <time.h>
 #include <errno.h>
 
 #include "tst_test.h"
-
-#define gettimeofday(a,b)  syscall(__NR_gettimeofday,a,b)
+#include "lapi/syscalls.h"
 
 static volatile sig_atomic_t done;
 static char *str_rtime;
@@ -48,13 +46,13 @@ static void verify_gettimeofday(void)
 
 	alarm(rtime);
 
-	if (gettimeofday(&tv1, NULL)) {
+	if (tst_syscall(__NR_gettimeofday, &tv1, NULL)) {
 		tst_res(TBROK | TERRNO, "gettimeofday() failed");
 		return;
 	}
 
 	while (!done) {
-		if (gettimeofday(&tv2, NULL)) {
+		if (tst_syscall(__NR_gettimeofday, &tv2, NULL)) {
 			tst_res(TBROK | TERRNO, "gettimeofday() failed");
 			return;
 		}
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/1 syscalls: Check for time64 unsafe syscalls before using them

Hi Khem

Quoted 19 lines

musl is using 64bit time_t now on 32bit architectures and these syscalls no longer exist, therefore its better to check for them being available before using them

---
  lib/tst_clocks.c                                        | 9 +++++----
  testcases/kernel/syscalls/gettimeofday/gettimeofday01.c | 6 ++----
  testcases/kernel/syscalls/gettimeofday/gettimeofday02.c | 8 +++-----
  3 files changed, 10 insertions(+), 13 deletions(-)
lib/tst_clocks.c +0 -0
index 5195da38f3..f4f8b2846b 100644
@@ -10,21 +10,22 @@
  #define _GNU_SOURCE
  #include <unistd.h>
  #include <time.h>

lib/tst_clocks.c line 20

Quoted 10 lines
lib/tst_clocks.c +3 -2
-#include <sys/syscall.h>
 
+#include "test.h"
  #include "tst_clocks.h"
+#include "lapi/syscalls.h"
 
  int tst_clock_getres(clockid_t clk_id, struct timespec *res)
  {
-	return syscall(SYS_clock_getres, clk_id, res);
+	return ltp_syscall(__NR_clock_getres, clk_id, res);

It should use new api, include "tst_test.h" and use tst_syscall. It doesn't like gettimeofday01.c.

Quoted 30 lines
lib/tst_clocks.c +2 -2
  }
 
  int tst_clock_gettime(clockid_t clk_id, struct timespec *ts)
  {
-	return syscall(SYS_clock_gettime, clk_id, ts);
+	return ltp_syscall(__NR_clock_gettime, clk_id, ts);
  }
 
  int tst_clock_settime(clockid_t clk_id, struct timespec *ts)
  {
-	return syscall(SYS_clock_settime, clk_id, ts);
+	return ltp_syscall(__NR_clock_settime, clk_id, ts);
  }
testcases/kernel/syscalls/gettimeofday/gettimeofday01.c +1 -3
index 583d8f7b9b..08ea1673ad 100644
@@ -38,10 +38,8 @@
  #include <sys/time.h>
  #include <errno.h>
  #include "test.h"
-#include <sys/syscall.h>
  #include <unistd.h>
-
-#define gettimeofday(a,b)  syscall(__NR_gettimeofday,a,b)
+#include "lapi/syscalls.h"
 
  char *TCID = "gettimeofday01";
  int TST_TOTAL = 1;

testcases/kernel/syscalls/gettimeofday/gettimeofday01.c int main(int ac, char **av) · line 64

Quoted 5 lines
testcases/kernel/syscalls/gettimeofday/gettimeofday01.c +1 -1
@@ -63,7 +61,7 @@ int main(int ac, char **av)
  	for (lc = 0; TEST_LOOPING(lc); lc++) {
  		tst_count = 0;
 
-		TEST(gettimeofday((void *)-1, (void *)-1));
+		TEST(ltp_syscall(__NR_gettimeofday, (void *)-1, (void *)-1));

In future, we can convert this case into new api and use tst_syscall.

Quoted 30 lines
testcases/kernel/syscalls/gettimeofday/gettimeofday01.c +0 -0
  		/* gettimeofday returns an int, so we need to turn the long
  		 * TEST_RETURN into an int to test with */
testcases/kernel/syscalls/gettimeofday/gettimeofday02.c +2 -4
index 1d60f448e8..5170ad2f78 100644
@@ -16,14 +16,12 @@
  #include <stdint.h>
  #include <sys/time.h>
  #include <stdlib.h>
-#include <sys/syscall.h>
  #include <unistd.h>
  #include <time.h>
  #include <errno.h>
 
  #include "tst_test.h"
-
-#define gettimeofday(a,b)  syscall(__NR_gettimeofday,a,b)
+#include "lapi/syscalls.h"
 
  static volatile sig_atomic_t done;
  static char *str_rtime;
@@ -48,13 +46,13 @@ static void verify_gettimeofday(void)
 
  	alarm(rtime);
 
-	if (gettimeofday(&tv1, NULL)) {
+	if (tst_syscall(__NR_gettimeofday, &tv1, NULL)) {

testcases/kernel/syscalls/gettimeofday/gettimeofday02.c static void verify_gettimeofday(void) · line 58

Quoted 10 lines
testcases/kernel/syscalls/gettimeofday/gettimeofday02.c +1 -1
  		tst_res(TBROK | TERRNO, "gettimeofday() failed");
  		return;
  	}
 
  	while (!done) {
-		if (gettimeofday(&tv2, NULL)) {
+		if (tst_syscall(__NR_gettimeofday, &tv2, NULL)) {
  			tst_res(TBROK | TERRNO, "gettimeofday() failed");
  			return;
  		}

other than, this patch looks good to me.