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

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