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

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