[PATCH 1/2] tests/inject-nf.test: replace getpid with geteuid

Ákos Uzonyi uzonyi.akos at gmail.com
Wed Jun 17 10:34:02 UTC 2020


Since we treat PIDs as signed integers, large values (>=2^31) will
cause overflow when we use printpid.
UIDs are treated as unsigned integers, so geteuid is a good alternative.
(getuid would be problematic, as it does not exists on alpha).
Also, on systems where geteuid32 exists, geteuid returns maximum 16 bit
values, so we have to use geteuid32 in this case.

* tests/inject-nf.c: Replace getpid with geteuid.
[__alpha__]: Remove.
[__NR_geteuid32]: New condition.
* tests/inject-nf.test (SYSCALL): Replace getpid with geteuid,geteuid32.
Remove alpha workaround.
---
 tests/inject-nf.c    | 20 +++++++++-----------
 tests/inject-nf.test |  9 +--------
 2 files changed, 10 insertions(+), 19 deletions(-)

diff --git a/tests/inject-nf.c b/tests/inject-nf.c
index c3774f6c..dc11b87b 100644
--- a/tests/inject-nf.c
+++ b/tests/inject-nf.c
@@ -16,28 +16,26 @@
 
 #include "raw_syscall.h"
 
-#ifdef __alpha__
-/* alpha has no getpid */
-# define SC_NR __NR_getpgrp
-# define SC_NAME "getpgrp"
-# define getpid getpgrp
+#ifdef __NR_geteuid32
+# define SC_NR __NR_geteuid32
+# define SC_NAME "geteuid32"
 #else
-# define SC_NR __NR_getpid
-# define SC_NAME "getpid"
+# define SC_NR __NR_geteuid
+# define SC_NAME "geteuid"
 #endif
 
 #ifdef raw_syscall_0
 # define INVOKE_SC(err) raw_syscall_0(SC_NR, &err)
 #else
-/* No raw_syscall_0, let's use getpid() and hope for the best.  */
-# define INVOKE_SC(err) getpid()
+/* No raw_syscall_0, let's use geteuid() and hope for the best. */
+# define INVOKE_SC(err) geteuid()
 #endif
 
 /*
  * This prototype is intentionally different
  * from the prototype provided by <unistd.h>.
  */
-extern kernel_ulong_t getpid(void);
+extern kernel_ulong_t geteuid(void);
 
 int
 main(int ac, char **av)
@@ -45,7 +43,7 @@ main(int ac, char **av)
 	assert(ac == 1 || ac == 2);
 
 	kernel_ulong_t expected =
-		(ac == 1) ? getpid() : strtoull(av[1], NULL, 0);
+		(ac == 1) ? geteuid() : strtoull(av[1], NULL, 0);
 	kernel_ulong_t err = 0;
 	kernel_ulong_t rc = INVOKE_SC(err);
 
diff --git a/tests/inject-nf.test b/tests/inject-nf.test
index cadb5adb..4b79b194 100755
--- a/tests/inject-nf.test
+++ b/tests/inject-nf.test
@@ -9,14 +9,7 @@
 
 . "${srcdir=.}/scno_tampering.sh"
 
-case "$STRACE_ARCH" in
-alpha)
-	SYSCALL=getpgrp
-	;;
-*)
-	SYSCALL=getpid
-	;;
-esac
+SYSCALL="geteuid,geteuid32"
 
 run_prog
 prog="$args"
-- 
2.27.0



More information about the Strace-devel mailing list