Blame SOURCES/0122-tests-inject-nf.test-replace-getpid-with-geteuid.patch

760e82
From c5be5bb949988c262012e7f4763b1d658c1769b9 Mon Sep 17 00:00:00 2001
760e82
From: =?UTF-8?q?=C3=81kos=20Uzonyi?= <uzonyi.akos@gmail.com>
760e82
Date: Fri, 19 Jun 2020 12:06:42 +0200
760e82
Subject: [PATCH 122/138] tests/inject-nf.test: replace getpid with geteuid
760e82
760e82
Since we treat PIDs as signed integers, large values (>=2^31) will
760e82
cause overflow when we use printpid.
760e82
UIDs are treated as unsigned integers, so geteuid is a good alternative.
760e82
(getuid would be problematic, as it does not exists on alpha).
760e82
Also, on systems where geteuid32 exists, geteuid returns maximum 16 bit
760e82
values, so we have to use geteuid32 in this case.
760e82
760e82
[ldv: geteuid syscall was introduced on Alpha by Linux kernel commit
760e82
v5.1-rc1~160^2~3^2~1, so this test will not work on old Alpha kernels.]
760e82
760e82
* tests/inject-nf.c: Replace getpid with either geteuid32 or geteuid.
760e82
[__alpha__]: Remove.
760e82
[__NR_geteuid32]: New condition.
760e82
* tests/inject-nf.test (SYSCALL): Replace getpid with '/^geteuid(32)?$'.
760e82
Remove alpha workaround.
760e82
---
760e82
 tests/inject-nf.c    | 20 +++++++++-----------
760e82
 tests/inject-nf.test |  9 +--------
760e82
 2 files changed, 10 insertions(+), 19 deletions(-)
760e82
760e82
Index: strace-5.7/tests/inject-nf.c
760e82
===================================================================
760e82
--- strace-5.7.orig/tests/inject-nf.c	2020-09-09 14:50:44.159739392 +0200
760e82
+++ strace-5.7/tests/inject-nf.c	2020-09-09 14:56:17.193937896 +0200
760e82
@@ -16,28 +16,26 @@
760e82
 
760e82
 #include "raw_syscall.h"
760e82
 
760e82
-#ifdef __alpha__
760e82
-/* alpha has no getpid */
760e82
-# define SC_NR __NR_getpgrp
760e82
-# define SC_NAME "getpgrp"
760e82
-# define getpid getpgrp
760e82
+#ifdef __NR_geteuid32
760e82
+# define SC_NR __NR_geteuid32
760e82
+# define SC_NAME "geteuid32"
760e82
 #else
760e82
-# define SC_NR __NR_getpid
760e82
-# define SC_NAME "getpid"
760e82
+# define SC_NR __NR_geteuid
760e82
+# define SC_NAME "geteuid"
760e82
 #endif
760e82
 
760e82
 #ifdef raw_syscall_0
760e82
 # define INVOKE_SC(err) raw_syscall_0(SC_NR, &err)
760e82
 #else
760e82
-/* No raw_syscall_0, let's use getpid() and hope for the best.  */
760e82
-# define INVOKE_SC(err) getpid()
760e82
+/* No raw_syscall_0, let's use geteuid() and hope for the best. */
760e82
+# define INVOKE_SC(err) geteuid()
760e82
 #endif
760e82
 
760e82
 /*
760e82
  * This prototype is intentionally different
760e82
  * from the prototype provided by <unistd.h>.
760e82
  */
760e82
-extern kernel_ulong_t getpid(void);
760e82
+extern kernel_ulong_t geteuid(void);
760e82
 
760e82
 int
760e82
 main(int ac, char **av)
760e82
@@ -45,7 +43,7 @@
760e82
 	assert(ac == 1 || ac == 2);
760e82
 
760e82
 	kernel_ulong_t expected =
760e82
-		(ac == 1) ? getpid() : strtoull(av[1], NULL, 0);
760e82
+		(ac == 1) ? geteuid() : strtoull(av[1], NULL, 0);
760e82
 	kernel_ulong_t err = 0;
760e82
 	kernel_ulong_t rc = INVOKE_SC(err);
760e82
 
760e82
Index: strace-5.7/tests/inject-nf.test
760e82
===================================================================
760e82
--- strace-5.7.orig/tests/inject-nf.test	2020-09-09 14:50:44.159739392 +0200
760e82
+++ strace-5.7/tests/inject-nf.test	2020-09-09 14:56:17.194937896 +0200
760e82
@@ -9,14 +9,7 @@
760e82
 
760e82
 . "${srcdir=.}/scno_tampering.sh"
760e82
 
760e82
-case "$STRACE_ARCH" in
760e82
-alpha)
760e82
-	SYSCALL=getpgrp
760e82
-	;;
760e82
-*)
760e82
-	SYSCALL=getpid
760e82
-	;;
760e82
-esac
760e82
+SYSCALL='/^geteuid(32)?$'
760e82
 
760e82
 run_prog
760e82
 prog="$args"
760e82
Index: strace-5.7/tests-m32/inject-nf.c
760e82
===================================================================
760e82
--- strace-5.7.orig/tests-m32/inject-nf.c	2019-09-25 03:02:03.000000000 +0200
760e82
+++ strace-5.7/tests-m32/inject-nf.c	2020-09-09 14:58:03.687001371 +0200
760e82
@@ -16,28 +16,26 @@
760e82
 
760e82
 #include "raw_syscall.h"
760e82
 
760e82
-#ifdef __alpha__
760e82
-/* alpha has no getpid */
760e82
-# define SC_NR __NR_getpgrp
760e82
-# define SC_NAME "getpgrp"
760e82
-# define getpid getpgrp
760e82
+#ifdef __NR_geteuid32
760e82
+# define SC_NR __NR_geteuid32
760e82
+# define SC_NAME "geteuid32"
760e82
 #else
760e82
-# define SC_NR __NR_getpid
760e82
-# define SC_NAME "getpid"
760e82
+# define SC_NR __NR_geteuid
760e82
+# define SC_NAME "geteuid"
760e82
 #endif
760e82
 
760e82
 #ifdef raw_syscall_0
760e82
 # define INVOKE_SC(err) raw_syscall_0(SC_NR, &err)
760e82
 #else
760e82
-/* No raw_syscall_0, let's use getpid() and hope for the best.  */
760e82
-# define INVOKE_SC(err) getpid()
760e82
+/* No raw_syscall_0, let's use geteuid() and hope for the best. */
760e82
+# define INVOKE_SC(err) geteuid()
760e82
 #endif
760e82
 
760e82
 /*
760e82
  * This prototype is intentionally different
760e82
  * from the prototype provided by <unistd.h>.
760e82
  */
760e82
-extern kernel_ulong_t getpid(void);
760e82
+extern kernel_ulong_t geteuid(void);
760e82
 
760e82
 int
760e82
 main(int ac, char **av)
760e82
@@ -45,7 +43,7 @@
760e82
 	assert(ac == 1 || ac == 2);
760e82
 
760e82
 	kernel_ulong_t expected =
760e82
-		(ac == 1) ? getpid() : strtoull(av[1], NULL, 0);
760e82
+		(ac == 1) ? geteuid() : strtoull(av[1], NULL, 0);
760e82
 	kernel_ulong_t err = 0;
760e82
 	kernel_ulong_t rc = INVOKE_SC(err);
760e82
 
760e82
Index: strace-5.7/tests-m32/inject-nf.test
760e82
===================================================================
760e82
--- strace-5.7.orig/tests-m32/inject-nf.test	2018-12-25 00:46:43.000000000 +0100
760e82
+++ strace-5.7/tests-m32/inject-nf.test	2020-09-09 14:58:03.727001394 +0200
760e82
@@ -9,14 +9,7 @@
760e82
 
760e82
 . "${srcdir=.}/scno_tampering.sh"
760e82
 
760e82
-case "$STRACE_ARCH" in
760e82
-alpha)
760e82
-	SYSCALL=getpgrp
760e82
-	;;
760e82
-*)
760e82
-	SYSCALL=getpid
760e82
-	;;
760e82
-esac
760e82
+SYSCALL='/^geteuid(32)?$'
760e82
 
760e82
 run_prog
760e82
 prog="$args"
760e82
Index: strace-5.7/tests-mx32/inject-nf.c
760e82
===================================================================
760e82
--- strace-5.7.orig/tests-mx32/inject-nf.c	2019-09-25 03:02:03.000000000 +0200
760e82
+++ strace-5.7/tests-mx32/inject-nf.c	2020-09-09 14:58:03.708001383 +0200
760e82
@@ -16,28 +16,26 @@
760e82
 
760e82
 #include "raw_syscall.h"
760e82
 
760e82
-#ifdef __alpha__
760e82
-/* alpha has no getpid */
760e82
-# define SC_NR __NR_getpgrp
760e82
-# define SC_NAME "getpgrp"
760e82
-# define getpid getpgrp
760e82
+#ifdef __NR_geteuid32
760e82
+# define SC_NR __NR_geteuid32
760e82
+# define SC_NAME "geteuid32"
760e82
 #else
760e82
-# define SC_NR __NR_getpid
760e82
-# define SC_NAME "getpid"
760e82
+# define SC_NR __NR_geteuid
760e82
+# define SC_NAME "geteuid"
760e82
 #endif
760e82
 
760e82
 #ifdef raw_syscall_0
760e82
 # define INVOKE_SC(err) raw_syscall_0(SC_NR, &err)
760e82
 #else
760e82
-/* No raw_syscall_0, let's use getpid() and hope for the best.  */
760e82
-# define INVOKE_SC(err) getpid()
760e82
+/* No raw_syscall_0, let's use geteuid() and hope for the best. */
760e82
+# define INVOKE_SC(err) geteuid()
760e82
 #endif
760e82
 
760e82
 /*
760e82
  * This prototype is intentionally different
760e82
  * from the prototype provided by <unistd.h>.
760e82
  */
760e82
-extern kernel_ulong_t getpid(void);
760e82
+extern kernel_ulong_t geteuid(void);
760e82
 
760e82
 int
760e82
 main(int ac, char **av)
760e82
@@ -45,7 +43,7 @@
760e82
 	assert(ac == 1 || ac == 2);
760e82
 
760e82
 	kernel_ulong_t expected =
760e82
-		(ac == 1) ? getpid() : strtoull(av[1], NULL, 0);
760e82
+		(ac == 1) ? geteuid() : strtoull(av[1], NULL, 0);
760e82
 	kernel_ulong_t err = 0;
760e82
 	kernel_ulong_t rc = INVOKE_SC(err);
760e82
 
760e82
Index: strace-5.7/tests-mx32/inject-nf.test
760e82
===================================================================
760e82
--- strace-5.7.orig/tests-mx32/inject-nf.test	2018-12-25 00:46:43.000000000 +0100
760e82
+++ strace-5.7/tests-mx32/inject-nf.test	2020-09-09 14:58:03.750001408 +0200
760e82
@@ -9,14 +9,7 @@
760e82
 
760e82
 . "${srcdir=.}/scno_tampering.sh"
760e82
 
760e82
-case "$STRACE_ARCH" in
760e82
-alpha)
760e82
-	SYSCALL=getpgrp
760e82
-	;;
760e82
-*)
760e82
-	SYSCALL=getpid
760e82
-	;;
760e82
-esac
760e82
+SYSCALL='/^geteuid(32)?$'
760e82
 
760e82
 run_prog
760e82
 prog="$args"