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

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