Compare commits

...

No commits in common. "imports/c8-beta/strace-4.24-6.el8" and "c8" have entirely different histories.

54 changed files with 2307 additions and 36364 deletions

2
.gitignore vendored
View File

@ -1 +1 @@
SOURCES/strace-4.24.tar.xz
SOURCES/strace-5.18.tar.xz

View File

@ -1 +1 @@
09a8c9638fd02622157af9d744ad7c7f991c75df SOURCES/strace-4.24.tar.xz
e038ea9fc29366ce6119cde27d8cf16ac554a353 SOURCES/strace-5.18.tar.xz

View File

@ -1,37 +0,0 @@
From ba803931948fe89ddf9e3ec407e5e16c689863ad Mon Sep 17 00:00:00 2001
From: Zhibin Li <08826794brmt@gmail.com>
Date: Wed, 1 Aug 2018 17:53:57 +0800
Subject: [PATCH 01/27] evdev: fix decoding of bit sets
According to drivers/input/evdev.c:bits_to_user(),
the Linux kernel returns the number of bytes, not bits.
* evdev.c (decode_bitset_): Treat syscall return value as the number
of bytes.
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
Fixes: v4.10~89 "Add decoding for evdev ioctls"
---
evdev.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/evdev.c b/evdev.c
index 7ca15c9..3c1aaa8 100644
--- a/evdev.c
+++ b/evdev.c
@@ -171,10 +171,10 @@ decode_bitset_(struct tcb *const tcp, const kernel_ulong_t arg,
tprints(", ");
unsigned int size;
- if ((kernel_ulong_t) tcp->u_rval > max_nr)
+ if ((kernel_ulong_t) tcp->u_rval > max_nr / 8)
size = max_nr;
else
- size = tcp->u_rval;
+ size = tcp->u_rval * 8;
char decoded_arg[size];
if (umove_or_printaddr(tcp, arg, &decoded_arg))
--
2.1.4

View File

@ -1,147 +0,0 @@
From c658eb981bfc302aafe5be6e4118a9c0a3f1735e Mon Sep 17 00:00:00 2001
From: Zhibin Li <08826794brmt@gmail.com>
Date: Wed, 1 Aug 2018 17:53:57 +0800
Subject: [PATCH 02/27] evdev: fix decoding of EVIOCGBIT(0, ...)
There is a comment in drivers/input/evdev.c which says:
/* EV_SYN==0 is EV_CNT, _not_ SYN_CNT, see EVIOCGBIT */
That is, EVIOCGBIT(0, ...) should return a bit mask with supported
event types instead of SYN_* event codes.
* defs.h (evdev_ev): New prototype.
* evdev.c: Include "xlat/evdev_ev.h" and remove "xlat/evdev_sync.h".
(bit_ioctl) <case EV_SYN>: Replace EV_SYN with 0, use evdev_ev
with XT_SORTED in decode_bitset invocation instead.
* ioctl.c: Do not include "xlat/evdev_ev.h".
(evdev_decode_number): Print nr == 0x20 as "0" instead of "EV_SYN".
* tests/ioctl_evdev.c (main): Use 0 instead of EV_SYN in EVIOCGBIT
output.
* xlat/evdev_sync.in: Remove.
Additional changes:
xlat/evdev_ev.h (auto-generated from xlat/evdev_ev.in)
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
Fixes: v4.10~89 "Add decoding for evdev ioctls"
---
defs.h | 1 +
evdev.c | 8 ++++----
ioctl.c | 7 ++++---
tests/ioctl_evdev.c | 2 +-
xlat/evdev_sync.in | 5 -----
5 files changed, 10 insertions(+), 13 deletions(-)
delete mode 100644 xlat/evdev_sync.in
Index: strace-4.24/defs.h
===================================================================
--- strace-4.24.orig/defs.h 2019-03-11 12:34:15.719549018 +0100
+++ strace-4.24/defs.h 2019-03-11 12:47:05.976567233 +0100
@@ -330,6 +330,7 @@
/** Number of elements in evdev_abs array without the terminating record. */
extern const size_t evdev_abs_size;
+extern const struct xlat evdev_ev[];
extern const struct xlat iffflags[];
extern const struct xlat ip_type_of_services[];
extern const struct xlat ipc_private[];
Index: strace-4.24/evdev.c
===================================================================
--- strace-4.24.orig/evdev.c 2019-03-11 12:34:21.911484926 +0100
+++ strace-4.24/evdev.c 2019-03-11 12:47:05.976567233 +0100
@@ -30,6 +30,7 @@
#include "defs.h"
#include "xlat/evdev_abs.h"
+#include "xlat/evdev_ev.h"
#ifdef HAVE_LINUX_INPUT_H
@@ -47,7 +48,6 @@
# include "xlat/evdev_relative_axes.h"
# include "xlat/evdev_snd.h"
# include "xlat/evdev_switch.h"
-# include "xlat/evdev_sync.h"
# ifndef SYN_MAX
# define SYN_MAX 0xf
@@ -258,9 +258,9 @@
const kernel_ulong_t arg)
{
switch (ev_nr) {
- case EV_SYN:
- return decode_bitset(tcp, arg, evdev_sync,
- SYN_MAX, "SYN_???", XT_INDEXED);
+ case 0:
+ return decode_bitset(tcp, arg, evdev_ev,
+ EV_MAX, "EV_???", XT_SORTED);
case EV_KEY:
return decode_bitset(tcp, arg, evdev_keycode,
KEY_MAX, "KEY_???", XT_INDEXED);
Index: strace-4.24/ioctl.c
===================================================================
--- strace-4.24.orig/ioctl.c 2019-03-11 12:34:15.719549018 +0100
+++ strace-4.24/ioctl.c 2019-03-11 12:47:05.976567233 +0100
@@ -33,8 +33,6 @@
#include <linux/ioctl.h>
#include "xlat/ioctl_dirs.h"
-#include "xlat/evdev_ev.h"
-
static int
compare(const void *a, const void *b)
{
@@ -99,7 +97,10 @@
if (nr >= 0x20 && nr <= 0x20 + 0x1f) {
tprints("EVIOCGBIT(");
- printxval(evdev_ev, nr - 0x20, "EV_???");
+ if (nr == 0x20)
+ tprintf("0");
+ else
+ printxval(evdev_ev, nr - 0x20, "EV_???");
tprintf(", %u)", _IOC_SIZE(code));
return 1;
} else if (nr >= 0x40 && nr <= 0x40 + 0x3f) {
Index: strace-4.24/tests/ioctl_evdev.c
===================================================================
--- strace-4.24.orig/tests/ioctl_evdev.c 2019-03-11 12:34:15.719549018 +0100
+++ strace-4.24/tests/ioctl_evdev.c 2019-03-11 12:47:05.977567222 +0100
@@ -138,7 +138,7 @@
TEST_NULL_ARG_EX(EVIOCGABS(0x3f), "EVIOCGABS(0x3f /* ABS_??? */)");
TEST_NULL_ARG_EX(EVIOCSABS(0x3f), "EVIOCSABS(0x3f /* ABS_??? */)");
- TEST_NULL_ARG(EVIOCGBIT(EV_SYN, 0));
+ TEST_NULL_ARG(EVIOCGBIT(0, 0));
TEST_NULL_ARG(EVIOCGBIT(EV_KEY, 1));
TEST_NULL_ARG(EVIOCGBIT(EV_REL, 2));
TEST_NULL_ARG(EVIOCGBIT(EV_ABS, 3));
Index: strace-4.24/xlat/evdev_sync.in
===================================================================
--- strace-4.24.orig/xlat/evdev_sync.in 2019-03-11 12:34:15.719549018 +0100
+++ /dev/null 1970-01-01 00:00:00.000000000 +0000
@@ -1,5 +0,0 @@
-#value_indexed
-SYN_REPORT 0
-SYN_CONFIG 1
-SYN_MT_REPORT 2
-SYN_DROPPED 3
Index: strace-4.24/xlat/evdev_ev.h
===================================================================
--- strace-4.24.orig/xlat/evdev_ev.h 2018-08-14 02:44:11.000000000 +0200
+++ strace-4.24/xlat/evdev_ev.h 2019-03-11 12:48:32.390670458 +0100
@@ -90,13 +90,8 @@
#ifndef XLAT_MACROS_ONLY
-# ifdef IN_MPERS
+# ifndef IN_MPERS
-# error static const struct xlat evdev_ev in mpers mode
-
-# else
-
-static
const struct xlat evdev_ev[] = {
XLAT(EV_SYN),
XLAT(EV_KEY),

View File

@ -1,52 +0,0 @@
From 1422eda187f936e576b17a3e0036b1c1c3476fc4 Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Sun, 19 Aug 2018 21:51:15 +0200
Subject: [PATCH 03/27] xlat: fix typo in smc_protocols.in
* xlat/smc_protocols.in: s/^MCPROTO_SMC/SMCPROTO_SMC/.
Additional changes:
Updated aut-generated xlat/smc_protocols.h
---
xlat/smc_protocols.in | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Index: strace-4.24/xlat/smc_protocols.in
===================================================================
--- strace-4.24.orig/xlat/smc_protocols.in 2018-05-08 22:59:20.000000000 +0200
+++ strace-4.24/xlat/smc_protocols.in 2019-03-10 05:08:53.367748788 +0100
@@ -1,3 +1,3 @@
#value_indexed
-MCPROTO_SMC 0
+SMCPROTO_SMC 0
SMCPROTO_SMC6 1
Index: strace-4.24/xlat/smc_protocols.h
===================================================================
--- strace-4.24.orig/xlat/smc_protocols.h 2018-08-14 02:44:23.000000000 +0200
+++ strace-4.24/xlat/smc_protocols.h 2019-03-10 05:09:36.010321779 +0100
@@ -3,12 +3,12 @@
#include "gcc_compat.h"
#include "static_assert.h"
-#if defined(MCPROTO_SMC) || (defined(HAVE_DECL_MCPROTO_SMC) && HAVE_DECL_MCPROTO_SMC)
+#if defined(SMCPROTO_SMC) || (defined(HAVE_DECL_SMCPROTO_SMC) && HAVE_DECL_SMCPROTO_SMC)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
-static_assert((MCPROTO_SMC) == (0), "MCPROTO_SMC != 0");
+static_assert((SMCPROTO_SMC) == (0), "SMCPROTO_SMC != 0");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
-# define MCPROTO_SMC 0
+# define SMCPROTO_SMC 0
#endif
#if defined(SMCPROTO_SMC6) || (defined(HAVE_DECL_SMCPROTO_SMC6) && HAVE_DECL_SMCPROTO_SMC6)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
@@ -28,7 +28,7 @@
static
const struct xlat smc_protocols[] = {
- [MCPROTO_SMC] = XLAT(MCPROTO_SMC),
+ [SMCPROTO_SMC] = XLAT(SMCPROTO_SMC),
[SMCPROTO_SMC6] = XLAT(SMCPROTO_SMC6),
XLAT_END
};

View File

@ -1,291 +0,0 @@
From acdd2e8d3d1551b41170a24951addb80b0b0d423 Mon Sep 17 00:00:00 2001
From: "Dmitry V. Levin" <ldv@altlinux.org>
Date: Tue, 14 Aug 2018 13:43:34 +0000
Subject: [PATCH 04/27] strace.c: introduce struct tcb_wait_data
Introduce a new structure to pass information between next_event(),
restart_delayed_tcb(), and dispatch_event().
This is going to be used by a subsequent change of next_event().
* strace.c (struct tcb_wait_data): New type.
(next_event): Remove parameters, return a pointer
to const struct tcb_wait_data. Return NULL instead of TE_BREAK.
(dispatch_event): Replace all parameters with a pointer
to const struct tcb_wait_data, obtain the trace event, siginfo,
and status from its fields.
(restart_delayed_tcb): Add local struct tcb_wait_data variable
with te field set to TE_RESTART, pass it to dispatch_event().
(main): Remove status and si variables, update next_event()
and dispatch_event() invocations.
Co-Authored-by: Eugene Syromyatnikov <evgsyr@gmail.com>
---
strace.c | 107 ++++++++++++++++++++++++++++++++++++++++-----------------------
1 file changed, 69 insertions(+), 38 deletions(-)
diff --git a/strace.c b/strace.c
index cd04b98..6d70d20 100644
--- a/strace.c
+++ b/strace.c
@@ -158,6 +158,12 @@ static bool open_append;
struct tcb *printing_tcp;
static struct tcb *current_tcp;
+struct tcb_wait_data {
+ enum trace_event te; /**< Event passed to dispatch_event() */
+ int status; /**< status, returned by wait4() */
+ siginfo_t si; /**< siginfo, returned by PTRACE_GETSIGINFO */
+};
+
static struct tcb **tcbtab;
static unsigned int nprocs;
static size_t tcbtabsize;
@@ -2226,16 +2232,19 @@ print_event_exit(struct tcb *tcp)
line_ended();
}
-static enum trace_event
-next_event(int *pstatus, siginfo_t *si)
+static const struct tcb_wait_data *
+next_event(void)
{
+ static struct tcb_wait_data wait_data;
+
int pid;
int status;
struct tcb *tcp;
+ struct tcb_wait_data *wd = &wait_data;
struct rusage ru;
if (interrupted)
- return TE_BREAK;
+ return NULL;
/*
* Used to exit simply when nprocs hits zero, but in this testcase:
@@ -2255,7 +2264,7 @@ next_event(int *pstatus, siginfo_t *si)
* on exit. Oh well...
*/
if (nprocs == 0)
- return TE_BREAK;
+ return NULL;
}
const bool unblock_delay_timer = is_delay_timer_armed();
@@ -2278,7 +2287,7 @@ next_event(int *pstatus, siginfo_t *si)
* then the system call will be interrupted and
* the expiration will be handled by the signal handler.
*/
- pid = wait4(-1, pstatus, __WALL, (cflag ? &ru : NULL));
+ pid = wait4(-1, &status, __WALL, (cflag ? &ru : NULL));
const int wait_errno = errno;
/*
@@ -2292,14 +2301,16 @@ next_event(int *pstatus, siginfo_t *si)
sigprocmask(SIG_BLOCK, &timer_set, NULL);
if (restart_failed)
- return TE_BREAK;
+ return NULL;
}
if (pid < 0) {
- if (wait_errno == EINTR)
- return TE_NEXT;
+ if (wait_errno == EINTR) {
+ wd->te = TE_NEXT;
+ return wd;
+ }
if (nprocs == 0 && wait_errno == ECHILD)
- return TE_BREAK;
+ return NULL;
/*
* If nprocs > 0, ECHILD is not expected,
* treat it as any other error here:
@@ -2308,12 +2319,13 @@ next_event(int *pstatus, siginfo_t *si)
perror_msg_and_die("wait4(__WALL)");
}
- status = *pstatus;
+ wd->status = status;
if (pid == popen_pid) {
if (!WIFSTOPPED(status))
popen_pid = 0;
- return TE_NEXT;
+ wd->te = TE_NEXT;
+ return wd;
}
if (debug_flag)
@@ -2324,8 +2336,10 @@ next_event(int *pstatus, siginfo_t *si)
if (!tcp) {
tcp = maybe_allocate_tcb(pid, status);
- if (!tcp)
- return TE_NEXT;
+ if (!tcp) {
+ wd->te = TE_NEXT;
+ return wd;
+ }
}
clear_regs(tcp);
@@ -2342,11 +2356,15 @@ next_event(int *pstatus, siginfo_t *si)
tcp->stime = stime;
}
- if (WIFSIGNALED(status))
- return TE_SIGNALLED;
+ if (WIFSIGNALED(status)) {
+ wd->te = TE_SIGNALLED;
+ return wd;
+ }
- if (WIFEXITED(status))
- return TE_EXITED;
+ if (WIFEXITED(status)) {
+ wd->te = TE_EXITED;
+ return wd;
+ }
/*
* As WCONTINUED flag has not been specified to wait4,
@@ -2373,19 +2391,19 @@ next_event(int *pstatus, siginfo_t *si)
if (sig == SIGSTOP && (tcp->flags & TCB_IGNORE_ONE_SIGSTOP)) {
debug_func_msg("ignored SIGSTOP on pid %d", tcp->pid);
tcp->flags &= ~TCB_IGNORE_ONE_SIGSTOP;
- return TE_RESTART;
+ wd->te = TE_RESTART;
} else if (sig == syscall_trap_sig) {
- return TE_SYSCALL_STOP;
+ wd->te = TE_SYSCALL_STOP;
} else {
- *si = (siginfo_t) {};
+ memset(&wd->si, 0, sizeof(wd->si));
/*
* True if tracee is stopped by signal
* (as opposed to "tracee received signal").
* TODO: shouldn't we check for errno == EINVAL too?
* We can get ESRCH instead, you know...
*/
- bool stopped = ptrace(PTRACE_GETSIGINFO, pid, 0, si) < 0;
- return stopped ? TE_GROUP_STOP : TE_SIGNAL_DELIVERY_STOP;
+ bool stopped = ptrace(PTRACE_GETSIGINFO, pid, 0, &wd->si) < 0;
+ wd->te = stopped ? TE_GROUP_STOP : TE_SIGNAL_DELIVERY_STOP;
}
break;
case PTRACE_EVENT_STOP:
@@ -2398,16 +2416,23 @@ next_event(int *pstatus, siginfo_t *si)
case SIGTSTP:
case SIGTTIN:
case SIGTTOU:
- return TE_GROUP_STOP;
+ wd->te = TE_GROUP_STOP;
+ break;
+ default:
+ wd->te = TE_RESTART;
}
- return TE_RESTART;
+ break;
case PTRACE_EVENT_EXEC:
- return TE_STOP_BEFORE_EXECVE;
+ wd->te = TE_STOP_BEFORE_EXECVE;
+ break;
case PTRACE_EVENT_EXIT:
- return TE_STOP_BEFORE_EXIT;
+ wd->te = TE_STOP_BEFORE_EXIT;
+ break;
default:
- return TE_RESTART;
+ wd->te = TE_RESTART;
}
+
+ return wd;
}
static int
@@ -2436,12 +2461,18 @@ trace_syscall(struct tcb *tcp, unsigned int *sig)
/* Returns true iff the main trace loop has to continue. */
static bool
-dispatch_event(enum trace_event ret, int *pstatus, siginfo_t *si)
+dispatch_event(const struct tcb_wait_data *wd)
{
unsigned int restart_op = PTRACE_SYSCALL;
unsigned int restart_sig = 0;
+ enum trace_event te = wd ? wd->te : TE_BREAK;
+ /*
+ * Copy wd->status to a non-const variable to workaround glibc bugs
+ * around union wait fixed by glibc commit glibc-2.24~391
+ */
+ int status = wd ? wd->status : 0;
- switch (ret) {
+ switch (te) {
case TE_BREAK:
return false;
@@ -2469,17 +2500,17 @@ dispatch_event(enum trace_event ret, int *pstatus, siginfo_t *si)
break;
case TE_SIGNAL_DELIVERY_STOP:
- restart_sig = WSTOPSIG(*pstatus);
- print_stopped(current_tcp, si, restart_sig);
+ restart_sig = WSTOPSIG(status);
+ print_stopped(current_tcp, &wd->si, restart_sig);
break;
case TE_SIGNALLED:
- print_signalled(current_tcp, current_tcp->pid, *pstatus);
+ print_signalled(current_tcp, current_tcp->pid, status);
droptcb(current_tcp);
return true;
case TE_GROUP_STOP:
- restart_sig = WSTOPSIG(*pstatus);
+ restart_sig = WSTOPSIG(status);
print_stopped(current_tcp, NULL, restart_sig);
if (use_seize) {
/*
@@ -2494,7 +2525,7 @@ dispatch_event(enum trace_event ret, int *pstatus, siginfo_t *si)
break;
case TE_EXITED:
- print_exited(current_tcp, current_tcp->pid, *pstatus);
+ print_exited(current_tcp, current_tcp->pid, status);
droptcb(current_tcp);
return true;
@@ -2577,13 +2608,15 @@ dispatch_event(enum trace_event ret, int *pstatus, siginfo_t *si)
static bool
restart_delayed_tcb(struct tcb *const tcp)
{
+ const struct tcb_wait_data wd = { .te = TE_RESTART };
+
debug_func_msg("pid %d", tcp->pid);
tcp->flags &= ~TCB_DELAYED;
struct tcb *const prev_tcp = current_tcp;
current_tcp = tcp;
- bool ret = dispatch_event(TE_RESTART, NULL, NULL);
+ bool ret = dispatch_event(&wd);
current_tcp = prev_tcp;
return ret;
@@ -2694,9 +2727,7 @@ main(int argc, char *argv[])
exit_code = !nprocs;
- int status;
- siginfo_t si;
- while (dispatch_event(next_event(&status, &si), &status, &si))
+ while (dispatch_event(next_event()))
;
terminate();
}
--
2.1.4

View File

@ -1,28 +0,0 @@
From 57aa6acb769e4a78d769e066411661e2aa053b4b Mon Sep 17 00:00:00 2001
From: "Dmitry V. Levin" <ldv@altlinux.org>
Date: Wed, 21 Nov 2018 22:51:49 +0000
Subject: [PATCH 05/27] Document -X option in strace -h output
* strace.c (usage): Mention -X option.
Reported-by: Dmitry Vyukov <dvyukov@google.com>
Complements: v4.23~308 "Add user interface for configuring xlat output style"
---
strace.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/strace.c b/strace.c
index 6d70d20..1146339 100644
--- a/strace.c
+++ b/strace.c
@@ -272,6 +272,7 @@ Output format:\n\
-T print time spent in each syscall\n\
-x print non-ascii strings in hex\n\
-xx print all strings in hex\n\
+ -X format set the format for printing of named constants and flags\n\
-y print paths associated with file descriptor arguments\n\
-yy print protocol specific information associated with socket file descriptors\n\
\n\
--
2.1.4

View File

@ -1,30 +0,0 @@
From fdc95e89441ba6f2d39f5f6f3e2ac20933245b8d Mon Sep 17 00:00:00 2001
From: Eugene Syromiatnikov <esyr@redhat.com>
Date: Thu, 20 Dec 2018 16:35:27 +0100
Subject: [PATCH 06/27] evdev: fix off-by-one error in decode_bitset
* evdev.c (decode_bitset): Decrement sorted/indexed xlat's size by one
in order to account for guarding XLAT_END, as other sorted/indexed xlat
wrappers do.
Fixes: v4.23~261 "evdev: support various types of xlats in decode_bitset"
---
evdev.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/evdev.c b/evdev.c
index cae2ef1..957d0e2 100644
--- a/evdev.c
+++ b/evdev.c
@@ -208,7 +208,7 @@ decode_bitset_(struct tcb *const tcp, const kernel_ulong_t arg,
#define decode_bitset(tcp_, arg_, decode_nr_, max_nr_, dflt_, xt_) \
decode_bitset_((tcp_), (arg_), (decode_nr_), (max_nr_), \
- (dflt_), ARRAY_SIZE(decode_nr_), (xt_))
+ (dflt_), ARRAY_SIZE(decode_nr_) - 1, (xt_))
# ifdef EVIOCGMTSLOTS
static int
--
2.1.4

View File

@ -1,29 +0,0 @@
From def46773e2540b4898b26c470d8d658b4b39075f Mon Sep 17 00:00:00 2001
From: "Dmitry V. Levin" <ldv@altlinux.org>
Date: Sun, 23 Dec 2018 22:12:36 +0000
Subject: [PATCH 07/27] nlattr: fix off-by-one error in indexed xlat lookup
* nlattr.c (decode_nla_meminfo): Decrement xlat size by one
to account for XLAT_END as other users of indexed xlats do.
Fixes: v4.23~89 "nlattr: print index names in netlink meminfo array"
---
nlattr.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/nlattr.c b/nlattr.c
index af7cc16..db37452 100644
--- a/nlattr.c
+++ b/nlattr.c
@@ -217,7 +217,7 @@ decode_nla_meminfo(struct tcb *const tcp,
tfetch_mem, print_uint32_array_member, &count,
PAF_PRINT_INDICES | PAF_INDEX_XLAT_VALUE_INDEXED
| XLAT_STYLE_FMT_U,
- ARRSZ_PAIR(netlink_sk_meminfo_indices),
+ ARRSZ_PAIR(netlink_sk_meminfo_indices) - 1,
"SK_MEMINFO_???");
return true;
--
2.1.4

View File

@ -1,29 +0,0 @@
From d0035c3031b0d5a1cbb300d698328d118af33d3e Mon Sep 17 00:00:00 2001
From: "Dmitry V. Levin" <ldv@altlinux.org>
Date: Sun, 23 Dec 2018 22:12:36 +0000
Subject: [PATCH 08/27] aio: fix off-by-one error in indexed xlat lookup
* aio.c (tprint_lio_opcode): Decrement xlat size by one to account
for XLAT_END as other users of indexed xlats do.
Fixes: v4.24~71 "aio: print IOCB_CMD_* using xlat"
---
aio.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/aio.c b/aio.c
index a07d8eb..24ad69f 100644
--- a/aio.c
+++ b/aio.c
@@ -70,7 +70,7 @@ tprint_lio_opcode(unsigned int cmd)
[IOCB_CMD_PWRITEV] = SUB_VECTOR,
};
- printxval_indexn_ex(ARRSZ_PAIR(aio_cmds), cmd, "IOCB_CMD_???",
+ printxval_indexn_ex(ARRSZ_PAIR(aio_cmds) - 1, cmd, "IOCB_CMD_???",
XLAT_STYLE_FMT_U);
return cmd < ARRAY_SIZE(subs) ? subs[cmd] : SUB_NONE;
--
2.1.4

View File

@ -1,94 +0,0 @@
From ee037ea1bbe3e9134eab3586bbd54613f39a1693 Mon Sep 17 00:00:00 2001
From: "Dmitry V. Levin" <ldv@altlinux.org>
Date: Sun, 23 Dec 2018 22:12:36 +0000
Subject: [PATCH 09/27] rtnl_link: fix off-by-one errors in indexed and sorted
xlat lookups
* rtnl_link.c (decode_nla_tun_type, decode_ifla_xdp_attached,
decode_ifla_inet_conf, decode_ifla_inet6_flags, decode_ifla_inet6_conf,
decode_ifla_inet6_stats, decode_ifla_inet6_icmp6_stats,
decode_ifla_inet6_agm): Decrement xlat size by one to account
for XLAT_END as other users of indexed and sorted xlats do.
Fixes: v4.25~71 "rtnl_link: decode named constants for IFLA_XDP_ATTACHED attribute value"
Fixes: v4.23~41 "rtnl_link: decode IFLA_AF_SPEC"
Fixes: v4.23~37 "rtnl_link: implement IFLA_INFO_DATA for tun devices"
Conflicts:
rtnl_link.c
---
rtnl_link.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/rtnl_link.c b/rtnl_link.c
index 1fbfd26..8e02bc7 100644
--- a/rtnl_link.c
+++ b/rtnl_link.c
@@ -356,7 +356,7 @@ decode_nla_tun_type(struct tcb *const tcp,
{
const struct decode_nla_xlat_opts opts = {
.xlat = tun_device_types,
- .xlat_size = ARRAY_SIZE(tun_device_types),
+ .xlat_size = ARRAY_SIZE(tun_device_types) - 1,
.xt = XT_INDEXED,
.dflt = "IFF_???",
.size = 1,
@@ -626,7 +626,8 @@ decode_ifla_inet_conf(struct tcb *const tcp,
print_array_ex(tcp, addr, cnt, &elem, sizeof(elem),
tfetch_mem, print_int32_array_member, NULL,
PAF_PRINT_INDICES | PAF_INDEX_XLAT_VALUE_INDEXED
- | XLAT_STYLE_FMT_D, ARRSZ_PAIR(inet_devconf_indices),
+ | XLAT_STYLE_FMT_D,
+ ARRSZ_PAIR(inet_devconf_indices) - 1,
"IPV4_DEVCONF_???");
return true;
@@ -643,7 +644,7 @@ decode_ifla_inet6_flags(struct tcb *const tcp,
const void *const opaque_data)
{
const struct decode_nla_xlat_opts opts = {
- ARRSZ_PAIR(inet6_if_flags), "IF_???",
+ ARRSZ_PAIR(inet6_if_flags) - 1, "IF_???",
.size = 4,
};
@@ -665,7 +666,8 @@ decode_ifla_inet6_conf(struct tcb *const tcp,
print_array_ex(tcp, addr, cnt, &elem, sizeof(elem),
tfetch_mem, print_int32_array_member, NULL,
PAF_PRINT_INDICES | PAF_INDEX_XLAT_VALUE_INDEXED
- | XLAT_STYLE_FMT_D, ARRSZ_PAIR(inet6_devconf_indices),
+ | XLAT_STYLE_FMT_D,
+ ARRSZ_PAIR(inet6_devconf_indices) - 1,
"DEVCONF_???");
return true;
@@ -686,7 +688,7 @@ decode_ifla_inet6_stats(struct tcb *const tcp,
print_array_ex(tcp, addr, cnt, &elem, sizeof(elem),
tfetch_mem, print_uint64_array_member, NULL,
PAF_PRINT_INDICES | PAF_INDEX_XLAT_VALUE_INDEXED
- | XLAT_STYLE_FMT_U, ARRSZ_PAIR(snmp_ip_stats),
+ | XLAT_STYLE_FMT_U, ARRSZ_PAIR(snmp_ip_stats) - 1,
"IPSTATS_MIB_???");
return true;
@@ -733,7 +735,7 @@ decode_ifla_inet6_icmp6_stats(struct tcb *const tcp,
print_array_ex(tcp, addr, cnt, &elem, sizeof(elem),
tfetch_mem, print_uint64_array_member, NULL,
PAF_PRINT_INDICES | PAF_INDEX_XLAT_VALUE_INDEXED
- | XLAT_STYLE_FMT_U, ARRSZ_PAIR(snmp_icmp6_stats),
+ | XLAT_STYLE_FMT_U, ARRSZ_PAIR(snmp_icmp6_stats) - 1,
"ICMP6_MIB_???");
return true;
@@ -762,7 +764,7 @@ decode_ifla_inet6_agm(struct tcb *const tcp,
const void *const opaque_data)
{
const struct decode_nla_xlat_opts opts = {
- ARRSZ_PAIR(in6_addr_gen_mode), "IN6_ADDR_GEN_MODE_???",
+ ARRSZ_PAIR(in6_addr_gen_mode) - 1, "IN6_ADDR_GEN_MODE_???",
.xt = XT_INDEXED,
.size = 1,
};
--
2.1.4

View File

@ -1,30 +0,0 @@
From 1fb452d1a836c69fc9cf7fea59a80a50fabd6385 Mon Sep 17 00:00:00 2001
From: "Dmitry V. Levin" <ldv@altlinux.org>
Date: Mon, 24 Dec 2018 10:19:24 +0000
Subject: [PATCH 10/27] xlat_idx: do not issue warnings for holes in indices
Some xlat indices like evdev_abs have holes, avoid issuing warnings
about them.
* xlat.c (xlat_idx): Do not issue warnings for holes in the index.
---
xlat.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/xlat.c b/xlat.c
index 4614cef..7de51da 100644
--- a/xlat.c
+++ b/xlat.c
@@ -269,6 +269,9 @@ xlat_idx(const struct xlat *xlat, size_t nmemb, uint64_t val)
return NULL;
if (val != pos[val].val) {
+ if (pos[val].val == 0)
+ return NULL; /* a hole in the index */
+
error_func_msg("Unexpected xlat value %" PRIu64
" at index %" PRIu64,
pos[val].val, val);
--
2.1.4

View File

@ -1,403 +0,0 @@
From ffc3e46d6ea23ba71eb49c8bc36eb3068968b691 Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Tue, 4 Sep 2018 16:45:04 +0200
Subject: [PATCH 11/27] strace.1.in: print names of entities in bold, provide
man page sections
* strace.1.in (.SH DESCRIPTION, .SH OPTIONS): Add man page section
numbers. Make mentions of strace and other entities bold.
Additional changes:
Update auto-generated strace.1
---
strace.1.in | 89 ++++++++++++++++++++++++++++++++++++++++++-------------------
1 file changed, 61 insertions(+), 28 deletions(-)
Index: strace-4.24/strace.1.in
===================================================================
--- strace-4.24.orig/strace.1.in 2018-07-07 12:29:02.000000000 +0200
+++ strace-4.24/strace.1.in 2019-03-10 05:12:00.665873244 +0100
@@ -177,7 +177,7 @@
open("xyzzy", O_WRONLY|O_APPEND|O_CREAT, 0666) = 3
.CE
Here, the third argument of
-.B open
+.BR open (2)
is decoded by breaking down the
flag argument into its three bitwise-OR constituents and printing the
mode value in octal by tradition. Where the traditional or native
@@ -198,7 +198,7 @@
.B st_mode
member is carefully decoded into a bitwise-OR of symbolic and numeric values.
Also notice in this example that the first argument to
-.B lstat
+.BR lstat (2)
is an input to the system call and the second argument is an output.
Since output arguments are not modified if the system call fails, arguments may
not always be dereferenced. For example, retrying the "ls \-l" example
@@ -224,15 +224,16 @@
(32 by default) bytes of strings are printed;
longer strings have an ellipsis appended following the closing quote.
Here is a line from "ls \-l" where the
-.B getpwuid
+.BR getpwuid (3)
library routine is reading the password file:
.CW
read(3, "root::0:0:System Administrator:/"..., 1024) = 422
.CE
While structures are annotated using curly braces, simple pointers
and arrays are printed using square brackets with commas separating
-elements. Here is an example from the command "id" on a system with
-supplementary group ids:
+elements. Here is an example from the command
+.BR id (1)
+on a system with supplementary group ids:
.CW
getgroups(32, [100, 0]) = 2
.CE
@@ -489,7 +490,7 @@
which is useful to seeing what files the process is referencing.
Furthermore, using the abbreviation will ensure that you don't
accidentally forget to include a call like
-.B lstat
+.BR lstat (2)
in the list. Betchya woulda forgot that one.
.TP
.BR "\-e\ trace" = %process
@@ -769,8 +770,7 @@
\fB\-e\ inject\fR= expression with default value of
.I errno
option set to
-.IR ENOSYS .
-
+.BR ENOSYS .
.TP
.BR "\-e\ kvm" = vcpu
Print the exit reason of kvm vcpu. Requires Linux kernel version 4.16.0
@@ -794,10 +794,11 @@
.BI "\-b " syscall
If specified syscall is reached, detach from traced process.
Currently, only
-.I execve
+.BR execve (2)
syscall is supported. This option is useful if you want to trace
-multi-threaded process and therefore require -f, but don't want
-to trace its (potentially very complex) children.
+multi-threaded process and therefore require
+.BR \-f ,
+but don't want to trace its (potentially very complex) children.
.TP
.B \-D
Run tracer process as a detached grandchild, not as parent of the
@@ -816,16 +817,20 @@
.B \-p
.I PID
.B \-f
-will attach all threads of process PID if it is multi-threaded,
-not only thread with thread_id = PID.
+will attach all threads of process
+.I PID
+if it is multi-threaded, not only thread with
+.IR thread_id " = " PID .
.TP
.B \-ff
If the
.B \-o
.I filename
option is in effect, each processes trace is written to
-.I filename.pid
-where pid is the numeric process id of each process.
+.IR filename . pid
+where
+.I pid
+is the numeric process id of each process.
This is incompatible with
.BR \-c ,
since no per-process counts are kept.
@@ -835,11 +840,30 @@
to obtain a combined strace log view.
.TP
.BI "\-I " interruptible
-When strace can be interrupted by signals (such as pressing ^C).
-1: no signals are blocked; 2: fatal signals are blocked while decoding syscall
-(default); 3: fatal signals are always blocked (default if '-o FILE PROG');
-4: fatal signals and SIGTSTP (^Z) are always blocked (useful to make
-strace -o FILE PROG not stop on ^Z).
+When
+.B strace
+can be interrupted by signals (such as pressing
+.BR ^C ).
+.RS
+.TP 4
+.B 1
+no signals are blocked;
+.TQ
+.B 2
+fatal signals are blocked while decoding syscall (default);
+.TQ
+.B 3
+fatal signals are always blocked (default if
+.BR -o " " \fIFILE\fR " " \fIPROG\fR );
+.TQ
+.B 4
+fatal signals and
+.BR SIGTSTP " (" ^Z )
+are always blocked (useful to make
+.BI "strace -o " "FILE PROG"
+not stop on
+.BR ^Z ).
+.RE
.SS Startup
.TP 12
\fB\-E\ \fIvar\fR=\,\fIval\fR
@@ -920,7 +944,8 @@
.B strace
can be used as a wrapper process transparent to the invoking parent process.
Note that parent-child relationship (signal stop notifications,
-getppid() value, etc) between traced process and its parent are not preserved
+.BR getppid (2)
+value, etc) between traced process and its parent are not preserved
unless
.B \-D
is used.
@@ -987,8 +1012,11 @@
definitions during the build time.
Please refer to the output of the
.B strace \-V
-command in order to figure out what support is available in your strace build
-("non-native" refers to an ABI that differs from the ABI strace has):
+command in order to figure out what support is available in your
+.B strace
+build ("non-native" refers to an ABI that differs from the ABI
+.B strace
+has):
.TP 15
.B m32-mpers
.B strace
@@ -1057,17 +1085,22 @@
.LP
On x32, syscalls that are intended to be used by 64-bit processes and not x32
ones (for example,
-.BR readv ,
+.BR readv (2),
that has syscall number 19 on x86_64, with its x32 counterpart has syscall
number 515), but called with
.B __X32_SYSCALL_BIT
-flag being set, are designated with "#64" suffix.
+flag being set, are designated with
+.B "#64"
+suffix.
.LP
On some platforms a process that is attached to with the
.B \-p
-option may observe a spurious EINTR return from the current
-system call that is not restartable. (Ideally, all system calls
-should be restarted on strace attach, making the attach invisible
+option may observe a spurious
+.B EINTR
+return from the current system call that is not restartable.
+(Ideally, all system calls should be restarted on
+.B strace
+attach, making the attach invisible
to the traced process, but a few system calls aren't.
Arguably, every instance of such behavior is a kernel bug.)
This may have an unpredictable effect on the process
Index: strace-4.24/strace.1
===================================================================
--- strace-4.24.orig/strace.1 2018-08-14 02:44:59.000000000 +0200
+++ strace-4.24/strace.1 2019-03-10 05:15:15.101926224 +0100
@@ -53,7 +53,7 @@
. el \
. BR "\\$1"
..
-.TH STRACE 1 "2018-07-07" "strace 4.24"
+.TH STRACE 1 "2019-03-08" "strace 4.24"
.SH NAME
strace \- trace system calls and signals
.SH SYNOPSIS
@@ -177,7 +177,7 @@
open("xyzzy", O_WRONLY|O_APPEND|O_CREAT, 0666) = 3
.CE
Here, the third argument of
-.B open
+.BR open (2)
is decoded by breaking down the
flag argument into its three bitwise-OR constituents and printing the
mode value in octal by tradition. Where the traditional or native
@@ -198,7 +198,7 @@
.B st_mode
member is carefully decoded into a bitwise-OR of symbolic and numeric values.
Also notice in this example that the first argument to
-.B lstat
+.BR lstat (2)
is an input to the system call and the second argument is an output.
Since output arguments are not modified if the system call fails, arguments may
not always be dereferenced. For example, retrying the "ls \-l" example
@@ -224,15 +224,16 @@
(32 by default) bytes of strings are printed;
longer strings have an ellipsis appended following the closing quote.
Here is a line from "ls \-l" where the
-.B getpwuid
+.BR getpwuid (3)
library routine is reading the password file:
.CW
read(3, "root::0:0:System Administrator:/"..., 1024) = 422
.CE
While structures are annotated using curly braces, simple pointers
and arrays are printed using square brackets with commas separating
-elements. Here is an example from the command "id" on a system with
-supplementary group ids:
+elements. Here is an example from the command
+.BR id (1)
+on a system with supplementary group ids:
.CW
getgroups(32, [100, 0]) = 2
.CE
@@ -489,7 +490,7 @@
which is useful to seeing what files the process is referencing.
Furthermore, using the abbreviation will ensure that you don't
accidentally forget to include a call like
-.B lstat
+.BR lstat (2)
in the list. Betchya woulda forgot that one.
.TP
.BR "\-e\ trace" = %process
@@ -769,8 +770,7 @@
\fB\-e\ inject\fR= expression with default value of
.I errno
option set to
-.IR ENOSYS .
-
+.BR ENOSYS .
.TP
.BR "\-e\ kvm" = vcpu
Print the exit reason of kvm vcpu. Requires Linux kernel version 4.16.0
@@ -794,10 +794,11 @@
.BI "\-b " syscall
If specified syscall is reached, detach from traced process.
Currently, only
-.I execve
+.BR execve (2)
syscall is supported. This option is useful if you want to trace
-multi-threaded process and therefore require -f, but don't want
-to trace its (potentially very complex) children.
+multi-threaded process and therefore require
+.BR \-f ,
+but don't want to trace its (potentially very complex) children.
.TP
.B \-D
Run tracer process as a detached grandchild, not as parent of the
@@ -816,16 +817,20 @@
.B \-p
.I PID
.B \-f
-will attach all threads of process PID if it is multi-threaded,
-not only thread with thread_id = PID.
+will attach all threads of process
+.I PID
+if it is multi-threaded, not only thread with
+.IR thread_id " = " PID .
.TP
.B \-ff
If the
.B \-o
.I filename
option is in effect, each processes trace is written to
-.I filename.pid
-where pid is the numeric process id of each process.
+.IR filename . pid
+where
+.I pid
+is the numeric process id of each process.
This is incompatible with
.BR \-c ,
since no per-process counts are kept.
@@ -835,11 +840,30 @@
to obtain a combined strace log view.
.TP
.BI "\-I " interruptible
-When strace can be interrupted by signals (such as pressing ^C).
-1: no signals are blocked; 2: fatal signals are blocked while decoding syscall
-(default); 3: fatal signals are always blocked (default if '-o FILE PROG');
-4: fatal signals and SIGTSTP (^Z) are always blocked (useful to make
-strace -o FILE PROG not stop on ^Z).
+When
+.B strace
+can be interrupted by signals (such as pressing
+.BR ^C ).
+.RS
+.TP 4
+.B 1
+no signals are blocked;
+.TQ
+.B 2
+fatal signals are blocked while decoding syscall (default);
+.TQ
+.B 3
+fatal signals are always blocked (default if
+.BR -o " " \fIFILE\fR " " \fIPROG\fR );
+.TQ
+.B 4
+fatal signals and
+.BR SIGTSTP " (" ^Z )
+are always blocked (useful to make
+.BI "strace -o " "FILE PROG"
+not stop on
+.BR ^Z ).
+.RE
.SS Startup
.TP 12
\fB\-E\ \fIvar\fR=\,\fIval\fR
@@ -920,7 +944,8 @@
.B strace
can be used as a wrapper process transparent to the invoking parent process.
Note that parent-child relationship (signal stop notifications,
-getppid() value, etc) between traced process and its parent are not preserved
+.BR getppid (2)
+value, etc) between traced process and its parent are not preserved
unless
.B \-D
is used.
@@ -987,8 +1012,11 @@
definitions during the build time.
Please refer to the output of the
.B strace \-V
-command in order to figure out what support is available in your strace build
-("non-native" refers to an ABI that differs from the ABI strace has):
+command in order to figure out what support is available in your
+.B strace
+build ("non-native" refers to an ABI that differs from the ABI
+.B strace
+has):
.TP 15
.B m32-mpers
.B strace
@@ -1057,17 +1085,22 @@
.LP
On x32, syscalls that are intended to be used by 64-bit processes and not x32
ones (for example,
-.BR readv ,
+.BR readv (2),
that has syscall number 19 on x86_64, with its x32 counterpart has syscall
number 515), but called with
.B __X32_SYSCALL_BIT
-flag being set, are designated with "#64" suffix.
+flag being set, are designated with
+.B "#64"
+suffix.
.LP
On some platforms a process that is attached to with the
.B \-p
-option may observe a spurious EINTR return from the current
-system call that is not restartable. (Ideally, all system calls
-should be restarted on strace attach, making the attach invisible
+option may observe a spurious
+.B EINTR
+return from the current system call that is not restartable.
+(Ideally, all system calls should be restarted on
+.B strace
+attach, making the attach invisible
to the traced process, but a few system calls aren't.
Arguably, every instance of such behavior is a kernel bug.)
This may have an unpredictable effect on the process

View File

@ -1,110 +0,0 @@
From be720dc56adad1ecac99476cc302fec1d1ba8ee8 Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Tue, 4 Sep 2018 20:30:30 +0200
Subject: [PATCH 12/27] strace.1.in: consistently use CTRL-combinations
Additional changes:
Updated auto-generated strace.1
---
strace.1.in | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
Index: strace-4.24/strace.1.in
===================================================================
--- strace-4.24.orig/strace.1.in 2019-03-10 05:12:00.665873244 +0100
+++ strace-4.24/strace.1.in 2019-03-10 05:17:19.205683488 +0100
@@ -843,7 +843,7 @@
When
.B strace
can be interrupted by signals (such as pressing
-.BR ^C ).
+.BR CTRL\-C ).
.RS
.TP 4
.B 1
@@ -858,11 +858,11 @@
.TQ
.B 4
fatal signals and
-.BR SIGTSTP " (" ^Z )
+.BR SIGTSTP " (" CTRL\-Z )
are always blocked (useful to make
.BI "strace -o " "FILE PROG"
not stop on
-.BR ^Z ).
+.BR CTRL\-Z ).
.RE
.SS Startup
.TP 12
@@ -883,8 +883,8 @@
.I pid
and begin tracing.
The trace may be terminated
-at any time by a keyboard interrupt signal (\c
-.SM CTRL\s0-C).
+at any time by a keyboard interrupt signal
+.RB ( CTRL\-C ).
.B strace
will respond by detaching itself from the traced process(es)
leaving it (them) to continue running.
@@ -1129,8 +1129,8 @@
.LP
Traced processes which are descended from
.I command
-may be left running after an interrupt signal (\c
-.SM CTRL\s0-C).
+may be left running after an interrupt signal
+.RB ( CTRL\-C ).
.SH HISTORY
The original
.B strace
Index: strace-4.24/strace.1
===================================================================
--- strace-4.24.orig/strace.1 2019-03-10 05:18:07.824196638 +0100
+++ strace-4.24/strace.1 2019-03-10 05:18:36.534909138 +0100
@@ -843,7 +843,7 @@
When
.B strace
can be interrupted by signals (such as pressing
-.BR ^C ).
+.BR CTRL\-C ).
.RS
.TP 4
.B 1
@@ -858,11 +858,11 @@
.TQ
.B 4
fatal signals and
-.BR SIGTSTP " (" ^Z )
+.BR SIGTSTP " (" CTRL\-Z )
are always blocked (useful to make
.BI "strace -o " "FILE PROG"
not stop on
-.BR ^Z ).
+.BR CTRL\-Z ).
.RE
.SS Startup
.TP 12
@@ -883,8 +883,8 @@
.I pid
and begin tracing.
The trace may be terminated
-at any time by a keyboard interrupt signal (\c
-.SM CTRL\s0-C).
+at any time by a keyboard interrupt signal
+.RB ( CTRL\-C ).
.B strace
will respond by detaching itself from the traced process(es)
leaving it (them) to continue running.
@@ -1129,8 +1129,8 @@
.LP
Traced processes which are descended from
.I command
-may be left running after an interrupt signal (\c
-.SM CTRL\s0-C).
+may be left running after an interrupt signal
+.RB ( CTRL\-C ).
.SH HISTORY
The original
.B strace

File diff suppressed because it is too large Load Diff

View File

@ -1,216 +0,0 @@
From 14e5342e996ff122875a2306ba8d84dac096a48a Mon Sep 17 00:00:00 2001
From: "Dmitry V. Levin" <ldv@altlinux.org>
Date: Thu, 3 Jan 2019 23:36:22 +0000
Subject: [PATCH 15/27] tests: use tail_alloc instead of calloc in
bpf-obj_get_info_by_fd-prog*
This guarantees that map_info and prog_info objects are not accessed
out of bounds.
* tests/bpf-obj_get_info_by_fd.c: Include <string.h>.
(main): Use tail_alloc instead of calloc for map_info and prog_info.
Conflicts:
tests/bpf-obj_get_info_by_fd.c
Additional changes:
tests-m32/bpf-obj_get_info_by_fd.c (copy of tests/bpf-obj_get_info_by_fd.c)
tests-mx32/bpf-obj_get_info_by_fd.c (copy of tests/bpf-obj_get_info_by_fd.c)
---
tests/bpf-obj_get_info_by_fd.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
Index: strace-4.24/tests/bpf-obj_get_info_by_fd.c
===================================================================
--- strace-4.24.orig/tests/bpf-obj_get_info_by_fd.c 2019-03-10 05:19:26.164412164 +0100
+++ strace-4.24/tests/bpf-obj_get_info_by_fd.c 2019-03-10 05:35:03.618024803 +0100
@@ -18,6 +18,7 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#include <sys/sysmacros.h>
#include <asm/unistd.h>
@@ -274,13 +275,14 @@
* initializer element is not constant.
*/
#define MAP_INFO_SZ (sizeof(*map_info) + 64)
- struct bpf_map_info_struct *map_info = calloc(1, MAP_INFO_SZ);
+ struct bpf_map_info_struct *map_info = tail_alloc(MAP_INFO_SZ);
struct BPF_OBJ_GET_INFO_BY_FD_struct bpf_map_get_info_attr = {
.bpf_fd = map_fd,
.info_len = MAP_INFO_SZ,
.info = (uintptr_t) map_info,
};
+ memset(map_info, 0, MAP_INFO_SZ);
int ret = sys_bpf(BPF_OBJ_GET_INFO_BY_FD, &bpf_map_get_info_attr,
sizeof(bpf_map_get_info_attr));
if (ret < 0)
@@ -330,7 +332,7 @@
* initializer element is not constant.
*/
#define PROG_INFO_SZ (sizeof(*prog_info) + 64)
- struct bpf_prog_info_struct *prog_info = calloc(1, PROG_INFO_SZ);
+ struct bpf_prog_info_struct *prog_info = tail_alloc(PROG_INFO_SZ);
struct bpf_insn *xlated_prog = tail_alloc(sizeof(*xlated_prog) * 42);
uint32_t *map_ids = tail_alloc(sizeof(*map_ids) * 2);
struct BPF_OBJ_GET_INFO_BY_FD_struct bpf_prog_get_info_attr = {
@@ -340,6 +342,7 @@
};
size_t old_prog_info_len = PROG_INFO_SZ;
+ memset(prog_info, 0, PROG_INFO_SZ);
for (unsigned int i = 0; i < 4; i++) {
prog_info->jited_prog_len = 0;
switch (i) {
Index: strace-4.24/tests-m32/bpf-obj_get_info_by_fd.c
===================================================================
--- strace-4.24.orig/tests-m32/bpf-obj_get_info_by_fd.c 2018-06-04 03:11:05.000000000 +0200
+++ strace-4.24/tests-m32/bpf-obj_get_info_by_fd.c 2019-03-10 05:35:43.934621086 +0100
@@ -4,27 +4,7 @@
* Copyright (c) 2018 The strace developers.
* All rights reserved.
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "tests.h"
@@ -38,6 +18,7 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#include <sys/sysmacros.h>
#include <asm/unistd.h>
@@ -294,13 +275,14 @@
* initializer element is not constant.
*/
#define MAP_INFO_SZ (sizeof(*map_info) + 64)
- struct bpf_map_info_struct *map_info = calloc(1, MAP_INFO_SZ);
+ struct bpf_map_info_struct *map_info = tail_alloc(MAP_INFO_SZ);
struct BPF_OBJ_GET_INFO_BY_FD_struct bpf_map_get_info_attr = {
.bpf_fd = map_fd,
.info_len = MAP_INFO_SZ,
.info = (uintptr_t) map_info,
};
+ memset(map_info, 0, MAP_INFO_SZ);
int ret = sys_bpf(BPF_OBJ_GET_INFO_BY_FD, &bpf_map_get_info_attr,
sizeof(bpf_map_get_info_attr));
if (ret < 0)
@@ -350,7 +332,7 @@
* initializer element is not constant.
*/
#define PROG_INFO_SZ (sizeof(*prog_info) + 64)
- struct bpf_prog_info_struct *prog_info = calloc(1, PROG_INFO_SZ);
+ struct bpf_prog_info_struct *prog_info = tail_alloc(PROG_INFO_SZ);
struct bpf_insn *xlated_prog = tail_alloc(sizeof(*xlated_prog) * 42);
uint32_t *map_ids = tail_alloc(sizeof(*map_ids) * 2);
struct BPF_OBJ_GET_INFO_BY_FD_struct bpf_prog_get_info_attr = {
@@ -360,6 +342,7 @@
};
size_t old_prog_info_len = PROG_INFO_SZ;
+ memset(prog_info, 0, PROG_INFO_SZ);
for (unsigned int i = 0; i < 4; i++) {
prog_info->jited_prog_len = 0;
switch (i) {
Index: strace-4.24/tests-mx32/bpf-obj_get_info_by_fd.c
===================================================================
--- strace-4.24.orig/tests-mx32/bpf-obj_get_info_by_fd.c 2018-06-04 03:11:05.000000000 +0200
+++ strace-4.24/tests-mx32/bpf-obj_get_info_by_fd.c 2019-03-10 05:35:48.837571989 +0100
@@ -4,27 +4,7 @@
* Copyright (c) 2018 The strace developers.
* All rights reserved.
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "tests.h"
@@ -38,6 +18,7 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#include <sys/sysmacros.h>
#include <asm/unistd.h>
@@ -294,13 +275,14 @@
* initializer element is not constant.
*/
#define MAP_INFO_SZ (sizeof(*map_info) + 64)
- struct bpf_map_info_struct *map_info = calloc(1, MAP_INFO_SZ);
+ struct bpf_map_info_struct *map_info = tail_alloc(MAP_INFO_SZ);
struct BPF_OBJ_GET_INFO_BY_FD_struct bpf_map_get_info_attr = {
.bpf_fd = map_fd,
.info_len = MAP_INFO_SZ,
.info = (uintptr_t) map_info,
};
+ memset(map_info, 0, MAP_INFO_SZ);
int ret = sys_bpf(BPF_OBJ_GET_INFO_BY_FD, &bpf_map_get_info_attr,
sizeof(bpf_map_get_info_attr));
if (ret < 0)
@@ -350,7 +332,7 @@
* initializer element is not constant.
*/
#define PROG_INFO_SZ (sizeof(*prog_info) + 64)
- struct bpf_prog_info_struct *prog_info = calloc(1, PROG_INFO_SZ);
+ struct bpf_prog_info_struct *prog_info = tail_alloc(PROG_INFO_SZ);
struct bpf_insn *xlated_prog = tail_alloc(sizeof(*xlated_prog) * 42);
uint32_t *map_ids = tail_alloc(sizeof(*map_ids) * 2);
struct BPF_OBJ_GET_INFO_BY_FD_struct bpf_prog_get_info_attr = {
@@ -360,6 +342,7 @@
};
size_t old_prog_info_len = PROG_INFO_SZ;
+ memset(prog_info, 0, PROG_INFO_SZ);
for (unsigned int i = 0; i < 4; i++) {
prog_info->jited_prog_len = 0;
switch (i) {

View File

@ -1,61 +0,0 @@
From 755e4a0da3035c128d18c9a8f7d2f61f29715323 Mon Sep 17 00:00:00 2001
From: Martin Lau <kafai@fb.com>
Date: Thu, 3 Jan 2019 23:36:22 +0000
Subject: [PATCH 16/27] tests: fix prog_info initialization in
bpf-obj_get_info_by_fd-prog*
The sys_bpf(BPF_OBJ_GET_INFO_BY_FD, &bpf_prog_get_info_attr, ...) is
called in a loop. The bpf_prog_get_info_attr.info object is in size 104
but bpf_prog_get_info_attr.info_len is in size 168. Hence, if the prog
is jited, the second iteration onwards will have nr_jited_ksyms == 1
which is asking the kernel to fill the
bpf_prog_get_info_attr.info.jited_ksyms and it is NULL.
* tests/bpf-obj_get_info_by_fd.c (main): Clear memory beyond prog_info
at the start of every iteration.
Additional changes:
tests-m32/bpf-obj_get_info_by_fd.c (copy of tests/bpf-obj_get_info_by_fd.c)
tests-mx32/bpf-obj_get_info_by_fd.c (copy of tests/bpf-obj_get_info_by_fd.c)
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
---
tests/bpf-obj_get_info_by_fd.c | 1 +
1 file changed, 1 insertion(+)
Index: strace-4.24/tests/bpf-obj_get_info_by_fd.c
===================================================================
--- strace-4.24.orig/tests/bpf-obj_get_info_by_fd.c 2019-03-10 05:38:07.889179571 +0100
+++ strace-4.24/tests/bpf-obj_get_info_by_fd.c 2019-03-10 05:38:16.038097970 +0100
@@ -345,6 +345,7 @@
memset(prog_info, 0, PROG_INFO_SZ);
for (unsigned int i = 0; i < 4; i++) {
prog_info->jited_prog_len = 0;
+ memset(prog_info + 1, 0, PROG_INFO_SZ - sizeof(*prog_info));
switch (i) {
case 1:
prog_info->xlated_prog_insns =
Index: strace-4.24/tests-m32/bpf-obj_get_info_by_fd.c
===================================================================
--- strace-4.24.orig/tests-m32/bpf-obj_get_info_by_fd.c 2019-03-10 05:35:43.934621086 +0100
+++ strace-4.24/tests-m32/bpf-obj_get_info_by_fd.c 2019-03-10 05:38:32.161936511 +0100
@@ -345,6 +345,7 @@
memset(prog_info, 0, PROG_INFO_SZ);
for (unsigned int i = 0; i < 4; i++) {
prog_info->jited_prog_len = 0;
+ memset(prog_info + 1, 0, PROG_INFO_SZ - sizeof(*prog_info));
switch (i) {
case 1:
prog_info->xlated_prog_insns =
Index: strace-4.24/tests-mx32/bpf-obj_get_info_by_fd.c
===================================================================
--- strace-4.24.orig/tests-mx32/bpf-obj_get_info_by_fd.c 2019-03-10 05:38:12.854129853 +0100
+++ strace-4.24/tests-mx32/bpf-obj_get_info_by_fd.c 2019-03-10 05:38:29.561962546 +0100
@@ -345,6 +345,7 @@
memset(prog_info, 0, PROG_INFO_SZ);
for (unsigned int i = 0; i < 4; i++) {
prog_info->jited_prog_len = 0;
+ memset(prog_info + 1, 0, PROG_INFO_SZ - sizeof(*prog_info));
switch (i) {
case 1:
prog_info->xlated_prog_insns =

View File

@ -1,211 +0,0 @@
From 8967985c6fedf1b0545f81d48c5c232718eb47d2 Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Tue, 29 Jan 2019 13:54:23 +0100
Subject: [PATCH 17/27] Merge "<... resumed>" printing
Apparently, it was slightly different with no apparent reason.
Use a single routine to print this message now.
* defs.h (print_syscall_resume): New function declaration.
* strace.c (print_event_exit): Replace open-coding of "<... resumed>"
message printing with a print_syscall_resume() call.
* syscall.c (syscall_exiting_trace): Likewise.
(print_syscall_resume): New function.
* tests/threads-execve.c: Update expected output.
Additional changes:
tests-m32/threads-execve.c (copy of tests/threads-execve.c)
tests-mx32/threads-execve.c (copy of tests/threads-execve.c)
---
defs.h | 2 ++
strace.c | 7 +------
syscall.c | 35 +++++++++++++++++++++--------------
tests/threads-execve.c | 2 +-
4 files changed, 25 insertions(+), 21 deletions(-)
Index: strace-4.24/defs.h
===================================================================
--- strace-4.24.orig/defs.h 2019-03-10 05:34:58.570075352 +0100
+++ strace-4.24/defs.h 2019-03-10 05:39:18.611471380 +0100
@@ -408,6 +408,8 @@
extern void set_overhead(int);
extern void print_pc(struct tcb *);
+extern void print_syscall_resume(struct tcb *tcp);
+
extern int syscall_entering_decode(struct tcb *);
extern int syscall_entering_trace(struct tcb *, unsigned int *);
extern void syscall_entering_finish(struct tcb *, int);
Index: strace-4.24/strace.c
===================================================================
--- strace-4.24.orig/strace.c 2019-03-10 05:34:58.570075352 +0100
+++ strace-4.24/strace.c 2019-03-10 05:39:18.612471370 +0100
@@ -2191,12 +2191,7 @@
set_current_tcp(tcp);
}
- if ((followfork < 2 && printing_tcp != tcp)
- || (tcp->flags & TCB_REPRINT)) {
- tcp->flags &= ~TCB_REPRINT;
- printleader(tcp);
- tprintf("<... %s resumed>", tcp->s_ent->sys_name);
- }
+ print_syscall_resume(tcp);
if (!(tcp->sys_func_rval & RVAL_DECODED)) {
/*
Index: strace-4.24/syscall.c
===================================================================
--- strace-4.24.orig/syscall.c 2019-03-10 05:34:58.570075352 +0100
+++ strace-4.24/syscall.c 2019-03-10 05:39:18.613471360 +0100
@@ -722,19 +722,9 @@
return get_syscall_result(tcp);
}
-int
-syscall_exiting_trace(struct tcb *tcp, struct timespec *ts, int res)
+void
+print_syscall_resume(struct tcb *tcp)
{
- if (syscall_tampered(tcp) || inject_delay_exit(tcp))
- tamper_with_syscall_exiting(tcp);
-
- if (cflag) {
- count_syscall(tcp, ts);
- if (cflag == CFLAG_ONLY_STATS) {
- return 0;
- }
- }
-
/* If not in -ff mode, and printing_tcp != tcp,
* then the log currently does not end with output
* of _our syscall entry_, but with something else.
@@ -744,11 +734,28 @@
* "strace -ff -oLOG test/threaded_execve" corner case.
* It's the only case when -ff mode needs reprinting.
*/
- if ((followfork < 2 && printing_tcp != tcp) || (tcp->flags & TCB_REPRINT)) {
+ if ((followfork < 2 && printing_tcp != tcp)
+ || (tcp->flags & TCB_REPRINT)) {
tcp->flags &= ~TCB_REPRINT;
printleader(tcp);
- tprintf("<... %s resumed> ", tcp->s_ent->sys_name);
+ tprintf("<... %s resumed>", tcp->s_ent->sys_name);
}
+}
+
+int
+syscall_exiting_trace(struct tcb *tcp, struct timespec *ts, int res)
+{
+ if (syscall_tampered(tcp) || inject_delay_exit(tcp))
+ tamper_with_syscall_exiting(tcp);
+
+ if (cflag) {
+ count_syscall(tcp, ts);
+ if (cflag == CFLAG_ONLY_STATS) {
+ return 0;
+ }
+ }
+
+ print_syscall_resume(tcp);
printing_tcp = tcp;
tcp->s_prev_ent = NULL;
Index: strace-4.24/tests/threads-execve.c
===================================================================
--- strace-4.24.orig/tests/threads-execve.c 2019-03-10 05:34:58.570075352 +0100
+++ strace-4.24/tests/threads-execve.c 2019-03-10 05:39:18.613471360 +0100
@@ -141,7 +141,7 @@
}
printf("%-5d +++ superseded by execve in pid %u +++\n"
- "%-5d <... execve resumed> ) = 0\n",
+ "%-5d <... execve resumed>) = 0\n",
leader, tid,
leader);
Index: strace-4.24/tests-m32/threads-execve.c
===================================================================
--- strace-4.24.orig/tests-m32/threads-execve.c 2017-05-22 19:33:51.000000000 +0200
+++ strace-4.24/tests-m32/threads-execve.c 2019-03-10 05:39:41.348243702 +0100
@@ -5,27 +5,7 @@
* Copyright (c) 2016-2017 The strace developers.
* All rights reserved.
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "tests.h"
@@ -161,7 +141,7 @@
}
printf("%-5d +++ superseded by execve in pid %u +++\n"
- "%-5d <... execve resumed> ) = 0\n",
+ "%-5d <... execve resumed>) = 0\n",
leader, tid,
leader);
Index: strace-4.24/tests-mx32/threads-execve.c
===================================================================
--- strace-4.24.orig/tests-mx32/threads-execve.c 2017-05-22 19:33:51.000000000 +0200
+++ strace-4.24/tests-mx32/threads-execve.c 2019-03-10 05:39:43.817218978 +0100
@@ -5,27 +5,7 @@
* Copyright (c) 2016-2017 The strace developers.
* All rights reserved.
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "tests.h"
@@ -161,7 +141,7 @@
}
printf("%-5d +++ superseded by execve in pid %u +++\n"
- "%-5d <... execve resumed> ) = 0\n",
+ "%-5d <... execve resumed>) = 0\n",
leader, tid,
leader);

View File

@ -1,513 +0,0 @@
From 25e40facc12017de2c4df5792f6a0a3f7db39896 Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Tue, 29 Jan 2019 14:40:11 +0100
Subject: [PATCH 18/27] Use accessors for tcp->s_ent, return a stub struct if
it is NULL
Since code paths are non-trivial, it's an attempt to future-proof
and prevent improper access of tcp->s_ent fields.
* defs.h (struct tcb): Update the description of s_ent field.
(stub_sysent): New declaration.
(tcp_sysent, n_args): New macro functions.
(indirect_ipccall): Use tcp_sysent() instead of tcp->s_ent.
* ipc.c (SYS_FUNC(ipc)): Use n_args() instead of tcp->s_ent->nargs.
* linux/alpha/get_syscall_args.c (get_syscall_args): Likewise.
* linux/bfin/get_syscall_args.c (get_syscall_args): Likewise.
* linux/hppa/get_syscall_args.c (get_syscall_args): Likewise.
* linux/ia64/get_syscall_args.c (get_syscall_args): Likewise.
* linux/microblaze/get_syscall_args.c (get_syscall_args): Likewise.
* linux/mips/get_syscall_args.c (get_syscall_args): Likewise.
* linux/sh/get_syscall_args.c (get_syscall_args): Likewise.
* linux/sh64/get_syscall_args.c (get_syscall_args): Likewise.
* linux/x86_64/get_syscall_args.c (get_syscall_args): Likewise.
* linux/xtensa/get_syscall_args.c (get_syscall_args): Likewise.
* prctl.c (print_prctl_args): Likewise.
* signal.c (SYS_FUNC(sgetmask)): Likewise.
* util.c (printargs, printargs_u, printargs_d): Likewise.
* syscall.c (decode_ipc_subcall, decode_syscall_subcall: Likewise.
(dumpio, tamper_with_syscall_exiting, syscall_entering_decode,
syscall_entering_decode, syscall_entering_trace, syscall_entering_trace,
syscall_exiting_decode, print_syscall_resume, syscall_exiting_trace,
get_syscall_result): Use tcp_sysent() instead of tcp->s_ent.
(stub_sysent): New stub sysent.
(get_scno): Reset scno, s_ent, qual_flg; initialise s->ent from
stub_sysent.
* pathtrace.c (pathtrace_match_set): Use tcp_sysent() instead of
tcp->s_ent.
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
Conflicts:
defs.h
linux/mips/get_syscall_args.c
syscall.c
---
defs.h | 10 ++++++--
ipc.c | 2 +-
linux/alpha/get_syscall_args.c | 2 +-
linux/bfin/get_syscall_args.c | 2 +-
linux/hppa/get_syscall_args.c | 2 +-
linux/ia64/get_syscall_args.c | 2 +-
linux/microblaze/get_syscall_args.c | 2 +-
linux/mips/get_syscall_args.c | 6 ++---
linux/sh/get_syscall_args.c | 2 +-
linux/sh64/get_syscall_args.c | 2 +-
linux/x86_64/get_syscall_args.c | 2 +-
linux/xtensa/get_syscall_args.c | 2 +-
pathtrace.c | 2 +-
prctl.c | 2 +-
signal.c | 4 +--
syscall.c | 49 +++++++++++++++++++++----------------
util.c | 6 ++---
17 files changed, 56 insertions(+), 43 deletions(-)
diff --git a/defs.h b/defs.h
index c7274c8..811bb0d 100644
--- a/defs.h
+++ b/defs.h
@@ -206,7 +206,9 @@ struct tcb {
const char *auxstr; /* Auxiliary info from syscall (see RVAL_STR) */
void *_priv_data; /* Private data for syscall decoding functions */
void (*_free_priv_data)(void *); /* Callback for freeing priv_data */
- const struct_sysent *s_ent; /* sysent[scno] or dummy struct for bad scno */
+ const struct_sysent *s_ent; /* sysent[scno] or a stub struct for bad
+ * scno. Use tcp_sysent() macro for access.
+ */
const struct_sysent *s_prev_ent; /* for "resuming interrupted SYSCALL" msg */
struct inject_opts *inject_vec[SUPPORTED_PERSONALITIES];
struct timespec stime; /* System time usage as of last process wait */
@@ -283,6 +285,10 @@ struct tcb {
#define syscall_delayed(tcp) ((tcp)->flags & TCB_DELAYED)
#define syscall_tampered_nofail(tcp) ((tcp)->flags & TCB_TAMPERED_NO_FAIL)
+extern const struct_sysent stub_sysent;
+#define tcp_sysent(tcp) (tcp->s_ent ?: &stub_sysent)
+#define n_args(tcp) (tcp_sysent(tcp)->nargs)
+
#include "xlat.h"
extern const struct xlat addrfams[];
@@ -352,7 +358,7 @@ extern const struct xlat whence_codes[];
#define IOCTL_NUMBER_HANDLED 1
#define IOCTL_NUMBER_STOP_LOOKUP 010
-#define indirect_ipccall(tcp) (tcp->s_ent->sys_flags & TRACE_INDIRECT_SUBCALL)
+#define indirect_ipccall(tcp) (tcp_sysent(tcp)->sys_flags & TRACE_INDIRECT_SUBCALL)
enum sock_proto {
SOCK_PROTO_UNKNOWN,
diff --git a/ipc.c b/ipc.c
index c35509b..b2b3aa4 100644
--- a/ipc.c
+++ b/ipc.c
@@ -21,7 +21,7 @@ SYS_FUNC(ipc)
printxval_u(ipccalls, call, NULL);
unsigned int i;
- for (i = 1; i < tcp->s_ent->nargs; ++i)
+ for (i = 1; i < n_args(tcp); ++i)
tprintf(", %#" PRI_klx, tcp->u_arg[i]);
return RVAL_DECODED;
diff --git a/linux/alpha/get_syscall_args.c b/linux/alpha/get_syscall_args.c
index be61abf..c28eb62 100644
--- a/linux/alpha/get_syscall_args.c
+++ b/linux/alpha/get_syscall_args.c
@@ -4,7 +4,7 @@ get_syscall_args(struct tcb *tcp)
{
unsigned int i;
- for (i = 0; i < tcp->s_ent->nargs; ++i)
+ for (i = 0; i < n_args(tcp); ++i)
if (upeek(tcp, REG_A0+i, &tcp->u_arg[i]) < 0)
return -1;
return 1;
diff --git a/linux/bfin/get_syscall_args.c b/linux/bfin/get_syscall_args.c
index 506d3a9..bebaf03 100644
--- a/linux/bfin/get_syscall_args.c
+++ b/linux/bfin/get_syscall_args.c
@@ -7,7 +7,7 @@ get_syscall_args(struct tcb *tcp)
};
unsigned int i;
- for (i = 0; i < tcp->s_ent->nargs; ++i)
+ for (i = 0; i < n_args(tcp); ++i)
if (upeek(tcp, argreg[i], &tcp->u_arg[i]) < 0)
return -1;
return 1;
diff --git a/linux/hppa/get_syscall_args.c b/linux/hppa/get_syscall_args.c
index aa938f5..70f2a24 100644
--- a/linux/hppa/get_syscall_args.c
+++ b/linux/hppa/get_syscall_args.c
@@ -4,7 +4,7 @@ get_syscall_args(struct tcb *tcp)
{
unsigned int i;
- for (i = 0; i < tcp->s_ent->nargs; ++i)
+ for (i = 0; i < n_args(tcp); ++i)
if (upeek(tcp, PT_GR26-4*i, &tcp->u_arg[i]) < 0)
return -1;
return 1;
diff --git a/linux/ia64/get_syscall_args.c b/linux/ia64/get_syscall_args.c
index ad73c54..eeeb59c 100644
--- a/linux/ia64/get_syscall_args.c
+++ b/linux/ia64/get_syscall_args.c
@@ -11,7 +11,7 @@ get_syscall_args(struct tcb *tcp)
unsigned long *out0 = ia64_rse_skip_regs(rbs_end, -sof + sol);
unsigned int i;
- for (i = 0; i < tcp->s_ent->nargs; ++i) {
+ for (i = 0; i < n_args(tcp); ++i) {
if (umove(tcp,
(unsigned long) ia64_rse_skip_regs(out0, i),
&tcp->u_arg[i]) < 0) {
diff --git a/linux/microblaze/get_syscall_args.c b/linux/microblaze/get_syscall_args.c
index 1a3a48f..0e249e3 100644
--- a/linux/microblaze/get_syscall_args.c
+++ b/linux/microblaze/get_syscall_args.c
@@ -4,7 +4,7 @@ get_syscall_args(struct tcb *tcp)
{
unsigned int i;
- for (i = 0; i < tcp->s_ent->nargs; ++i)
+ for (i = 0; i < n_args(tcp); ++i)
if (upeek(tcp, (5 + i) * 4, &tcp->u_arg[i]) < 0)
return -1;
return 1;
diff --git a/linux/mips/get_syscall_args.c b/linux/mips/get_syscall_args.c
index 3c9160e..0ff5136 100644
--- a/linux/mips/get_syscall_args.c
+++ b/linux/mips/get_syscall_args.c
@@ -14,16 +14,16 @@ get_syscall_args(struct tcb *tcp)
tcp->u_arg[1] = mips_REG_A1;
tcp->u_arg[2] = mips_REG_A2;
tcp->u_arg[3] = mips_REG_A3;
- if (tcp->s_ent->nargs > 4
+ if (n_args(tcp) > 4
&& umoven(tcp, mips_REG_SP + 4 * sizeof(tcp->u_arg[0]),
- (tcp->s_ent->nargs - 4) * sizeof(tcp->u_arg[0]),
+ (n_args(tcp) - 4) * sizeof(tcp->u_arg[0]),
&tcp->u_arg[4]) < 0) {
/*
* Let's proceed with the first 4 arguments
* instead of reporting the failure.
*/
memset(&tcp->u_arg[4], 0,
- (tcp->s_ent->nargs - 4) * sizeof(tcp->u_arg[0]));
+ (n_args(tcp) - 4) * sizeof(tcp->u_arg[0]));
}
#else
# error unsupported mips abi
diff --git a/linux/sh/get_syscall_args.c b/linux/sh/get_syscall_args.c
index b4ee1dd..02593b0 100644
--- a/linux/sh/get_syscall_args.c
+++ b/linux/sh/get_syscall_args.c
@@ -12,7 +12,7 @@ get_syscall_args(struct tcb *tcp)
};
unsigned int i;
- for (i = 0; i < tcp->s_ent->nargs; ++i)
+ for (i = 0; i < n_args(tcp); ++i)
if (upeek(tcp, syscall_regs[i], &tcp->u_arg[i]) < 0)
return -1;
return 1;
diff --git a/linux/sh64/get_syscall_args.c b/linux/sh64/get_syscall_args.c
index e35c350..241ff09 100644
--- a/linux/sh64/get_syscall_args.c
+++ b/linux/sh64/get_syscall_args.c
@@ -6,7 +6,7 @@ get_syscall_args(struct tcb *tcp)
static const int syscall_regs[MAX_ARGS] = { 2, 3, 4, 5, 6, 7 };
unsigned int i;
- for (i = 0; i < tcp->s_ent->nargs; ++i)
+ for (i = 0; i < n_args(tcp); ++i)
if (upeek(tcp, REG_GENERAL(syscall_regs[i]),
&tcp->u_arg[i]) < 0)
return -1;
diff --git a/linux/x86_64/get_syscall_args.c b/linux/x86_64/get_syscall_args.c
index f285ac3..8ee8ebd 100644
--- a/linux/x86_64/get_syscall_args.c
+++ b/linux/x86_64/get_syscall_args.c
@@ -4,7 +4,7 @@ get_syscall_args(struct tcb *tcp)
{
if (x86_io.iov_len != sizeof(i386_regs)) {
/* x86-64 or x32 ABI */
- if (tcp->s_ent->sys_flags & COMPAT_SYSCALL_TYPES) {
+ if (tcp_sysent(tcp)->sys_flags & COMPAT_SYSCALL_TYPES) {
/*
* X32 compat syscall: zero-extend from 32 bits.
* Use truncate_klong_to_current_wordsize(tcp->u_arg[N])
diff --git a/linux/xtensa/get_syscall_args.c b/linux/xtensa/get_syscall_args.c
index 2a20cdb..6903221 100644
--- a/linux/xtensa/get_syscall_args.c
+++ b/linux/xtensa/get_syscall_args.c
@@ -13,7 +13,7 @@ get_syscall_args(struct tcb *tcp)
};
unsigned int i;
- for (i = 0; i < tcp->s_ent->nargs; ++i)
+ for (i = 0; i < n_args(tcp); ++i)
if (upeek(tcp, xtensaregs[i], &tcp->u_arg[i]) < 0)
return -1;
return 1;
diff --git a/pathtrace.c b/pathtrace.c
index 2cd12e6..5493028 100644
--- a/pathtrace.c
+++ b/pathtrace.c
@@ -167,7 +167,7 @@ pathtrace_match_set(struct tcb *tcp, struct path_set *set)
{
const struct_sysent *s;
- s = tcp->s_ent;
+ s = tcp_sysent(tcp);
if (!(s->sys_flags & (TRACE_FILE | TRACE_DESC | TRACE_NETWORK)))
return false;
diff --git a/prctl.c b/prctl.c
index 5830f11..c31ea60 100644
--- a/prctl.c
+++ b/prctl.c
@@ -61,7 +61,7 @@ print_prctl_args(struct tcb *tcp, const unsigned int first)
{
unsigned int i;
- for (i = first; i < tcp->s_ent->nargs; ++i)
+ for (i = first; i < n_args(tcp); ++i)
tprintf(", %#" PRI_klx, tcp->u_arg[i]);
}
diff --git a/signal.c b/signal.c
index 17a3f79..e59a76d 100644
--- a/signal.c
+++ b/signal.c
@@ -383,10 +383,10 @@ SYS_FUNC(sgetmask)
SYS_FUNC(sigsuspend)
{
#ifdef MIPS
- print_sigset_addr_len(tcp, tcp->u_arg[tcp->s_ent->nargs - 1],
+ print_sigset_addr_len(tcp, tcp->u_arg[n_args(tcp) - 1],
current_wordsize);
#else
- tprint_old_sigmask_val("", tcp->u_arg[tcp->s_ent->nargs - 1]);
+ tprint_old_sigmask_val("", tcp->u_arg[n_args(tcp) - 1]);
#endif
return RVAL_DECODED;
diff --git a/syscall.c b/syscall.c
index 33f6dcd..40fcedb 100644
--- a/syscall.c
+++ b/syscall.c
@@ -339,7 +339,7 @@ decode_ipc_subcall(struct tcb *tcp)
tcp->qual_flg = qual_flags(tcp->scno);
tcp->s_ent = &sysent[tcp->scno];
- const unsigned int n = tcp->s_ent->nargs;
+ const unsigned int n = n_args(tcp);
unsigned int i;
for (i = 0; i < n; i++)
tcp->u_arg[i] = tcp->u_arg[i + 1];
@@ -363,7 +363,7 @@ decode_syscall_subcall(struct tcb *tcp)
* and sync_file_range) requires additional code,
* see linux/mips/get_syscall_args.c
*/
- if (tcp->s_ent->nargs == MAX_ARGS) {
+ if (n_args(tcp) == MAX_ARGS) {
if (umoven(tcp,
mips_REG_SP + MAX_ARGS * sizeof(tcp->u_arg[0]),
sizeof(tcp->u_arg[0]),
@@ -382,7 +382,7 @@ dumpio(struct tcb *tcp)
return;
if (is_number_in_set(fd, write_set)) {
- switch (tcp->s_ent->sen) {
+ switch (tcp_sysent(tcp)->sen) {
case SEN_write:
case SEN_pwrite:
case SEN_send:
@@ -409,7 +409,7 @@ dumpio(struct tcb *tcp)
return;
if (is_number_in_set(fd, read_set)) {
- switch (tcp->s_ent->sen) {
+ switch (tcp_sysent(tcp)->sen) {
case SEN_read:
case SEN_pread:
case SEN_recv:
@@ -573,7 +573,7 @@ tamper_with_syscall_exiting(struct tcb *tcp)
if (update_tcb) {
tcp->u_error = 0;
- get_error(tcp, !(tcp->s_ent->sys_flags & SYSCALL_NEVER_FAILS));
+ get_error(tcp, !(tcp_sysent(tcp)->sys_flags & SYSCALL_NEVER_FAILS));
}
return 0;
@@ -593,10 +593,9 @@ syscall_entering_decode(struct tcb *tcp)
int res = get_scno(tcp);
if (res == 0)
return res;
- int scno_good = res;
if (res != 1 || (res = get_syscall_args(tcp)) != 1) {
printleader(tcp);
- tprintf("%s(", scno_good == 1 ? tcp->s_ent->sys_name : "????");
+ tprintf("%s(", tcp_sysent(tcp)->sys_name);
/*
* " <unavailable>" will be added later by the code which
* detects ptrace errors.
@@ -608,7 +607,7 @@ syscall_entering_decode(struct tcb *tcp)
|| defined SYS_socket_subcall \
|| defined SYS_syscall_subcall
for (;;) {
- switch (tcp->s_ent->sen) {
+ switch (tcp_sysent(tcp)->sen) {
# ifdef SYS_ipc_subcall
case SEN_ipc:
decode_ipc_subcall(tcp);
@@ -622,7 +621,7 @@ syscall_entering_decode(struct tcb *tcp)
# ifdef SYS_syscall_subcall
case SEN_syscall:
decode_syscall_subcall(tcp);
- if (tcp->s_ent->sen != SEN_syscall)
+ if (tcp_sysent(tcp)->sen != SEN_syscall)
continue;
break;
# endif
@@ -642,7 +641,7 @@ syscall_entering_trace(struct tcb *tcp, unsigned int *sig)
tcp->qual_flg &= ~QUAL_INJECT;
}
- switch (tcp->s_ent->sen) {
+ switch (tcp_sysent(tcp)->sen) {
case SEN_execve:
case SEN_execveat:
#if defined SPARC || defined SPARC64
@@ -672,14 +671,14 @@ syscall_entering_trace(struct tcb *tcp, unsigned int *sig)
#ifdef ENABLE_STACKTRACE
if (stack_trace_enabled) {
- if (tcp->s_ent->sys_flags & STACKTRACE_CAPTURE_ON_ENTER)
+ if (tcp_sysent(tcp)->sys_flags & STACKTRACE_CAPTURE_ON_ENTER)
unwind_tcb_capture(tcp);
}
#endif
printleader(tcp);
- tprintf("%s(", tcp->s_ent->sys_name);
- int res = raw(tcp) ? printargs(tcp) : tcp->s_ent->sys_func(tcp);
+ tprintf("%s(", tcp_sysent(tcp)->sys_name);
+ int res = raw(tcp) ? printargs(tcp) : tcp_sysent(tcp)->sys_func(tcp);
fflush(tcp->outf);
return res;
}
@@ -709,7 +708,7 @@ syscall_exiting_decode(struct tcb *tcp, struct timespec *pts)
if ((Tflag || cflag) && !(filtered(tcp) || hide_log(tcp)))
clock_gettime(CLOCK_MONOTONIC, pts);
- if (tcp->s_ent->sys_flags & MEMORY_MAPPING_CHANGE)
+ if (tcp_sysent(tcp)->sys_flags & MEMORY_MAPPING_CHANGE)
mmap_notify_report(tcp);
if (filtered(tcp) || hide_log(tcp))
@@ -738,7 +737,7 @@ print_syscall_resume(struct tcb *tcp)
|| (tcp->flags & TCB_REPRINT)) {
tcp->flags &= ~TCB_REPRINT;
printleader(tcp);
- tprintf("<... %s resumed>", tcp->s_ent->sys_name);
+ tprintf("<... %s resumed>", tcp_sysent(tcp)->sys_name);
}
}
@@ -786,7 +785,7 @@ syscall_exiting_trace(struct tcb *tcp, struct timespec *ts, int res)
if (tcp->sys_func_rval & RVAL_DECODED)
sys_res = tcp->sys_func_rval;
else
- sys_res = tcp->s_ent->sys_func(tcp);
+ sys_res = tcp_sysent(tcp)->sys_func(tcp);
}
tprints(") ");
@@ -1175,6 +1174,13 @@ free_sysent_buf(void *ptr)
free(ptr);
}
+const struct_sysent stub_sysent = {
+ .nargs = MAX_ARGS,
+ .sen = SEN_printargs,
+ .sys_func = printargs,
+ .sys_name = "????",
+};
+
/*
* Returns:
* 0: "ignore this ptrace stop", syscall_entering_decode() should return a "bail
@@ -1186,6 +1192,10 @@ free_sysent_buf(void *ptr)
int
get_scno(struct tcb *tcp)
{
+ tcp->scno = -1;
+ tcp->s_ent = NULL;
+ tcp->qual_flg = QUAL_RAW | DEFAULT_QUAL_FLAGS;
+
if (get_regs(tcp) < 0)
return -1;
@@ -1202,14 +1212,11 @@ get_scno(struct tcb *tcp)
struct sysent_buf *s = xcalloc(1, sizeof(*s));
s->tcp = tcp;
- s->ent.nargs = MAX_ARGS;
- s->ent.sen = SEN_printargs;
- s->ent.sys_func = printargs;
+ s->ent = stub_sysent;
s->ent.sys_name = s->buf;
xsprintf(s->buf, "syscall_%#" PRI_klx, shuffle_scno(tcp->scno));
tcp->s_ent = &s->ent;
- tcp->qual_flg = QUAL_RAW | DEFAULT_QUAL_FLAGS;
set_tcb_priv_data(tcp, s, free_sysent_buf);
@@ -1246,7 +1253,7 @@ get_syscall_result(struct tcb *tcp)
return -1;
tcp->u_error = 0;
get_error(tcp,
- (!(tcp->s_ent->sys_flags & SYSCALL_NEVER_FAILS)
+ (!(tcp_sysent(tcp)->sys_flags & SYSCALL_NEVER_FAILS)
|| syscall_tampered(tcp))
&& !syscall_tampered_nofail(tcp));
diff --git a/util.c b/util.c
index aefedee..b841c0f 100644
--- a/util.c
+++ b/util.c
@@ -1161,7 +1161,7 @@ print_array_ex(struct tcb *const tcp,
int
printargs(struct tcb *tcp)
{
- const int n = tcp->s_ent->nargs;
+ const int n = n_args(tcp);
int i;
for (i = 0; i < n; ++i)
tprintf("%s%#" PRI_klx, i ? ", " : "", tcp->u_arg[i]);
@@ -1171,7 +1171,7 @@ printargs(struct tcb *tcp)
int
printargs_u(struct tcb *tcp)
{
- const int n = tcp->s_ent->nargs;
+ const int n = n_args(tcp);
int i;
for (i = 0; i < n; ++i)
tprintf("%s%u", i ? ", " : "",
@@ -1182,7 +1182,7 @@ printargs_u(struct tcb *tcp)
int
printargs_d(struct tcb *tcp)
{
- const int n = tcp->s_ent->nargs;
+ const int n = n_args(tcp);
int i;
for (i = 0; i < n; ++i)
tprintf("%s%d", i ? ", " : "",
--
2.1.4

View File

@ -1,27 +0,0 @@
From 6f9c98e28df7cbc1e3417908604550956ca76f21 Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Tue, 29 Jan 2019 15:35:00 +0100
Subject: [PATCH 19/27] syscall.c: set MEMORY_MAPPING_CHANGE in stub sysent
As unknown syscalls may incur unknown side effects.
* syscall.c (stub_sysent): Set sys_flags to MEMORY_MAPPING_CHANGE.
---
syscall.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/syscall.c b/syscall.c
index 40fcedb..b836cd6 100644
--- a/syscall.c
+++ b/syscall.c
@@ -1176,6 +1176,7 @@ free_sysent_buf(void *ptr)
const struct_sysent stub_sysent = {
.nargs = MAX_ARGS,
+ .sys_flags = MEMORY_MAPPING_CHANGE,
.sen = SEN_printargs,
.sys_func = printargs,
.sys_name = "????",
--
2.1.4

View File

@ -1,33 +0,0 @@
From 38a060e855568e2990affd5cd37aeda372f79c33 Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Sun, 10 Feb 2019 19:49:46 +0100
Subject: [PATCH 20/27] Make inline message on failed restart attempt more
verbose
Hopefully, now it is less confusing.
* strace.c (ptrace_restart): Provide intent and pid in the inline error
message.
References: https://bugzilla.redhat.com/show_bug.cgi?id=1662936
---
strace.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/strace.c b/strace.c
index 7fe6548..f2aa846 100644
--- a/strace.c
+++ b/strace.c
@@ -380,7 +380,8 @@ ptrace_restart(const unsigned int op, struct tcb *const tcp, unsigned int sig)
* but before we tried to restart it. Log looks ugly.
*/
if (current_tcp && current_tcp->curcol != 0) {
- tprintf(" <ptrace(%s):%s>\n", msg, strerror(err));
+ tprintf(" <Cannot restart pid %d with ptrace(%s): %s>\n",
+ tcp->pid, msg, strerror(err));
line_ended();
}
if (err == ESRCH)
--
2.1.4

View File

@ -1,41 +0,0 @@
From 179063d63c4e1f49dd863db7ec5d70a3fa2a3713 Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Mon, 11 Feb 2019 00:57:38 +0100
Subject: [PATCH 21/27] ptrace_restart: do not print diagnostics when ptrace
returns ESRCH
After some discussion, it was decided that the situation
when the tracee is gone does not worth reporting.
* strace.c (ptrace_restart): Return early if ptrace returned ESRCH.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1662936
---
strace.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/strace.c b/strace.c
index f2aa846..0745838 100644
--- a/strace.c
+++ b/strace.c
@@ -353,7 +353,7 @@ ptrace_restart(const unsigned int op, struct tcb *const tcp, unsigned int sig)
errno = 0;
ptrace(op, tcp->pid, 0L, (unsigned long) sig);
err = errno;
- if (!err)
+ if (!err || err == ESRCH)
return 0;
switch (op) {
@@ -384,8 +384,6 @@ ptrace_restart(const unsigned int op, struct tcb *const tcp, unsigned int sig)
tcp->pid, msg, strerror(err));
line_ended();
}
- if (err == ESRCH)
- return 0;
errno = err;
perror_msg("ptrace(PTRACE_%s,pid:%d,sig:%u)", msg, tcp->pid, sig);
return -1;
--
2.1.4

View File

@ -1,636 +0,0 @@
From f5888ee34b2cca8562d2878dbc6b2db9b8256672 Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Fri, 1 Feb 2019 11:04:51 +0100
Subject: [PATCH 22/27] tests: add kill_child test
This tests repeatedly creates and kills children, so some corner
cases in handling of not-quite-existing processes can be observed.
Previously, strace was crashing in the following situation:
13994 ????( <unfinished ...>
...
13994 <... ???? resumed>) = ?
as tcp->s_ent wasn't initialised on syscall entering and
strace.c:print_event_exit segfaulted when tried to access
tcp->s_ent->sys_name.
* tests/kill_child.c: New file.
* tests/kill_child.test: New test.
* tests/.gitignore: Add kill_child.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(MISC_TESTS): Add kill_child.test.
Skipped files (not present in dist tarball):
tests/.gitignore
Additional changes:
tests/Makefile.in (auto-generated from tests/Makefile.am)
tests-m32/Makefile.in (auto-generated from tests-m32/Makefile.am)
tests-m32/kill_child.c (copy of tests/kill_child.c)
tests-m32/kill_child.test (copy of tests/kill_child.test)
tests-m32/Makefile.in (auto-generted from tests-mx32/Makefile.am)
tests-mx32/kill_child.c (copy of tests/kill_child.c)
tests-mx32/kill_child.test (copy of tests/kill_child.test)
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
---
tests/.gitignore | 1 +
tests/Makefile.am | 2 ++
tests/kill_child.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++
tests/kill_child.test | 31 +++++++++++++++++++++++
4 files changed, 103 insertions(+)
create mode 100644 tests/kill_child.c
create mode 100755 tests/kill_child.test
Index: strace-4.24/tests/Makefile.am
===================================================================
--- strace-4.24.orig/tests/Makefile.am 2019-03-10 05:34:51.995141191 +0100
+++ strace-4.24/tests/Makefile.am 2019-03-10 05:40:37.969676713 +0100
@@ -104,6 +104,7 @@
ioctl_perf-success \
ioctl_rtc-v \
is_linux_mips_n64 \
+ kill_child \
ksysent \
list_sigaction_signum \
localtime \
@@ -299,6 +300,7 @@
get_regs.test \
inject-nf.test \
interactive_block.test \
+ kill_child.test \
ksysent.test \
localtime.test \
opipe.test \
Index: strace-4.24/tests/kill_child.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ strace-4.24/tests/kill_child.c 2019-03-10 05:40:37.970676703 +0100
@@ -0,0 +1,69 @@
+/*
+ * Check for the corner case that previously lead to segfault
+ * due to an attempt to access unitialised tcp->s_ent.
+ *
+ * 13994 ????( <unfinished ...>
+ * ...
+ * 13994 <... ???? resumed>) = ?
+ *
+ * Copyright (c) 2019 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "tests.h"
+
+#include <sched.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/wait.h>
+
+#define ITERS 10000
+#define SC_ITERS 10000
+
+int
+main(void)
+{
+ volatile sig_atomic_t *const mem =
+ mmap(NULL, get_page_size(), PROT_READ | PROT_WRITE,
+ MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+ if (mem == MAP_FAILED)
+ perror_msg_and_fail("mmap");
+
+ for (unsigned int i = 0; i < ITERS; ++i) {
+ mem[0] = mem[1] = 0;
+
+ const pid_t pid = fork();
+ if (pid < 0)
+ perror_msg_and_fail("fork");
+
+ if (!pid) {
+ /* wait for the parent */
+ while (!mem[0])
+ ;
+ /* let the parent know we are running */
+ mem[1] = 1;
+
+ for (unsigned int j = 0; j < SC_ITERS; j++)
+ sched_yield();
+
+ pause();
+ return 0;
+ }
+
+ /* let the child know we are running */
+ mem[0] = 1;
+ /* wait for the child */
+ while (!mem[1])
+ ;
+
+ if (kill(pid, SIGKILL))
+ perror_msg_and_fail("kill");
+ if (wait(NULL) != pid)
+ perror_msg_and_fail("wait");
+ }
+
+ return 0;
+}
Index: strace-4.24/tests/kill_child.test
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ strace-4.24/tests/kill_child.test 2019-03-10 05:40:37.970676703 +0100
@@ -0,0 +1,31 @@
+#!/bin/sh
+#
+# Check whether repeated killing of just forked processes crashes strace.
+#
+# Copyright (c) 2019 The strace developers.
+# All rights reserved.
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+. "${srcdir=.}/init.sh"
+
+run_prog_skip_if_failed date +%s > /dev/null
+s0="$(date +%s)"
+
+run_prog
+args="-f -qq -e signal=none -e trace=sched_yield,/kill $args"
+
+# Run strace until the known corner case is observed.
+while :; do
+ run_strace $args
+
+ # Printing of "<... SYSCALL resumed>" in strace.c:print_event_exit
+ # used to segfault when the syscall number had not been obtained
+ # on syscall entering.
+ grep -q '^[1-9][0-9]* <\.\.\. ???? resumed>) \+= ?$' "$LOG" && exit 0
+
+ s1="$(date +%s)"
+ if [ "$(($s1-$s0))" -gt "$(($TIMEOUT_DURATION/2))" ]; then
+ skip_ 'Unable to reproduce <... ???? resumed>'
+ fi
+done
Index: strace-4.24/tests/Makefile.in
===================================================================
--- strace-4.24.orig/tests/Makefile.in 2019-03-10 05:34:51.995141191 +0100
+++ strace-4.24/tests/Makefile.in 2019-03-10 05:40:37.973676673 +0100
@@ -153,8 +153,9 @@
ioctl_evdev-v$(EXEEXT) ioctl_loop-nv$(EXEEXT) \
ioctl_loop-v$(EXEEXT) ioctl_nsfs$(EXEEXT) \
ioctl_perf-success$(EXEEXT) ioctl_rtc-v$(EXEEXT) \
- is_linux_mips_n64$(EXEEXT) ksysent$(EXEEXT) \
- list_sigaction_signum$(EXEEXT) localtime$(EXEEXT) \
+ is_linux_mips_n64$(EXEEXT) kill_child$(EXEEXT) \
+ ksysent$(EXEEXT) list_sigaction_signum$(EXEEXT) \
+ localtime$(EXEEXT) \
mmsg-silent$(EXEEXT) mmsg_name-v$(EXEEXT) \
msg_control-v$(EXEEXT) net-accept-connect$(EXEEXT) \
net-tpacket_stats-success$(EXEEXT) netlink_inet_diag$(EXEEXT) \
@@ -1186,6 +1187,10 @@
kill_OBJECTS = kill.$(OBJEXT)
kill_LDADD = $(LDADD)
kill_DEPENDENCIES = libtests.a
+kill_child_SOURCES = kill_child.c
+kill_child_OBJECTS = kill_child.$(OBJEXT)
+kill_child_LDADD = $(LDADD)
+kill_child_DEPENDENCIES = libtests.a
ksysent_SOURCES = ksysent.c
ksysent_OBJECTS = ksysent.$(OBJEXT)
ksysent_LDADD = $(LDADD)
@@ -2741,9 +2746,9 @@
ipc_shm.c ipc_shm-Xabbrev.c ipc_shm-Xraw.c ipc_shm-Xverbose.c \
is_linux_mips_n64.c kcmp.c kcmp-y.c kern_features.c \
kexec_file_load.c kexec_load.c keyctl.c keyctl-Xabbrev.c \
- keyctl-Xraw.c keyctl-Xverbose.c kill.c ksysent.c lchown.c \
- lchown32.c link.c linkat.c list_sigaction_signum.c llseek.c \
- localtime.c lookup_dcookie.c lseek.c lstat.c lstat64.c \
+ keyctl-Xraw.c keyctl-Xverbose.c kill.c kill_child.c ksysent.c \
+ lchown.c lchown32.c link.c linkat.c list_sigaction_signum.c \
+ llseek.c localtime.c lookup_dcookie.c lseek.c lstat.c lstat64.c \
madvise.c mbind.c membarrier.c memfd_create.c migrate_pages.c \
mincore.c mkdir.c mkdirat.c mknod.c mknodat.c mlock.c mlock2.c \
mlockall.c mmap.c mmap-Xabbrev.c mmap-Xraw.c mmap-Xverbose.c \
@@ -2886,9 +2891,9 @@
ipc_shm.c ipc_shm-Xabbrev.c ipc_shm-Xraw.c ipc_shm-Xverbose.c \
is_linux_mips_n64.c kcmp.c kcmp-y.c kern_features.c \
kexec_file_load.c kexec_load.c keyctl.c keyctl-Xabbrev.c \
- keyctl-Xraw.c keyctl-Xverbose.c kill.c ksysent.c lchown.c \
- lchown32.c link.c linkat.c list_sigaction_signum.c llseek.c \
- localtime.c lookup_dcookie.c lseek.c lstat.c lstat64.c \
+ keyctl-Xraw.c keyctl-Xverbose.c kill.c kill_child.c ksysent.c \
+ lchown.c lchown32.c link.c linkat.c list_sigaction_signum.c \
+ llseek.c localtime.c lookup_dcookie.c lseek.c lstat.c lstat64.c \
madvise.c mbind.c membarrier.c memfd_create.c migrate_pages.c \
mincore.c mkdir.c mkdirat.c mknod.c mknodat.c mlock.c mlock2.c \
mlockall.c mmap.c mmap-Xabbrev.c mmap-Xraw.c mmap-Xverbose.c \
@@ -4227,6 +4232,7 @@
get_regs.test \
inject-nf.test \
interactive_block.test \
+ kill_child.test \
ksysent.test \
localtime.test \
opipe.test \
@@ -5190,6 +5196,10 @@
@rm -f kill$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(kill_OBJECTS) $(kill_LDADD) $(LIBS)
+kill_child$(EXEEXT): $(kill_child_OBJECTS) $(kill_child_DEPENDENCIES) $(EXTRA_kill_child_DEPENDENCIES)
+ @rm -f kill_child$(EXEEXT)
+ $(AM_V_CCLD)$(LINK) $(kill_child_OBJECTS) $(kill_child_LDADD) $(LIBS)
+
ksysent$(EXEEXT): $(ksysent_OBJECTS) $(ksysent_DEPENDENCIES) $(EXTRA_ksysent_DEPENDENCIES)
@rm -f ksysent$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(ksysent_OBJECTS) $(ksysent_LDADD) $(LIBS)
@@ -6855,6 +6865,7 @@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/keyctl-Xverbose.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/keyctl.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/kill.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/kill_child.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ksysent.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lchown.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lchown32.Po@am__quote@
Index: strace-4.24/tests-m32/Makefile.in
===================================================================
--- strace-4.24.orig/tests-m32/Makefile.in 2018-08-14 02:44:38.000000000 +0200
+++ strace-4.24/tests-m32/Makefile.in 2019-03-10 05:44:56.112091757 +0100
@@ -153,8 +153,9 @@
ioctl_evdev-v$(EXEEXT) ioctl_loop-nv$(EXEEXT) \
ioctl_loop-v$(EXEEXT) ioctl_nsfs$(EXEEXT) \
ioctl_perf-success$(EXEEXT) ioctl_rtc-v$(EXEEXT) \
- is_linux_mips_n64$(EXEEXT) ksysent$(EXEEXT) \
- list_sigaction_signum$(EXEEXT) localtime$(EXEEXT) \
+ is_linux_mips_n64$(EXEEXT) kill_child$(EXEEXT) \
+ ksysent$(EXEEXT) list_sigaction_signum$(EXEEXT) \
+ localtime$(EXEEXT) \
mmsg-silent$(EXEEXT) mmsg_name-v$(EXEEXT) \
msg_control-v$(EXEEXT) net-accept-connect$(EXEEXT) \
net-tpacket_stats-success$(EXEEXT) netlink_inet_diag$(EXEEXT) \
@@ -1186,6 +1187,10 @@
kill_OBJECTS = kill.$(OBJEXT)
kill_LDADD = $(LDADD)
kill_DEPENDENCIES = libtests.a
+kill_child_SOURCES = kill_child.c
+kill_child_OBJECTS = kill_child.$(OBJEXT)
+kill_child_LDADD = $(LDADD)
+kill_child_DEPENDENCIES = libtests.a
ksysent_SOURCES = ksysent.c
ksysent_OBJECTS = ksysent.$(OBJEXT)
ksysent_LDADD = $(LDADD)
@@ -2741,9 +2746,9 @@
ipc_shm.c ipc_shm-Xabbrev.c ipc_shm-Xraw.c ipc_shm-Xverbose.c \
is_linux_mips_n64.c kcmp.c kcmp-y.c kern_features.c \
kexec_file_load.c kexec_load.c keyctl.c keyctl-Xabbrev.c \
- keyctl-Xraw.c keyctl-Xverbose.c kill.c ksysent.c lchown.c \
- lchown32.c link.c linkat.c list_sigaction_signum.c llseek.c \
- localtime.c lookup_dcookie.c lseek.c lstat.c lstat64.c \
+ keyctl-Xraw.c keyctl-Xverbose.c kill.c kill_child.c ksysent.c \
+ lchown.c lchown32.c link.c linkat.c list_sigaction_signum.c \
+ llseek.c localtime.c lookup_dcookie.c lseek.c lstat.c lstat64.c \
madvise.c mbind.c membarrier.c memfd_create.c migrate_pages.c \
mincore.c mkdir.c mkdirat.c mknod.c mknodat.c mlock.c mlock2.c \
mlockall.c mmap.c mmap-Xabbrev.c mmap-Xraw.c mmap-Xverbose.c \
@@ -2886,9 +2891,9 @@
ipc_shm.c ipc_shm-Xabbrev.c ipc_shm-Xraw.c ipc_shm-Xverbose.c \
is_linux_mips_n64.c kcmp.c kcmp-y.c kern_features.c \
kexec_file_load.c kexec_load.c keyctl.c keyctl-Xabbrev.c \
- keyctl-Xraw.c keyctl-Xverbose.c kill.c ksysent.c lchown.c \
- lchown32.c link.c linkat.c list_sigaction_signum.c llseek.c \
- localtime.c lookup_dcookie.c lseek.c lstat.c lstat64.c \
+ keyctl-Xraw.c keyctl-Xverbose.c kill.c kill_child.c ksysent.c \
+ lchown.c lchown32.c link.c linkat.c list_sigaction_signum.c \
+ llseek.c localtime.c lookup_dcookie.c lseek.c lstat.c lstat64.c \
madvise.c mbind.c membarrier.c memfd_create.c migrate_pages.c \
mincore.c mkdir.c mkdirat.c mknod.c mknodat.c mlock.c mlock2.c \
mlockall.c mmap.c mmap-Xabbrev.c mmap-Xraw.c mmap-Xverbose.c \
@@ -4227,6 +4232,7 @@
get_regs.test \
inject-nf.test \
interactive_block.test \
+ kill_child.test \
ksysent.test \
localtime.test \
opipe.test \
@@ -5190,6 +5196,10 @@
@rm -f kill$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(kill_OBJECTS) $(kill_LDADD) $(LIBS)
+kill_child$(EXEEXT): $(kill_child_OBJECTS) $(kill_child_DEPENDENCIES) $(EXTRA_kill_child_DEPENDENCIES)
+ @rm -f kill_child$(EXEEXT)
+ $(AM_V_CCLD)$(LINK) $(kill_child_OBJECTS) $(kill_child_LDADD) $(LIBS)
+
ksysent$(EXEEXT): $(ksysent_OBJECTS) $(ksysent_DEPENDENCIES) $(EXTRA_ksysent_DEPENDENCIES)
@rm -f ksysent$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(ksysent_OBJECTS) $(ksysent_LDADD) $(LIBS)
@@ -6855,6 +6865,7 @@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/keyctl-Xverbose.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/keyctl.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/kill.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/kill_child.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ksysent.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lchown.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lchown32.Po@am__quote@
Index: strace-4.24/tests-m32/kill_child.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ strace-4.24/tests-m32/kill_child.c 2019-03-10 05:41:09.454361435 +0100
@@ -0,0 +1,69 @@
+/*
+ * Check for the corner case that previously lead to segfault
+ * due to an attempt to access unitialised tcp->s_ent.
+ *
+ * 13994 ????( <unfinished ...>
+ * ...
+ * 13994 <... ???? resumed>) = ?
+ *
+ * Copyright (c) 2019 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "tests.h"
+
+#include <sched.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/wait.h>
+
+#define ITERS 10000
+#define SC_ITERS 10000
+
+int
+main(void)
+{
+ volatile sig_atomic_t *const mem =
+ mmap(NULL, get_page_size(), PROT_READ | PROT_WRITE,
+ MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+ if (mem == MAP_FAILED)
+ perror_msg_and_fail("mmap");
+
+ for (unsigned int i = 0; i < ITERS; ++i) {
+ mem[0] = mem[1] = 0;
+
+ const pid_t pid = fork();
+ if (pid < 0)
+ perror_msg_and_fail("fork");
+
+ if (!pid) {
+ /* wait for the parent */
+ while (!mem[0])
+ ;
+ /* let the parent know we are running */
+ mem[1] = 1;
+
+ for (unsigned int j = 0; j < SC_ITERS; j++)
+ sched_yield();
+
+ pause();
+ return 0;
+ }
+
+ /* let the child know we are running */
+ mem[0] = 1;
+ /* wait for the child */
+ while (!mem[1])
+ ;
+
+ if (kill(pid, SIGKILL))
+ perror_msg_and_fail("kill");
+ if (wait(NULL) != pid)
+ perror_msg_and_fail("wait");
+ }
+
+ return 0;
+}
Index: strace-4.24/tests-m32/kill_child.test
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ strace-4.24/tests-m32/kill_child.test 2019-03-10 05:41:25.066205103 +0100
@@ -0,0 +1,31 @@
+#!/bin/sh
+#
+# Check whether repeated killing of just forked processes crashes strace.
+#
+# Copyright (c) 2019 The strace developers.
+# All rights reserved.
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+. "${srcdir=.}/init.sh"
+
+run_prog_skip_if_failed date +%s > /dev/null
+s0="$(date +%s)"
+
+run_prog
+args="-f -qq -e signal=none -e trace=sched_yield,/kill $args"
+
+# Run strace until the known corner case is observed.
+while :; do
+ run_strace $args
+
+ # Printing of "<... SYSCALL resumed>" in strace.c:print_event_exit
+ # used to segfault when the syscall number had not been obtained
+ # on syscall entering.
+ grep -q '^[1-9][0-9]* <\.\.\. ???? resumed>) \+= ?$' "$LOG" && exit 0
+
+ s1="$(date +%s)"
+ if [ "$(($s1-$s0))" -gt "$(($TIMEOUT_DURATION/2))" ]; then
+ skip_ 'Unable to reproduce <... ???? resumed>'
+ fi
+done
Index: strace-4.24/tests-mx32/kill_child.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ strace-4.24/tests-mx32/kill_child.c 2019-03-10 05:41:12.566330273 +0100
@@ -0,0 +1,69 @@
+/*
+ * Check for the corner case that previously lead to segfault
+ * due to an attempt to access unitialised tcp->s_ent.
+ *
+ * 13994 ????( <unfinished ...>
+ * ...
+ * 13994 <... ???? resumed>) = ?
+ *
+ * Copyright (c) 2019 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "tests.h"
+
+#include <sched.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/wait.h>
+
+#define ITERS 10000
+#define SC_ITERS 10000
+
+int
+main(void)
+{
+ volatile sig_atomic_t *const mem =
+ mmap(NULL, get_page_size(), PROT_READ | PROT_WRITE,
+ MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+ if (mem == MAP_FAILED)
+ perror_msg_and_fail("mmap");
+
+ for (unsigned int i = 0; i < ITERS; ++i) {
+ mem[0] = mem[1] = 0;
+
+ const pid_t pid = fork();
+ if (pid < 0)
+ perror_msg_and_fail("fork");
+
+ if (!pid) {
+ /* wait for the parent */
+ while (!mem[0])
+ ;
+ /* let the parent know we are running */
+ mem[1] = 1;
+
+ for (unsigned int j = 0; j < SC_ITERS; j++)
+ sched_yield();
+
+ pause();
+ return 0;
+ }
+
+ /* let the child know we are running */
+ mem[0] = 1;
+ /* wait for the child */
+ while (!mem[1])
+ ;
+
+ if (kill(pid, SIGKILL))
+ perror_msg_and_fail("kill");
+ if (wait(NULL) != pid)
+ perror_msg_and_fail("wait");
+ }
+
+ return 0;
+}
Index: strace-4.24/tests-mx32/kill_child.test
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ strace-4.24/tests-mx32/kill_child.test 2019-03-10 05:41:27.802177706 +0100
@@ -0,0 +1,31 @@
+#!/bin/sh
+#
+# Check whether repeated killing of just forked processes crashes strace.
+#
+# Copyright (c) 2019 The strace developers.
+# All rights reserved.
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+. "${srcdir=.}/init.sh"
+
+run_prog_skip_if_failed date +%s > /dev/null
+s0="$(date +%s)"
+
+run_prog
+args="-f -qq -e signal=none -e trace=sched_yield,/kill $args"
+
+# Run strace until the known corner case is observed.
+while :; do
+ run_strace $args
+
+ # Printing of "<... SYSCALL resumed>" in strace.c:print_event_exit
+ # used to segfault when the syscall number had not been obtained
+ # on syscall entering.
+ grep -q '^[1-9][0-9]* <\.\.\. ???? resumed>) \+= ?$' "$LOG" && exit 0
+
+ s1="$(date +%s)"
+ if [ "$(($s1-$s0))" -gt "$(($TIMEOUT_DURATION/2))" ]; then
+ skip_ 'Unable to reproduce <... ???? resumed>'
+ fi
+done
Index: strace-4.24/tests-mx32/Makefile.in
===================================================================
--- strace-4.24.orig/tests-mx32/Makefile.in 2018-08-14 02:44:38.000000000 +0200
+++ strace-4.24/tests-mx32/Makefile.in 2019-03-10 05:45:49.892553217 +0100
@@ -153,8 +153,9 @@
ioctl_evdev-v$(EXEEXT) ioctl_loop-nv$(EXEEXT) \
ioctl_loop-v$(EXEEXT) ioctl_nsfs$(EXEEXT) \
ioctl_perf-success$(EXEEXT) ioctl_rtc-v$(EXEEXT) \
- is_linux_mips_n64$(EXEEXT) ksysent$(EXEEXT) \
- list_sigaction_signum$(EXEEXT) localtime$(EXEEXT) \
+ is_linux_mips_n64$(EXEEXT) kill_child$(EXEEXT) \
+ ksysent$(EXEEXT) list_sigaction_signum$(EXEEXT) \
+ localtime$(EXEEXT) \
mmsg-silent$(EXEEXT) mmsg_name-v$(EXEEXT) \
msg_control-v$(EXEEXT) net-accept-connect$(EXEEXT) \
net-tpacket_stats-success$(EXEEXT) netlink_inet_diag$(EXEEXT) \
@@ -1186,6 +1187,10 @@
kill_OBJECTS = kill.$(OBJEXT)
kill_LDADD = $(LDADD)
kill_DEPENDENCIES = libtests.a
+kill_child_SOURCES = kill_child.c
+kill_child_OBJECTS = kill_child.$(OBJEXT)
+kill_child_LDADD = $(LDADD)
+kill_child_DEPENDENCIES = libtests.a
ksysent_SOURCES = ksysent.c
ksysent_OBJECTS = ksysent.$(OBJEXT)
ksysent_LDADD = $(LDADD)
@@ -2741,9 +2746,9 @@
ipc_shm.c ipc_shm-Xabbrev.c ipc_shm-Xraw.c ipc_shm-Xverbose.c \
is_linux_mips_n64.c kcmp.c kcmp-y.c kern_features.c \
kexec_file_load.c kexec_load.c keyctl.c keyctl-Xabbrev.c \
- keyctl-Xraw.c keyctl-Xverbose.c kill.c ksysent.c lchown.c \
- lchown32.c link.c linkat.c list_sigaction_signum.c llseek.c \
- localtime.c lookup_dcookie.c lseek.c lstat.c lstat64.c \
+ keyctl-Xraw.c keyctl-Xverbose.c kill.c kill_child.c ksysent.c \
+ lchown.c lchown32.c link.c linkat.c list_sigaction_signum.c \
+ llseek.c localtime.c lookup_dcookie.c lseek.c lstat.c lstat64.c \
madvise.c mbind.c membarrier.c memfd_create.c migrate_pages.c \
mincore.c mkdir.c mkdirat.c mknod.c mknodat.c mlock.c mlock2.c \
mlockall.c mmap.c mmap-Xabbrev.c mmap-Xraw.c mmap-Xverbose.c \
@@ -2886,9 +2891,9 @@
ipc_shm.c ipc_shm-Xabbrev.c ipc_shm-Xraw.c ipc_shm-Xverbose.c \
is_linux_mips_n64.c kcmp.c kcmp-y.c kern_features.c \
kexec_file_load.c kexec_load.c keyctl.c keyctl-Xabbrev.c \
- keyctl-Xraw.c keyctl-Xverbose.c kill.c ksysent.c lchown.c \
- lchown32.c link.c linkat.c list_sigaction_signum.c llseek.c \
- localtime.c lookup_dcookie.c lseek.c lstat.c lstat64.c \
+ keyctl-Xraw.c keyctl-Xverbose.c kill.c kill_child.c ksysent.c \
+ lchown.c lchown32.c link.c linkat.c list_sigaction_signum.c \
+ llseek.c localtime.c lookup_dcookie.c lseek.c lstat.c lstat64.c \
madvise.c mbind.c membarrier.c memfd_create.c migrate_pages.c \
mincore.c mkdir.c mkdirat.c mknod.c mknodat.c mlock.c mlock2.c \
mlockall.c mmap.c mmap-Xabbrev.c mmap-Xraw.c mmap-Xverbose.c \
@@ -4227,6 +4232,7 @@
get_regs.test \
inject-nf.test \
interactive_block.test \
+ kill_child.test \
ksysent.test \
localtime.test \
opipe.test \
@@ -5190,6 +5196,10 @@
@rm -f kill$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(kill_OBJECTS) $(kill_LDADD) $(LIBS)
+kill_child$(EXEEXT): $(kill_child_OBJECTS) $(kill_child_DEPENDENCIES) $(EXTRA_kill_child_DEPENDENCIES)
+ @rm -f kill_child$(EXEEXT)
+ $(AM_V_CCLD)$(LINK) $(kill_child_OBJECTS) $(kill_child_LDADD) $(LIBS)
+
ksysent$(EXEEXT): $(ksysent_OBJECTS) $(ksysent_DEPENDENCIES) $(EXTRA_ksysent_DEPENDENCIES)
@rm -f ksysent$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(ksysent_OBJECTS) $(ksysent_LDADD) $(LIBS)
@@ -6855,6 +6865,7 @@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/keyctl-Xverbose.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/keyctl.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/kill.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/kill_child.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ksysent.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lchown.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lchown32.Po@am__quote@

View File

@ -1,193 +0,0 @@
From ca7fc3695b061c48af1975d14a3e50a87329031a Mon Sep 17 00:00:00 2001
From: "Dmitry V. Levin" <ldv@altlinux.org>
Date: Wed, 6 Mar 2019 16:02:38 +0000
Subject: [PATCH 23/27] tests: move PTRACE_SEIZE check to a separate file
The check is going to be used by another test soon.
* tests/PTRACE_SEIZE.sh: New file.
* tests/detach-stopped.test: Use it.
* tests/Makefile.am (EXTRA_DIST): Add PTRACE_SEIZE.sh.
Conflicts:
tests/Makefile.am
tests/detach-stopped.test
Additional changes:
tests-m32/PTRACE_SEIZE.sh (copy of tests/PTRACE_SEIZE.sh)
tests-m32/detach-stopped.test (copy of tests/detach-stopped.test)
tests-mx32/PTRACE_SEIZE.sh (copy of tests/PTRACE_SEIZE.sh)
tests-mx32/detach-stopped.test (copy of tests/detach-stopped.test)
---
tests/Makefile.am | 1 +
tests/PTRACE_SEIZE.sh | 13 +++++++++++++
tests/detach-stopped.test | 6 +-----
3 files changed, 15 insertions(+), 5 deletions(-)
create mode 100755 tests/PTRACE_SEIZE.sh
Index: strace-4.24/tests/Makefile.am
===================================================================
--- strace-4.24.orig/tests/Makefile.am 2019-03-10 05:40:37.969676713 +0100
+++ strace-4.24/tests/Makefile.am 2019-03-10 05:47:36.446486219 +0100
@@ -361,6 +361,7 @@
EXTRA_DIST = \
COPYING \
GPL-2.0-or-later \
+ PTRACE_SEIZE.sh \
accept_compat.h \
attach-p-cmd.h \
caps-abbrev.awk \
Index: strace-4.24/tests/PTRACE_SEIZE.sh
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ strace-4.24/tests/PTRACE_SEIZE.sh 2019-03-10 05:47:36.447486209 +0100
@@ -0,0 +1,13 @@
+#!/bin/sh
+#
+# Skip the test if PTRACE_SEIZE is not supported.
+#
+# Copyright (c) 2014-2019 The strace developers.
+# All rights reserved.
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+$STRACE -d -enone / > /dev/null 2> "$LOG" ||:
+if grep -x "[^:]*strace: PTRACE_SEIZE doesn't work" "$LOG" > /dev/null; then
+ skip_ "PTRACE_SEIZE doesn't work"
+fi
Index: strace-4.24/tests/detach-stopped.test
===================================================================
--- strace-4.24.orig/tests/detach-stopped.test 2019-03-10 05:34:50.982151335 +0100
+++ strace-4.24/tests/detach-stopped.test 2019-03-10 05:47:36.447486209 +0100
@@ -9,17 +9,13 @@
# SPDX-License-Identifier: GPL-2.0-or-later
. "${srcdir=.}/init.sh"
+. "${srcdir=.}/PTRACE_SEIZE.sh"
run_prog_skip_if_failed \
kill -0 $$
check_prog sleep
-$STRACE -d -enone / > /dev/null 2> "$LOG"
-if grep -x "[^:]*strace: PTRACE_SEIZE doesn't work" "$LOG" > /dev/null; then
- skip_ "PTRACE_SEIZE doesn't work"
-fi
-
set -e
> "$LOG"
Index: strace-4.24/tests-m32/PTRACE_SEIZE.sh
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ strace-4.24/tests-m32/PTRACE_SEIZE.sh 2019-03-10 05:48:20.038049708 +0100
@@ -0,0 +1,13 @@
+#!/bin/sh
+#
+# Skip the test if PTRACE_SEIZE is not supported.
+#
+# Copyright (c) 2014-2019 The strace developers.
+# All rights reserved.
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+$STRACE -d -enone / > /dev/null 2> "$LOG" ||:
+if grep -x "[^:]*strace: PTRACE_SEIZE doesn't work" "$LOG" > /dev/null; then
+ skip_ "PTRACE_SEIZE doesn't work"
+fi
Index: strace-4.24/tests-m32/detach-stopped.test
===================================================================
--- strace-4.24.orig/tests-m32/detach-stopped.test 2017-05-22 19:33:51.000000000 +0200
+++ strace-4.24/tests-m32/detach-stopped.test 2019-03-10 05:48:30.588944054 +0100
@@ -6,40 +6,16 @@
# Copyright (c) 2014-2017 The strace developers.
# All rights reserved.
#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-# 3. The name of the author may not be used to endorse or promote products
-# derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+# SPDX-License-Identifier: GPL-2.0-or-later
. "${srcdir=.}/init.sh"
+. "${srcdir=.}/PTRACE_SEIZE.sh"
run_prog_skip_if_failed \
kill -0 $$
check_prog sleep
-$STRACE -d -enone / > /dev/null 2> "$LOG"
-if grep -x "[^:]*strace: PTRACE_SEIZE doesn't work" "$LOG" > /dev/null; then
- skip_ "PTRACE_SEIZE doesn't work"
-fi
-
set -e
> "$LOG"
Index: strace-4.24/tests-mx32/detach-stopped.test
===================================================================
--- strace-4.24.orig/tests-mx32/detach-stopped.test 2017-05-22 19:33:51.000000000 +0200
+++ strace-4.24/tests-mx32/detach-stopped.test 2019-03-10 05:48:33.040919501 +0100
@@ -6,40 +6,16 @@
# Copyright (c) 2014-2017 The strace developers.
# All rights reserved.
#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-# 3. The name of the author may not be used to endorse or promote products
-# derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+# SPDX-License-Identifier: GPL-2.0-or-later
. "${srcdir=.}/init.sh"
+. "${srcdir=.}/PTRACE_SEIZE.sh"
run_prog_skip_if_failed \
kill -0 $$
check_prog sleep
-$STRACE -d -enone / > /dev/null 2> "$LOG"
-if grep -x "[^:]*strace: PTRACE_SEIZE doesn't work" "$LOG" > /dev/null; then
- skip_ "PTRACE_SEIZE doesn't work"
-fi
-
set -e
> "$LOG"

View File

@ -1,901 +0,0 @@
From 96dc1aa20237b80087f6c9ee29147bb85a5594d9 Mon Sep 17 00:00:00 2001
From: "Dmitry V. Levin" <ldv@altlinux.org>
Date: Wed, 6 Mar 2019 16:02:38 +0000
Subject: [PATCH 24/27] tests: check tracing of orphaned process group
* tests/orphaned_process_group.c: New file.
* tests/.gitignore: Add orphaned_process_group.
* tests/Makefile.am (check_PROGRAMS): Likewise.
* tests/gen_tests.in (orphaned_process_group): New test.
Skipped files (not present in the tarball):
tests/.gitignore
Additional changes:
tests/Makefile.in (generated from tests/Makefile.am)
tests/tests/orphaned_process_group.gen.test (generated from tests/gen_tests.in)
tests-m32/Makefile.in (generated from tests-m32/Makefile.am)
tests-m32/gen_tests.in (copy of tests/gen_tests.in)
tests-m32/orphaned_process_group.c (copy of tests/orphaned_process_group.c)
tests-m32/tests/orphaned_process_group.gen.test (generated from tests-m32/gen_tests.in)
tests-mx32/Makefile.in (generated from tests-mx32/Makefile.am)
tests-mx32/gen_tests.in (copy of tests/gen_tests.in)
tests-mx32/orphaned_process_group.c (copy of tests/orphaned_process_group.c)
tests-mx32/tests/orphaned_process_group.gen.test (generated from tests-mx32/gen_tests.in)
---
tests/.gitignore | 1 +
tests/Makefile.am | 1 +
tests/gen_tests.in | 1 +
tests/orphaned_process_group.c | 155 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 158 insertions(+)
create mode 100644 tests/orphaned_process_group.c
Index: strace-4.24/tests/Makefile.am
===================================================================
--- strace-4.24.orig/tests/Makefile.am 2019-03-10 05:47:36.446486219 +0100
+++ strace-4.24/tests/Makefile.am 2019-03-10 05:50:05.488993755 +0100
@@ -120,6 +120,7 @@
nsyscalls-d \
oldselect-P \
oldselect-efault-P \
+ orphaned_process_group \
pc \
perf_event_open_nonverbose \
perf_event_open_unabbrev \
Index: strace-4.24/tests/gen_tests.in
===================================================================
--- strace-4.24.orig/tests/gen_tests.in 2019-03-10 05:19:26.185411954 +0100
+++ strace-4.24/tests/gen_tests.in 2019-03-10 05:50:05.488993755 +0100
@@ -287,6 +287,7 @@
oldstat -a32 -v -P stat.sample -P /dev/full
open -a30 -P $NAME.sample
openat -a36 -P $NAME.sample
+orphaned_process_group . "${srcdir=.}/PTRACE_SEIZE.sh"; run_strace_match_diff -f -e trace=none -e signal='!chld'
osf_utimes -a21
pause -a8 -esignal=none
perf_event_open -a1
Index: strace-4.24/tests/orphaned_process_group.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ strace-4.24/tests/orphaned_process_group.c 2019-03-10 05:50:05.488993755 +0100
@@ -0,0 +1,155 @@
+/*
+ * Check tracing of orphaned process group.
+ *
+ * Copyright (c) 2019 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "tests.h"
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/wait.h>
+
+#define TIMEOUT 5
+
+static void
+alarm_handler(const int no)
+{
+ error_msg_and_skip("Orphaned process group semantics"
+ " is not supported by the kernel");
+}
+
+int
+main(void)
+{
+ int status;
+
+ /*
+ * Unblock all signals.
+ */
+ static sigset_t mask;
+ if (sigprocmask(SIG_SETMASK, &mask, NULL))
+ perror_msg_and_fail("sigprocmask");
+
+ /*
+ * Create a pipe to track termination of processes.
+ */
+ int pipe_fds[2];
+ if (pipe(pipe_fds))
+ perror_msg_and_fail("pipe");
+
+ /*
+ * Create a leader for its own new process group.
+ */
+ pid_t leader = fork();
+ if (leader < 0)
+ perror_msg_and_fail("fork");
+
+ if (leader) {
+ /*
+ * Close the writing end of the pipe.
+ */
+ close(pipe_fds[1]);
+
+ /*
+ * Install the SIGALRM signal handler.
+ */
+ static const struct sigaction sa = {
+ .sa_handler = alarm_handler
+ };
+ if (sigaction(SIGALRM, &sa, NULL))
+ perror_msg_and_fail("sigaction");
+
+ /*
+ * Set an alarm clock.
+ */
+ alarm(TIMEOUT);
+
+ /*
+ * Wait for termination of the child process.
+ */
+ if (waitpid(leader, &status, 0) != leader)
+ perror_msg_and_fail("waitpid leader");
+ if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+ error_msg_and_fail("waitpid leader: "
+ "unexpected wait status %d",
+ status);
+
+ /*
+ * Wait for termination of all processes
+ * in the process group of the child process.
+ */
+ if (read(pipe_fds[0], &status, sizeof(status)) != 0)
+ perror_msg_and_fail("read");
+
+ /*
+ * At this point all processes are gone.
+ * Let the tracer time to catch up.
+ */
+ alarm(0);
+ sleep(1);
+ return 0;
+ }
+
+ /*
+ * Close the reading end of the pipe.
+ */
+ close(pipe_fds[0]);
+
+ /*
+ * Create a new process group.
+ */
+ if (setpgid(0, 0))
+ perror_msg_and_fail("setpgid");
+
+ /*
+ * When the leader process terminates, the process group becomes orphaned.
+ * If any member of the orphaned process group is stopped, then
+ * a SIGHUP signal followed by a SIGCONT signal is sent to each process
+ * in the orphaned process group.
+ * Create a process in a stopped state to activate this behaviour.
+ */
+ const pid_t stopped = fork();
+ if (stopped < 0)
+ perror_msg_and_fail("fork");
+ if (!stopped) {
+ static const struct sigaction sa = { .sa_handler = SIG_DFL };
+ if (sigaction(SIGHUP, &sa, NULL))
+ perror_msg_and_fail("sigaction");
+
+ raise(SIGSTOP);
+ _exit(0);
+ }
+
+ /*
+ * Wait for the process to stop.
+ */
+ if (waitpid(stopped, &status, WUNTRACED) != stopped)
+ perror_msg_and_fail("waitpid WUNTRACED");
+ if (!WIFSTOPPED(status) || WSTOPSIG(status) != SIGSTOP)
+ error_msg_and_fail("unexpected wait status %d", status);
+
+ /*
+ * Print the expected output.
+ */
+ leader = getpid();
+ printf("%-5d --- %s {si_signo=%s, si_code=SI_TKILL"
+ ", si_pid=%d, si_uid=%u} ---\n",
+ stopped, "SIGSTOP", "SIGSTOP", stopped, geteuid());
+ printf("%-5d --- stopped by SIGSTOP ---\n", stopped);
+ printf("%-5d +++ exited with 0 +++\n", leader);
+ printf("%-5d --- %s {si_signo=%s, si_code=SI_KERNEL} ---\n",
+ stopped, "SIGHUP", "SIGHUP");
+ printf("%-5d +++ killed by %s +++\n", stopped, "SIGHUP");
+ printf("%-5d +++ exited with 0 +++\n", getppid());
+
+ /*
+ * Make the process group orphaned.
+ */
+ return 0;
+}
Index: strace-4.24/tests-m32/orphaned_process_group.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ strace-4.24/tests-m32/orphaned_process_group.c 2019-03-10 05:51:47.527971970 +0100
@@ -0,0 +1,155 @@
+/*
+ * Check tracing of orphaned process group.
+ *
+ * Copyright (c) 2019 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "tests.h"
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/wait.h>
+
+#define TIMEOUT 5
+
+static void
+alarm_handler(const int no)
+{
+ error_msg_and_skip("Orphaned process group semantics"
+ " is not supported by the kernel");
+}
+
+int
+main(void)
+{
+ int status;
+
+ /*
+ * Unblock all signals.
+ */
+ static sigset_t mask;
+ if (sigprocmask(SIG_SETMASK, &mask, NULL))
+ perror_msg_and_fail("sigprocmask");
+
+ /*
+ * Create a pipe to track termination of processes.
+ */
+ int pipe_fds[2];
+ if (pipe(pipe_fds))
+ perror_msg_and_fail("pipe");
+
+ /*
+ * Create a leader for its own new process group.
+ */
+ pid_t leader = fork();
+ if (leader < 0)
+ perror_msg_and_fail("fork");
+
+ if (leader) {
+ /*
+ * Close the writing end of the pipe.
+ */
+ close(pipe_fds[1]);
+
+ /*
+ * Install the SIGALRM signal handler.
+ */
+ static const struct sigaction sa = {
+ .sa_handler = alarm_handler
+ };
+ if (sigaction(SIGALRM, &sa, NULL))
+ perror_msg_and_fail("sigaction");
+
+ /*
+ * Set an alarm clock.
+ */
+ alarm(TIMEOUT);
+
+ /*
+ * Wait for termination of the child process.
+ */
+ if (waitpid(leader, &status, 0) != leader)
+ perror_msg_and_fail("waitpid leader");
+ if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+ error_msg_and_fail("waitpid leader: "
+ "unexpected wait status %d",
+ status);
+
+ /*
+ * Wait for termination of all processes
+ * in the process group of the child process.
+ */
+ if (read(pipe_fds[0], &status, sizeof(status)) != 0)
+ perror_msg_and_fail("read");
+
+ /*
+ * At this point all processes are gone.
+ * Let the tracer time to catch up.
+ */
+ alarm(0);
+ sleep(1);
+ return 0;
+ }
+
+ /*
+ * Close the reading end of the pipe.
+ */
+ close(pipe_fds[0]);
+
+ /*
+ * Create a new process group.
+ */
+ if (setpgid(0, 0))
+ perror_msg_and_fail("setpgid");
+
+ /*
+ * When the leader process terminates, the process group becomes orphaned.
+ * If any member of the orphaned process group is stopped, then
+ * a SIGHUP signal followed by a SIGCONT signal is sent to each process
+ * in the orphaned process group.
+ * Create a process in a stopped state to activate this behaviour.
+ */
+ const pid_t stopped = fork();
+ if (stopped < 0)
+ perror_msg_and_fail("fork");
+ if (!stopped) {
+ static const struct sigaction sa = { .sa_handler = SIG_DFL };
+ if (sigaction(SIGHUP, &sa, NULL))
+ perror_msg_and_fail("sigaction");
+
+ raise(SIGSTOP);
+ _exit(0);
+ }
+
+ /*
+ * Wait for the process to stop.
+ */
+ if (waitpid(stopped, &status, WUNTRACED) != stopped)
+ perror_msg_and_fail("waitpid WUNTRACED");
+ if (!WIFSTOPPED(status) || WSTOPSIG(status) != SIGSTOP)
+ error_msg_and_fail("unexpected wait status %d", status);
+
+ /*
+ * Print the expected output.
+ */
+ leader = getpid();
+ printf("%-5d --- %s {si_signo=%s, si_code=SI_TKILL"
+ ", si_pid=%d, si_uid=%u} ---\n",
+ stopped, "SIGSTOP", "SIGSTOP", stopped, geteuid());
+ printf("%-5d --- stopped by SIGSTOP ---\n", stopped);
+ printf("%-5d +++ exited with 0 +++\n", leader);
+ printf("%-5d --- %s {si_signo=%s, si_code=SI_KERNEL} ---\n",
+ stopped, "SIGHUP", "SIGHUP");
+ printf("%-5d +++ killed by %s +++\n", stopped, "SIGHUP");
+ printf("%-5d +++ exited with 0 +++\n", getppid());
+
+ /*
+ * Make the process group orphaned.
+ */
+ return 0;
+}
Index: strace-4.24/tests-mx32/orphaned_process_group.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ strace-4.24/tests-mx32/orphaned_process_group.c 2019-03-10 05:51:50.259944613 +0100
@@ -0,0 +1,155 @@
+/*
+ * Check tracing of orphaned process group.
+ *
+ * Copyright (c) 2019 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "tests.h"
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/wait.h>
+
+#define TIMEOUT 5
+
+static void
+alarm_handler(const int no)
+{
+ error_msg_and_skip("Orphaned process group semantics"
+ " is not supported by the kernel");
+}
+
+int
+main(void)
+{
+ int status;
+
+ /*
+ * Unblock all signals.
+ */
+ static sigset_t mask;
+ if (sigprocmask(SIG_SETMASK, &mask, NULL))
+ perror_msg_and_fail("sigprocmask");
+
+ /*
+ * Create a pipe to track termination of processes.
+ */
+ int pipe_fds[2];
+ if (pipe(pipe_fds))
+ perror_msg_and_fail("pipe");
+
+ /*
+ * Create a leader for its own new process group.
+ */
+ pid_t leader = fork();
+ if (leader < 0)
+ perror_msg_and_fail("fork");
+
+ if (leader) {
+ /*
+ * Close the writing end of the pipe.
+ */
+ close(pipe_fds[1]);
+
+ /*
+ * Install the SIGALRM signal handler.
+ */
+ static const struct sigaction sa = {
+ .sa_handler = alarm_handler
+ };
+ if (sigaction(SIGALRM, &sa, NULL))
+ perror_msg_and_fail("sigaction");
+
+ /*
+ * Set an alarm clock.
+ */
+ alarm(TIMEOUT);
+
+ /*
+ * Wait for termination of the child process.
+ */
+ if (waitpid(leader, &status, 0) != leader)
+ perror_msg_and_fail("waitpid leader");
+ if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+ error_msg_and_fail("waitpid leader: "
+ "unexpected wait status %d",
+ status);
+
+ /*
+ * Wait for termination of all processes
+ * in the process group of the child process.
+ */
+ if (read(pipe_fds[0], &status, sizeof(status)) != 0)
+ perror_msg_and_fail("read");
+
+ /*
+ * At this point all processes are gone.
+ * Let the tracer time to catch up.
+ */
+ alarm(0);
+ sleep(1);
+ return 0;
+ }
+
+ /*
+ * Close the reading end of the pipe.
+ */
+ close(pipe_fds[0]);
+
+ /*
+ * Create a new process group.
+ */
+ if (setpgid(0, 0))
+ perror_msg_and_fail("setpgid");
+
+ /*
+ * When the leader process terminates, the process group becomes orphaned.
+ * If any member of the orphaned process group is stopped, then
+ * a SIGHUP signal followed by a SIGCONT signal is sent to each process
+ * in the orphaned process group.
+ * Create a process in a stopped state to activate this behaviour.
+ */
+ const pid_t stopped = fork();
+ if (stopped < 0)
+ perror_msg_and_fail("fork");
+ if (!stopped) {
+ static const struct sigaction sa = { .sa_handler = SIG_DFL };
+ if (sigaction(SIGHUP, &sa, NULL))
+ perror_msg_and_fail("sigaction");
+
+ raise(SIGSTOP);
+ _exit(0);
+ }
+
+ /*
+ * Wait for the process to stop.
+ */
+ if (waitpid(stopped, &status, WUNTRACED) != stopped)
+ perror_msg_and_fail("waitpid WUNTRACED");
+ if (!WIFSTOPPED(status) || WSTOPSIG(status) != SIGSTOP)
+ error_msg_and_fail("unexpected wait status %d", status);
+
+ /*
+ * Print the expected output.
+ */
+ leader = getpid();
+ printf("%-5d --- %s {si_signo=%s, si_code=SI_TKILL"
+ ", si_pid=%d, si_uid=%u} ---\n",
+ stopped, "SIGSTOP", "SIGSTOP", stopped, geteuid());
+ printf("%-5d --- stopped by SIGSTOP ---\n", stopped);
+ printf("%-5d +++ exited with 0 +++\n", leader);
+ printf("%-5d --- %s {si_signo=%s, si_code=SI_KERNEL} ---\n",
+ stopped, "SIGHUP", "SIGHUP");
+ printf("%-5d +++ killed by %s +++\n", stopped, "SIGHUP");
+ printf("%-5d +++ exited with 0 +++\n", getppid());
+
+ /*
+ * Make the process group orphaned.
+ */
+ return 0;
+}
Index: strace-4.24/tests/Makefile.in
===================================================================
--- strace-4.24.orig/tests/Makefile.in 2019-03-10 05:40:37.973676673 +0100
+++ strace-4.24/tests/Makefile.in 2019-03-10 05:56:10.763336015 +0100
@@ -161,8 +161,8 @@
net-tpacket_stats-success$(EXEEXT) netlink_inet_diag$(EXEEXT) \
netlink_netlink_diag$(EXEEXT) netlink_unix_diag$(EXEEXT) \
nsyscalls$(EXEEXT) nsyscalls-d$(EXEEXT) oldselect-P$(EXEEXT) \
- oldselect-efault-P$(EXEEXT) pc$(EXEEXT) \
- perf_event_open_nonverbose$(EXEEXT) \
+ oldselect-efault-P$(EXEEXT) orphaned_process_group$(EXEEXT) \
+ pc$(EXEEXT) perf_event_open_nonverbose$(EXEEXT) \
perf_event_open_unabbrev$(EXEEXT) ppoll-v$(EXEEXT) \
prctl-seccomp-filter-v$(EXEEXT) prctl-seccomp-strict$(EXEEXT) \
prctl-spec-inject$(EXEEXT) print_maxfd$(EXEEXT) \
@@ -1743,6 +1743,10 @@
openat_OBJECTS = openat.$(OBJEXT)
openat_LDADD = $(LDADD)
openat_DEPENDENCIES = libtests.a
+orphaned_process_group_SOURCES = orphaned_process_group.c
+orphaned_process_group_OBJECTS = orphaned_process_group.$(OBJEXT)
+orphaned_process_group_LDADD = $(LDADD)
+orphaned_process_group_DEPENDENCIES = libtests.a
osf_utimes_SOURCES = osf_utimes.c
osf_utimes_OBJECTS = osf_utimes.$(OBJEXT)
osf_utimes_LDADD = $(LDADD)
@@ -2786,7 +2790,8 @@
old_mmap-P.c old_mmap-Xabbrev.c old_mmap-Xraw.c \
old_mmap-Xverbose.c old_mmap-v-none.c oldfstat.c oldlstat.c \
oldselect.c oldselect-P.c oldselect-efault.c \
- oldselect-efault-P.c oldstat.c open.c openat.c osf_utimes.c \
+ oldselect-efault-P.c oldstat.c open.c openat.c \
+ orphaned_process_group.c osf_utimes.c \
pause.c pc.c perf_event_open.c perf_event_open_nonverbose.c \
perf_event_open_unabbrev.c personality.c personality-Xabbrev.c \
personality-Xraw.c personality-Xverbose.c pipe.c pipe2.c \
@@ -2931,7 +2936,8 @@
old_mmap-P.c old_mmap-Xabbrev.c old_mmap-Xraw.c \
old_mmap-Xverbose.c old_mmap-v-none.c oldfstat.c oldlstat.c \
oldselect.c oldselect-P.c oldselect-efault.c \
- oldselect-efault-P.c oldstat.c open.c openat.c osf_utimes.c \
+ oldselect-efault-P.c oldstat.c open.c openat.c \
+ orphaned_process_group.c osf_utimes.c \
pause.c pc.c perf_event_open.c perf_event_open_nonverbose.c \
perf_event_open_unabbrev.c personality.c personality-Xabbrev.c \
personality-Xraw.c personality-Xverbose.c pipe.c pipe2.c \
@@ -4058,7 +4064,8 @@
oldselect.gen.test oldselect-P.gen.test \
oldselect-efault.gen.test oldselect-efault-P.gen.test \
oldstat.gen.test open.gen.test openat.gen.test \
- osf_utimes.gen.test pause.gen.test perf_event_open.gen.test \
+ orphaned_process_group.gen.test osf_utimes.gen.test \
+ pause.gen.test perf_event_open.gen.test \
perf_event_open_nonverbose.gen.test \
perf_event_open_unabbrev.gen.test personality-Xabbrev.gen.test \
personality-Xraw.gen.test personality-Xverbose.gen.test \
@@ -5752,6 +5759,10 @@
@rm -f openat$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(openat_OBJECTS) $(openat_LDADD) $(LIBS)
+orphaned_process_group$(EXEEXT): $(orphaned_process_group_OBJECTS) $(orphaned_process_group_DEPENDENCIES) $(EXTRA_orphaned_process_group_DEPENDENCIES)
+ @rm -f orphaned_process_group$(EXEEXT)
+ $(AM_V_CCLD)$(LINK) $(orphaned_process_group_OBJECTS) $(orphaned_process_group_LDADD) $(LIBS)
+
osf_utimes$(EXEEXT): $(osf_utimes_OBJECTS) $(osf_utimes_DEPENDENCIES) $(EXTRA_osf_utimes_DEPENDENCIES)
@rm -f osf_utimes$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(osf_utimes_OBJECTS) $(osf_utimes_LDADD) $(LIBS)
@@ -7030,6 +7041,7 @@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oldstat.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/open.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/openat.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/orphaned_process_group.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/osf_utimes.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pause.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pc.Po@am__quote@
@@ -9128,6 +9140,9 @@
$(srcdir)/openat.gen.test: $(abs_srcdir)/gen_tests.sh $(srcdir)/gen_tests.in
$(AM_V_GEN) $^ $@
+$(srcdir)/orphaned_process_group.gen.test: $(abs_srcdir)/gen_tests.sh $(srcdir)/gen_tests.in
+ $(AM_V_GEN) $^ $@
+
$(srcdir)/osf_utimes.gen.test: $(abs_srcdir)/gen_tests.sh $(srcdir)/gen_tests.in
$(AM_V_GEN) $^ $@
Index: strace-4.24/tests-m32/Makefile.in
===================================================================
--- strace-4.24.orig/tests-m32/Makefile.in 2019-03-10 05:44:56.112091757 +0100
+++ strace-4.24/tests-m32/Makefile.in 2019-03-10 05:57:09.322749620 +0100
@@ -161,8 +161,8 @@
net-tpacket_stats-success$(EXEEXT) netlink_inet_diag$(EXEEXT) \
netlink_netlink_diag$(EXEEXT) netlink_unix_diag$(EXEEXT) \
nsyscalls$(EXEEXT) nsyscalls-d$(EXEEXT) oldselect-P$(EXEEXT) \
- oldselect-efault-P$(EXEEXT) pc$(EXEEXT) \
- perf_event_open_nonverbose$(EXEEXT) \
+ oldselect-efault-P$(EXEEXT) orphaned_process_group$(EXEEXT) \
+ pc$(EXEEXT) perf_event_open_nonverbose$(EXEEXT) \
perf_event_open_unabbrev$(EXEEXT) ppoll-v$(EXEEXT) \
prctl-seccomp-filter-v$(EXEEXT) prctl-seccomp-strict$(EXEEXT) \
prctl-spec-inject$(EXEEXT) print_maxfd$(EXEEXT) \
@@ -1743,6 +1743,10 @@
openat_OBJECTS = openat.$(OBJEXT)
openat_LDADD = $(LDADD)
openat_DEPENDENCIES = libtests.a
+orphaned_process_group_SOURCES = orphaned_process_group.c
+orphaned_process_group_OBJECTS = orphaned_process_group.$(OBJEXT)
+orphaned_process_group_LDADD = $(LDADD)
+orphaned_process_group_DEPENDENCIES = libtests.a
osf_utimes_SOURCES = osf_utimes.c
osf_utimes_OBJECTS = osf_utimes.$(OBJEXT)
osf_utimes_LDADD = $(LDADD)
@@ -2786,7 +2790,8 @@
old_mmap-P.c old_mmap-Xabbrev.c old_mmap-Xraw.c \
old_mmap-Xverbose.c old_mmap-v-none.c oldfstat.c oldlstat.c \
oldselect.c oldselect-P.c oldselect-efault.c \
- oldselect-efault-P.c oldstat.c open.c openat.c osf_utimes.c \
+ oldselect-efault-P.c oldstat.c open.c openat.c \
+ orphaned_process_group.c osf_utimes.c \
pause.c pc.c perf_event_open.c perf_event_open_nonverbose.c \
perf_event_open_unabbrev.c personality.c personality-Xabbrev.c \
personality-Xraw.c personality-Xverbose.c pipe.c pipe2.c \
@@ -2931,7 +2936,8 @@
old_mmap-P.c old_mmap-Xabbrev.c old_mmap-Xraw.c \
old_mmap-Xverbose.c old_mmap-v-none.c oldfstat.c oldlstat.c \
oldselect.c oldselect-P.c oldselect-efault.c \
- oldselect-efault-P.c oldstat.c open.c openat.c osf_utimes.c \
+ oldselect-efault-P.c oldstat.c open.c openat.c \
+ orphaned_process_group.c osf_utimes.c \
pause.c pc.c perf_event_open.c perf_event_open_nonverbose.c \
perf_event_open_unabbrev.c personality.c personality-Xabbrev.c \
personality-Xraw.c personality-Xverbose.c pipe.c pipe2.c \
@@ -4058,7 +4064,8 @@
oldselect.gen.test oldselect-P.gen.test \
oldselect-efault.gen.test oldselect-efault-P.gen.test \
oldstat.gen.test open.gen.test openat.gen.test \
- osf_utimes.gen.test pause.gen.test perf_event_open.gen.test \
+ orphaned_process_group.gen.test osf_utimes.gen.test \
+ pause.gen.test perf_event_open.gen.test \
perf_event_open_nonverbose.gen.test \
perf_event_open_unabbrev.gen.test personality-Xabbrev.gen.test \
personality-Xraw.gen.test personality-Xverbose.gen.test \
@@ -5752,6 +5759,10 @@
@rm -f openat$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(openat_OBJECTS) $(openat_LDADD) $(LIBS)
+orphaned_process_group$(EXEEXT): $(orphaned_process_group_OBJECTS) $(orphaned_process_group_DEPENDENCIES) $(EXTRA_orphaned_process_group_DEPENDENCIES)
+ @rm -f orphaned_process_group$(EXEEXT)
+ $(AM_V_CCLD)$(LINK) $(orphaned_process_group_OBJECTS) $(orphaned_process_group_LDADD) $(LIBS)
+
osf_utimes$(EXEEXT): $(osf_utimes_OBJECTS) $(osf_utimes_DEPENDENCIES) $(EXTRA_osf_utimes_DEPENDENCIES)
@rm -f osf_utimes$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(osf_utimes_OBJECTS) $(osf_utimes_LDADD) $(LIBS)
@@ -7030,6 +7041,7 @@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oldstat.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/open.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/openat.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/orphaned_process_group.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/osf_utimes.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pause.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pc.Po@am__quote@
@@ -9128,6 +9140,9 @@
$(srcdir)/openat.gen.test: $(abs_srcdir)/gen_tests.sh $(srcdir)/gen_tests.in
$(AM_V_GEN) $^ $@
+$(srcdir)/orphaned_process_group.gen.test: $(abs_srcdir)/gen_tests.sh $(srcdir)/gen_tests.in
+ $(AM_V_GEN) $^ $@
+
$(srcdir)/osf_utimes.gen.test: $(abs_srcdir)/gen_tests.sh $(srcdir)/gen_tests.in
$(AM_V_GEN) $^ $@
Index: strace-4.24/tests-mx32/Makefile.in
===================================================================
--- strace-4.24.orig/tests-mx32/Makefile.in 2019-03-10 05:45:49.892553217 +0100
+++ strace-4.24/tests-mx32/Makefile.in 2019-03-10 05:57:19.939643305 +0100
@@ -161,8 +161,8 @@
net-tpacket_stats-success$(EXEEXT) netlink_inet_diag$(EXEEXT) \
netlink_netlink_diag$(EXEEXT) netlink_unix_diag$(EXEEXT) \
nsyscalls$(EXEEXT) nsyscalls-d$(EXEEXT) oldselect-P$(EXEEXT) \
- oldselect-efault-P$(EXEEXT) pc$(EXEEXT) \
- perf_event_open_nonverbose$(EXEEXT) \
+ oldselect-efault-P$(EXEEXT) orphaned_process_group$(EXEEXT) \
+ pc$(EXEEXT) perf_event_open_nonverbose$(EXEEXT) \
perf_event_open_unabbrev$(EXEEXT) ppoll-v$(EXEEXT) \
prctl-seccomp-filter-v$(EXEEXT) prctl-seccomp-strict$(EXEEXT) \
prctl-spec-inject$(EXEEXT) print_maxfd$(EXEEXT) \
@@ -1743,6 +1743,10 @@
openat_OBJECTS = openat.$(OBJEXT)
openat_LDADD = $(LDADD)
openat_DEPENDENCIES = libtests.a
+orphaned_process_group_SOURCES = orphaned_process_group.c
+orphaned_process_group_OBJECTS = orphaned_process_group.$(OBJEXT)
+orphaned_process_group_LDADD = $(LDADD)
+orphaned_process_group_DEPENDENCIES = libtests.a
osf_utimes_SOURCES = osf_utimes.c
osf_utimes_OBJECTS = osf_utimes.$(OBJEXT)
osf_utimes_LDADD = $(LDADD)
@@ -2786,7 +2790,8 @@
old_mmap-P.c old_mmap-Xabbrev.c old_mmap-Xraw.c \
old_mmap-Xverbose.c old_mmap-v-none.c oldfstat.c oldlstat.c \
oldselect.c oldselect-P.c oldselect-efault.c \
- oldselect-efault-P.c oldstat.c open.c openat.c osf_utimes.c \
+ oldselect-efault-P.c oldstat.c open.c openat.c \
+ orphaned_process_group.c osf_utimes.c \
pause.c pc.c perf_event_open.c perf_event_open_nonverbose.c \
perf_event_open_unabbrev.c personality.c personality-Xabbrev.c \
personality-Xraw.c personality-Xverbose.c pipe.c pipe2.c \
@@ -2931,7 +2936,8 @@
old_mmap-P.c old_mmap-Xabbrev.c old_mmap-Xraw.c \
old_mmap-Xverbose.c old_mmap-v-none.c oldfstat.c oldlstat.c \
oldselect.c oldselect-P.c oldselect-efault.c \
- oldselect-efault-P.c oldstat.c open.c openat.c osf_utimes.c \
+ oldselect-efault-P.c oldstat.c open.c openat.c \
+ orphaned_process_group.c osf_utimes.c \
pause.c pc.c perf_event_open.c perf_event_open_nonverbose.c \
perf_event_open_unabbrev.c personality.c personality-Xabbrev.c \
personality-Xraw.c personality-Xverbose.c pipe.c pipe2.c \
@@ -4058,7 +4064,8 @@
oldselect.gen.test oldselect-P.gen.test \
oldselect-efault.gen.test oldselect-efault-P.gen.test \
oldstat.gen.test open.gen.test openat.gen.test \
- osf_utimes.gen.test pause.gen.test perf_event_open.gen.test \
+ orphaned_process_group.gen.test osf_utimes.gen.test \
+ pause.gen.test perf_event_open.gen.test \
perf_event_open_nonverbose.gen.test \
perf_event_open_unabbrev.gen.test personality-Xabbrev.gen.test \
personality-Xraw.gen.test personality-Xverbose.gen.test \
@@ -5752,6 +5759,10 @@
@rm -f openat$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(openat_OBJECTS) $(openat_LDADD) $(LIBS)
+orphaned_process_group$(EXEEXT): $(orphaned_process_group_OBJECTS) $(orphaned_process_group_DEPENDENCIES) $(EXTRA_orphaned_process_group_DEPENDENCIES)
+ @rm -f orphaned_process_group$(EXEEXT)
+ $(AM_V_CCLD)$(LINK) $(orphaned_process_group_OBJECTS) $(orphaned_process_group_LDADD) $(LIBS)
+
osf_utimes$(EXEEXT): $(osf_utimes_OBJECTS) $(osf_utimes_DEPENDENCIES) $(EXTRA_osf_utimes_DEPENDENCIES)
@rm -f osf_utimes$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(osf_utimes_OBJECTS) $(osf_utimes_LDADD) $(LIBS)
@@ -7030,6 +7041,7 @@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oldstat.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/open.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/openat.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/orphaned_process_group.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/osf_utimes.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pause.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pc.Po@am__quote@
@@ -9128,6 +9140,9 @@
$(srcdir)/openat.gen.test: $(abs_srcdir)/gen_tests.sh $(srcdir)/gen_tests.in
$(AM_V_GEN) $^ $@
+$(srcdir)/orphaned_process_group.gen.test: $(abs_srcdir)/gen_tests.sh $(srcdir)/gen_tests.in
+ $(AM_V_GEN) $^ $@
+
$(srcdir)/osf_utimes.gen.test: $(abs_srcdir)/gen_tests.sh $(srcdir)/gen_tests.in
$(AM_V_GEN) $^ $@
Index: strace-4.24/tests-m32/orphaned_process_group.gen.test
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ strace-4.24/tests-m32/orphaned_process_group.gen.test 2019-03-10 05:59:50.567134970 +0100
@@ -0,0 +1,4 @@
+#!/bin/sh -efu
+# Generated by ./tests/gen_tests.sh from ./tests/gen_tests.in (orphaned_process_group . "${srcdir=.}/PTRACE_SEIZE.sh"; run_strace_match_diff -f -e trace=none -e signal='!chld'); do not edit.
+. "${srcdir=.}/init.sh"
+. "${srcdir=.}/PTRACE_SEIZE.sh"; run_strace_match_diff -f -e trace=none -e signal='!chld'
Index: strace-4.24/tests-mx32/orphaned_process_group.gen.test
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ strace-4.24/tests-mx32/orphaned_process_group.gen.test 2019-03-10 05:59:51.671123915 +0100
@@ -0,0 +1,4 @@
+#!/bin/sh -efu
+# Generated by ./tests/gen_tests.sh from ./tests/gen_tests.in (orphaned_process_group . "${srcdir=.}/PTRACE_SEIZE.sh"; run_strace_match_diff -f -e trace=none -e signal='!chld'); do not edit.
+. "${srcdir=.}/init.sh"
+. "${srcdir=.}/PTRACE_SEIZE.sh"; run_strace_match_diff -f -e trace=none -e signal='!chld'
Index: strace-4.24/tests/orphaned_process_group.gen.test
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ strace-4.24/tests/orphaned_process_group.gen.test 2019-03-10 05:59:48.722153445 +0100
@@ -0,0 +1,4 @@
+#!/bin/sh -efu
+# Generated by ./tests/gen_tests.sh from ./tests/gen_tests.in (orphaned_process_group . "${srcdir=.}/PTRACE_SEIZE.sh"; run_strace_match_diff -f -e trace=none -e signal='!chld'); do not edit.
+. "${srcdir=.}/init.sh"
+. "${srcdir=.}/PTRACE_SEIZE.sh"; run_strace_match_diff -f -e trace=none -e signal='!chld'
Index: strace-4.24/tests-m32/gen_tests.in
===================================================================
--- strace-4.24.orig/tests-m32/gen_tests.in 2018-08-01 16:57:16.000000000 +0200
+++ strace-4.24/tests-m32/gen_tests.in 2019-03-10 06:00:59.151448188 +0100
@@ -3,27 +3,7 @@
# Copyright (c) 2017-2018 The strace developers.
# All rights reserved.
#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-# 3. The name of the author may not be used to endorse or promote products
-# derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+# SPDX-License-Identifier: GPL-2.0-or-later
_newselect
_newselect-P -e trace=_newselect -P /dev/full 9>>/dev/full
@@ -307,6 +287,7 @@
oldstat -a32 -v -P stat.sample -P /dev/full
open -a30 -P $NAME.sample
openat -a36 -P $NAME.sample
+orphaned_process_group . "${srcdir=.}/PTRACE_SEIZE.sh"; run_strace_match_diff -f -e trace=none -e signal='!chld'
osf_utimes -a21
pause -a8 -esignal=none
perf_event_open -a1
Index: strace-4.24/tests-mx32/gen_tests.in
===================================================================
--- strace-4.24.orig/tests-mx32/gen_tests.in 2018-08-01 16:57:16.000000000 +0200
+++ strace-4.24/tests-mx32/gen_tests.in 2019-03-10 06:01:00.297436713 +0100
@@ -3,27 +3,7 @@
# Copyright (c) 2017-2018 The strace developers.
# All rights reserved.
#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-# 3. The name of the author may not be used to endorse or promote products
-# derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+# SPDX-License-Identifier: GPL-2.0-or-later
_newselect
_newselect-P -e trace=_newselect -P /dev/full 9>>/dev/full
@@ -307,6 +287,7 @@
oldstat -a32 -v -P stat.sample -P /dev/full
open -a30 -P $NAME.sample
openat -a36 -P $NAME.sample
+orphaned_process_group . "${srcdir=.}/PTRACE_SEIZE.sh"; run_strace_match_diff -f -e trace=none -e signal='!chld'
osf_utimes -a21
pause -a8 -esignal=none
perf_event_open -a1

View File

@ -1,788 +0,0 @@
From 1fc4e011bb0d977b64385e5dff91620c42985bcf Mon Sep 17 00:00:00 2001
From: "Dmitry V. Levin" <ldv@altlinux.org>
Date: Wed, 4 Jul 2018 02:11:27 +0000
Subject: [PATCH 25/27] tests: check tracing of looping threads
* test/many_looping_threads.c: Remove.
* test/.gitignore: Remove many_looping_threads.
* test/Makefile (PROGS): Likewise.
(many_looping_threads): Remove.
* tests/looping_threads.c: New file.
* tests/looping_threads.test: New test.
* tests/.gitignore: Add looping_threads.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(looping_threads_LDADD): New variable.
(MISC_TESTS, XFAIL_TESTS): Add looping_threads.test.
Conflicts:
tests/Makefile.am
Skipped files (not present in the tarball):
test/.gitignore
test/Makefile
test/many_looping_threads.c
tests/.gitignore
Additional changes:
tests/Makefile.in (generated from tests/Makefile.am)
tests-m32/Makefile.in (generated from tests-m32/Makefile.am)
tests-m32/looping_threads.c (copy of tests/looping_threads.c)
tests-m32/looping_threads.test (copy of tests/looping_threads.test)
tests-mx32/Makefile.in (generated from tests-mx32/Makefile.am)
tests-mx32/looping_threads.c (copy of tests/looping_threads.c)
tests-mx32/looping_threads.test (copy of tests/looping_threads.test)
---
test/.gitignore | 1 -
test/Makefile | 5 +-
test/many_looping_threads.c | 49 ------------------
tests/.gitignore | 1 +
tests/Makefile.am | 6 ++-
tests/looping_threads.c | 121 ++++++++++++++++++++++++++++++++++++++++++++
tests/looping_threads.test | 38 ++++++++++++++
7 files changed, 166 insertions(+), 55 deletions(-)
delete mode 100644 test/many_looping_threads.c
create mode 100644 tests/looping_threads.c
create mode 100755 tests/looping_threads.test
Index: strace-4.24/tests/Makefile.am
===================================================================
--- strace-4.24.orig/tests/Makefile.am 2019-03-10 05:50:05.488993755 +0100
+++ strace-4.24/tests/Makefile.am 2019-03-10 06:01:56.696871947 +0100
@@ -108,6 +108,7 @@
ksysent \
list_sigaction_signum \
localtime \
+ looping_threads \
mmsg-silent \
mmsg_name-v \
msg_control-v \
@@ -172,6 +173,7 @@
fstatat64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
ftruncate64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
localtime_LDADD = $(clock_LIBS) $(LDADD)
+looping_threads_LDADD = -lpthread $(LDADD)
lstat64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
mmap64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
mmap64_Xabbrev_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
@@ -304,6 +306,7 @@
kill_child.test \
ksysent.test \
localtime.test \
+ looping_threads.test \
opipe.test \
options-syntax.test \
pc.test \
@@ -347,7 +350,8 @@
XFAIL_TESTS_mx32 = $(STACKTRACE_TESTS)
XFAIL_TESTS_x86_64 = int_0x80.gen.test
XFAIL_TESTS_x32 = int_0x80.gen.test
-XFAIL_TESTS = $(XFAIL_TESTS_$(MPERS_NAME)) $(XFAIL_TESTS_$(ARCH))
+XFAIL_TESTS = $(XFAIL_TESTS_$(MPERS_NAME)) $(XFAIL_TESTS_$(ARCH)) \
+ looping_threads.test
TEST_LOG_COMPILER = env
AM_TEST_LOG_FLAGS = STRACE_ARCH=$(ARCH) STRACE_NATIVE_ARCH=$(NATIVE_ARCH) \
Index: strace-4.24/tests/looping_threads.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ strace-4.24/tests/looping_threads.c 2019-03-10 06:01:56.697871937 +0100
@@ -0,0 +1,121 @@
+/*
+ * Check tracing of looping threads.
+ *
+ * Copyright (c) 2009-2019 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "tests.h"
+#include <assert.h>
+#include <errno.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/wait.h>
+
+static void *
+thread(void *arg)
+{
+ for (;;)
+ getuid();
+ return arg;
+}
+
+int
+main(int ac, const char *av[])
+{
+ assert(ac == 3);
+
+ int timeout = atoi(av[1]);
+ assert(timeout > 0);
+
+ int num_threads = atoi(av[2]);
+ assert(num_threads > 0);
+
+ /*
+ * Unblock all signals.
+ */
+ static sigset_t mask;
+ if (sigprocmask(SIG_SETMASK, &mask, NULL))
+ perror_msg_and_fail("sigprocmask");
+
+ /*
+ * Reset SIGALRM and SIGHUP signal handlers.
+ */
+ static const struct sigaction sa_def = { .sa_handler = SIG_DFL };
+ if (sigaction(SIGHUP, &sa_def, NULL))
+ perror_msg_and_fail("sigaction SIGHUP");
+ if (sigaction(SIGALRM, &sa_def, NULL))
+ perror_msg_and_fail("sigaction SIGALRM");
+
+ /*
+ * Create a new process group.
+ */
+ if (setpgid(0, 0))
+ perror_msg_and_fail("setpgid");
+
+ /*
+ * Set an alarm clock.
+ */
+ alarm(timeout);
+
+ /*
+ * When the main process terminates, the process group becomes orphaned.
+ * If any member of the orphaned process group is stopped, then
+ * a SIGHUP signal followed by a SIGCONT signal is sent to each process
+ * in the orphaned process group.
+ * Create a process in a stopped state to activate this behaviour.
+ */
+ const pid_t stopped = fork();
+ if (stopped < 0)
+ perror_msg_and_fail("fork");
+ if (!stopped) {
+ raise(SIGSTOP);
+ _exit(0);
+ }
+
+ /*
+ * Wait for the process to stop.
+ */
+ int status;
+ if (waitpid(stopped, &status, WUNTRACED) != stopped)
+ perror_msg_and_fail("waitpid WUNTRACED");
+ if (!WIFSTOPPED(status) || WSTOPSIG(status) != SIGSTOP)
+ error_msg_and_fail("waitpid WUNTRACED: "
+ "unexpected wait status %d", status);
+ /*
+ * Create all threads in a subprocess, this guarantees that
+ * their tracer will not be their parent.
+ */
+ pid_t pid = fork();
+ if (pid < 0)
+ perror_msg_and_fail("fork");
+ if (!pid) {
+ for (int i = 0; i < num_threads; i++) {
+ pthread_t t;
+ if ((errno = pthread_create(&t, NULL, thread, NULL))) {
+ if (EAGAIN == errno)
+ break;
+ perror_msg_and_fail("pthread_create #%d", i);
+ }
+ }
+
+ /* This terminates all threads created above. */
+ _exit(0);
+ }
+
+ if (waitpid(pid, &status, 0) != pid)
+ perror_msg_and_fail("waitpid");
+ if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+ error_msg_and_fail("waitpid: unexpected wait status %d",
+ status);
+
+ /*
+ * Make the process group orphaned.
+ */
+ return 0;
+}
Index: strace-4.24/tests/looping_threads.test
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ strace-4.24/tests/looping_threads.test 2019-03-10 06:01:56.697871937 +0100
@@ -0,0 +1,38 @@
+#!/bin/sh
+#
+# Check tracing of looping threads.
+#
+# Copyright (c) 2009-2019 The strace developers.
+# All rights reserved.
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+. "${srcdir=.}/init.sh"
+. "${srcdir=.}/PTRACE_SEIZE.sh"
+
+run_prog ../orphaned_process_group > /dev/null
+
+run_prog_skip_if_failed date +%s > /dev/null
+s0="$(date +%s)"
+
+check_prog nproc
+inc="$(nproc)"
+[ "$inc" -ge 1 ] || inc=1
+
+timeout_2="$(($TIMEOUT_DURATION/2))"
+timeout_8="$(($TIMEOUT_DURATION/8))"
+nproc=1
+
+run_prog "../$NAME" "$timeout_8" "$nproc"
+
+while :; do
+ run_strace -f -qq -enone -esignal=none "../$NAME" "$timeout_2" "$nproc"
+
+ s1="$(date +%s)"
+ [ "$(($s1-$s0))" -lt "$timeout_8" ] ||
+ break
+
+ nproc="$(($nproc+$inc))"
+done
+
+warn_ "$ME_: nproc=$nproc elapsed=$(($s1-$s0))"
Index: strace-4.24/tests-m32/looping_threads.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ strace-4.24/tests-m32/looping_threads.c 2019-03-10 06:02:29.984538615 +0100
@@ -0,0 +1,121 @@
+/*
+ * Check tracing of looping threads.
+ *
+ * Copyright (c) 2009-2019 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "tests.h"
+#include <assert.h>
+#include <errno.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/wait.h>
+
+static void *
+thread(void *arg)
+{
+ for (;;)
+ getuid();
+ return arg;
+}
+
+int
+main(int ac, const char *av[])
+{
+ assert(ac == 3);
+
+ int timeout = atoi(av[1]);
+ assert(timeout > 0);
+
+ int num_threads = atoi(av[2]);
+ assert(num_threads > 0);
+
+ /*
+ * Unblock all signals.
+ */
+ static sigset_t mask;
+ if (sigprocmask(SIG_SETMASK, &mask, NULL))
+ perror_msg_and_fail("sigprocmask");
+
+ /*
+ * Reset SIGALRM and SIGHUP signal handlers.
+ */
+ static const struct sigaction sa_def = { .sa_handler = SIG_DFL };
+ if (sigaction(SIGHUP, &sa_def, NULL))
+ perror_msg_and_fail("sigaction SIGHUP");
+ if (sigaction(SIGALRM, &sa_def, NULL))
+ perror_msg_and_fail("sigaction SIGALRM");
+
+ /*
+ * Create a new process group.
+ */
+ if (setpgid(0, 0))
+ perror_msg_and_fail("setpgid");
+
+ /*
+ * Set an alarm clock.
+ */
+ alarm(timeout);
+
+ /*
+ * When the main process terminates, the process group becomes orphaned.
+ * If any member of the orphaned process group is stopped, then
+ * a SIGHUP signal followed by a SIGCONT signal is sent to each process
+ * in the orphaned process group.
+ * Create a process in a stopped state to activate this behaviour.
+ */
+ const pid_t stopped = fork();
+ if (stopped < 0)
+ perror_msg_and_fail("fork");
+ if (!stopped) {
+ raise(SIGSTOP);
+ _exit(0);
+ }
+
+ /*
+ * Wait for the process to stop.
+ */
+ int status;
+ if (waitpid(stopped, &status, WUNTRACED) != stopped)
+ perror_msg_and_fail("waitpid WUNTRACED");
+ if (!WIFSTOPPED(status) || WSTOPSIG(status) != SIGSTOP)
+ error_msg_and_fail("waitpid WUNTRACED: "
+ "unexpected wait status %d", status);
+ /*
+ * Create all threads in a subprocess, this guarantees that
+ * their tracer will not be their parent.
+ */
+ pid_t pid = fork();
+ if (pid < 0)
+ perror_msg_and_fail("fork");
+ if (!pid) {
+ for (int i = 0; i < num_threads; i++) {
+ pthread_t t;
+ if ((errno = pthread_create(&t, NULL, thread, NULL))) {
+ if (EAGAIN == errno)
+ break;
+ perror_msg_and_fail("pthread_create #%d", i);
+ }
+ }
+
+ /* This terminates all threads created above. */
+ _exit(0);
+ }
+
+ if (waitpid(pid, &status, 0) != pid)
+ perror_msg_and_fail("waitpid");
+ if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+ error_msg_and_fail("waitpid: unexpected wait status %d",
+ status);
+
+ /*
+ * Make the process group orphaned.
+ */
+ return 0;
+}
Index: strace-4.24/tests-mx32/looping_threads.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ strace-4.24/tests-mx32/looping_threads.c 2019-03-10 06:02:32.320515223 +0100
@@ -0,0 +1,121 @@
+/*
+ * Check tracing of looping threads.
+ *
+ * Copyright (c) 2009-2019 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "tests.h"
+#include <assert.h>
+#include <errno.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/wait.h>
+
+static void *
+thread(void *arg)
+{
+ for (;;)
+ getuid();
+ return arg;
+}
+
+int
+main(int ac, const char *av[])
+{
+ assert(ac == 3);
+
+ int timeout = atoi(av[1]);
+ assert(timeout > 0);
+
+ int num_threads = atoi(av[2]);
+ assert(num_threads > 0);
+
+ /*
+ * Unblock all signals.
+ */
+ static sigset_t mask;
+ if (sigprocmask(SIG_SETMASK, &mask, NULL))
+ perror_msg_and_fail("sigprocmask");
+
+ /*
+ * Reset SIGALRM and SIGHUP signal handlers.
+ */
+ static const struct sigaction sa_def = { .sa_handler = SIG_DFL };
+ if (sigaction(SIGHUP, &sa_def, NULL))
+ perror_msg_and_fail("sigaction SIGHUP");
+ if (sigaction(SIGALRM, &sa_def, NULL))
+ perror_msg_and_fail("sigaction SIGALRM");
+
+ /*
+ * Create a new process group.
+ */
+ if (setpgid(0, 0))
+ perror_msg_and_fail("setpgid");
+
+ /*
+ * Set an alarm clock.
+ */
+ alarm(timeout);
+
+ /*
+ * When the main process terminates, the process group becomes orphaned.
+ * If any member of the orphaned process group is stopped, then
+ * a SIGHUP signal followed by a SIGCONT signal is sent to each process
+ * in the orphaned process group.
+ * Create a process in a stopped state to activate this behaviour.
+ */
+ const pid_t stopped = fork();
+ if (stopped < 0)
+ perror_msg_and_fail("fork");
+ if (!stopped) {
+ raise(SIGSTOP);
+ _exit(0);
+ }
+
+ /*
+ * Wait for the process to stop.
+ */
+ int status;
+ if (waitpid(stopped, &status, WUNTRACED) != stopped)
+ perror_msg_and_fail("waitpid WUNTRACED");
+ if (!WIFSTOPPED(status) || WSTOPSIG(status) != SIGSTOP)
+ error_msg_and_fail("waitpid WUNTRACED: "
+ "unexpected wait status %d", status);
+ /*
+ * Create all threads in a subprocess, this guarantees that
+ * their tracer will not be their parent.
+ */
+ pid_t pid = fork();
+ if (pid < 0)
+ perror_msg_and_fail("fork");
+ if (!pid) {
+ for (int i = 0; i < num_threads; i++) {
+ pthread_t t;
+ if ((errno = pthread_create(&t, NULL, thread, NULL))) {
+ if (EAGAIN == errno)
+ break;
+ perror_msg_and_fail("pthread_create #%d", i);
+ }
+ }
+
+ /* This terminates all threads created above. */
+ _exit(0);
+ }
+
+ if (waitpid(pid, &status, 0) != pid)
+ perror_msg_and_fail("waitpid");
+ if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+ error_msg_and_fail("waitpid: unexpected wait status %d",
+ status);
+
+ /*
+ * Make the process group orphaned.
+ */
+ return 0;
+}
Index: strace-4.24/tests/Makefile.in
===================================================================
--- strace-4.24.orig/tests/Makefile.in 2019-03-10 05:56:10.763336015 +0100
+++ strace-4.24/tests/Makefile.in 2019-03-10 06:05:55.655479092 +0100
@@ -155,7 +155,7 @@
ioctl_perf-success$(EXEEXT) ioctl_rtc-v$(EXEEXT) \
is_linux_mips_n64$(EXEEXT) kill_child$(EXEEXT) \
ksysent$(EXEEXT) list_sigaction_signum$(EXEEXT) \
- localtime$(EXEEXT) \
+ localtime$(EXEEXT) looping_threads$(EXEEXT) \
mmsg-silent$(EXEEXT) mmsg_name-v$(EXEEXT) \
msg_control-v$(EXEEXT) net-accept-connect$(EXEEXT) \
net-tpacket_stats-success$(EXEEXT) netlink_inet_diag$(EXEEXT) \
@@ -1226,6 +1226,9 @@
lookup_dcookie_OBJECTS = lookup_dcookie.$(OBJEXT)
lookup_dcookie_LDADD = $(LDADD)
lookup_dcookie_DEPENDENCIES = libtests.a
+looping_threads_SOURCES = looping_threads.c
+looping_threads_OBJECTS = looping_threads.$(OBJEXT)
+looping_threads_DEPENDENCIES = $(LDADD)
lseek_SOURCES = lseek.c
lseek_OBJECTS = lseek.$(OBJEXT)
lseek_LDADD = $(LDADD)
@@ -2752,11 +2755,12 @@
kexec_file_load.c kexec_load.c keyctl.c keyctl-Xabbrev.c \
keyctl-Xraw.c keyctl-Xverbose.c kill.c kill_child.c ksysent.c \
lchown.c lchown32.c link.c linkat.c list_sigaction_signum.c \
- llseek.c localtime.c lookup_dcookie.c lseek.c lstat.c lstat64.c \
- madvise.c mbind.c membarrier.c memfd_create.c migrate_pages.c \
- mincore.c mkdir.c mkdirat.c mknod.c mknodat.c mlock.c mlock2.c \
- mlockall.c mmap.c mmap-Xabbrev.c mmap-Xraw.c mmap-Xverbose.c \
- mmap64.c mmap64-Xabbrev.c mmap64-Xraw.c mmap64-Xverbose.c \
+ llseek.c localtime.c lookup_dcookie.c looping_threads.c \
+ lseek.c lstat.c lstat64.c madvise.c mbind.c membarrier.c \
+ memfd_create.c migrate_pages.c mincore.c mkdir.c mkdirat.c \
+ mknod.c mknodat.c mlock.c mlock2.c mlockall.c mmap.c \
+ mmap-Xabbrev.c mmap-Xraw.c mmap-Xverbose.c mmap64.c \
+ mmap64-Xabbrev.c mmap64-Xraw.c mmap64-Xverbose.c \
mmsg.c mmsg-silent.c mmsg_name.c mmsg_name-v.c modify_ldt.c \
mount.c mount-Xabbrev.c mount-Xraw.c mount-Xverbose.c \
move_pages.c mq.c mq_sendrecv.c mq_sendrecv-read.c \
@@ -2898,11 +2902,12 @@
kexec_file_load.c kexec_load.c keyctl.c keyctl-Xabbrev.c \
keyctl-Xraw.c keyctl-Xverbose.c kill.c kill_child.c ksysent.c \
lchown.c lchown32.c link.c linkat.c list_sigaction_signum.c \
- llseek.c localtime.c lookup_dcookie.c lseek.c lstat.c lstat64.c \
- madvise.c mbind.c membarrier.c memfd_create.c migrate_pages.c \
- mincore.c mkdir.c mkdirat.c mknod.c mknodat.c mlock.c mlock2.c \
- mlockall.c mmap.c mmap-Xabbrev.c mmap-Xraw.c mmap-Xverbose.c \
- mmap64.c mmap64-Xabbrev.c mmap64-Xraw.c mmap64-Xverbose.c \
+ llseek.c localtime.c lookup_dcookie.c looping_threads.c \
+ lseek.c lstat.c lstat64.c madvise.c mbind.c membarrier.c \
+ memfd_create.c migrate_pages.c mincore.c mkdir.c mkdirat.c \
+ mknod.c mknodat.c mlock.c mlock2.c mlockall.c mmap.c \
+ mmap-Xabbrev.c mmap-Xraw.c mmap-Xverbose.c mmap64.c \
+ mmap64-Xabbrev.c mmap64-Xraw.c mmap64-Xverbose.c \
mmsg.c mmsg-silent.c mmsg_name.c mmsg_name-v.c modify_ldt.c \
mount.c mount-Xabbrev.c mount-Xraw.c mount-Xverbose.c \
move_pages.c mq.c mq_sendrecv.c mq_sendrecv-read.c \
@@ -3922,6 +3927,7 @@
fstatat64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
ftruncate64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
localtime_LDADD = $(clock_LIBS) $(LDADD)
+looping_threads_LDADD = -lpthread $(LDADD)
lstat64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
mmap64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
mmap64_Xabbrev_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
@@ -4242,6 +4248,7 @@
kill_child.test \
ksysent.test \
localtime.test \
+ looping_threads.test \
opipe.test \
options-syntax.test \
pc.test \
@@ -5243,6 +5250,10 @@
@rm -f lookup_dcookie$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(lookup_dcookie_OBJECTS) $(lookup_dcookie_LDADD) $(LIBS)
+looping_threads$(EXEEXT): $(looping_threads_OBJECTS) $(looping_threads_DEPENDENCIES) $(EXTRA_looping_threads_DEPENDENCIES)
+ @rm -f looping_threads$(EXEEXT)
+ $(AM_V_CCLD)$(LINK) $(looping_threads_OBJECTS) $(looping_threads_LDADD) $(LIBS)
+
lseek$(EXEEXT): $(lseek_OBJECTS) $(lseek_DEPENDENCIES) $(EXTRA_lseek_DEPENDENCIES)
@rm -f lseek$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(lseek_OBJECTS) $(lseek_LDADD) $(LIBS)
@@ -6912,6 +6923,7 @@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/llseek.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/localtime.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lookup_dcookie.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/looping_threads.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lseek.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lstat.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lstat64-lstat64.Po@am__quote@
Index: strace-4.24/tests-m32/Makefile.in
===================================================================
--- strace-4.24.orig/tests-m32/Makefile.in 2019-03-10 05:57:09.322749620 +0100
+++ strace-4.24/tests-m32/Makefile.in 2019-03-10 06:06:47.107963863 +0100
@@ -155,7 +155,7 @@
ioctl_perf-success$(EXEEXT) ioctl_rtc-v$(EXEEXT) \
is_linux_mips_n64$(EXEEXT) kill_child$(EXEEXT) \
ksysent$(EXEEXT) list_sigaction_signum$(EXEEXT) \
- localtime$(EXEEXT) \
+ localtime$(EXEEXT) looping_threads$(EXEEXT) \
mmsg-silent$(EXEEXT) mmsg_name-v$(EXEEXT) \
msg_control-v$(EXEEXT) net-accept-connect$(EXEEXT) \
net-tpacket_stats-success$(EXEEXT) netlink_inet_diag$(EXEEXT) \
@@ -1226,6 +1226,9 @@
lookup_dcookie_OBJECTS = lookup_dcookie.$(OBJEXT)
lookup_dcookie_LDADD = $(LDADD)
lookup_dcookie_DEPENDENCIES = libtests.a
+looping_threads_SOURCES = looping_threads.c
+looping_threads_OBJECTS = looping_threads.$(OBJEXT)
+looping_threads_DEPENDENCIES = $(LDADD)
lseek_SOURCES = lseek.c
lseek_OBJECTS = lseek.$(OBJEXT)
lseek_LDADD = $(LDADD)
@@ -2752,11 +2755,12 @@
kexec_file_load.c kexec_load.c keyctl.c keyctl-Xabbrev.c \
keyctl-Xraw.c keyctl-Xverbose.c kill.c kill_child.c ksysent.c \
lchown.c lchown32.c link.c linkat.c list_sigaction_signum.c \
- llseek.c localtime.c lookup_dcookie.c lseek.c lstat.c lstat64.c \
- madvise.c mbind.c membarrier.c memfd_create.c migrate_pages.c \
- mincore.c mkdir.c mkdirat.c mknod.c mknodat.c mlock.c mlock2.c \
- mlockall.c mmap.c mmap-Xabbrev.c mmap-Xraw.c mmap-Xverbose.c \
- mmap64.c mmap64-Xabbrev.c mmap64-Xraw.c mmap64-Xverbose.c \
+ llseek.c localtime.c lookup_dcookie.c looping_threads.c \
+ lseek.c lstat.c lstat64.c madvise.c mbind.c membarrier.c \
+ memfd_create.c migrate_pages.c mincore.c mkdir.c mkdirat.c \
+ mknod.c mknodat.c mlock.c mlock2.c mlockall.c mmap.c \
+ mmap-Xabbrev.c mmap-Xraw.c mmap-Xverbose.c mmap64.c \
+ mmap64-Xabbrev.c mmap64-Xraw.c mmap64-Xverbose.c \
mmsg.c mmsg-silent.c mmsg_name.c mmsg_name-v.c modify_ldt.c \
mount.c mount-Xabbrev.c mount-Xraw.c mount-Xverbose.c \
move_pages.c mq.c mq_sendrecv.c mq_sendrecv-read.c \
@@ -2898,11 +2902,12 @@
kexec_file_load.c kexec_load.c keyctl.c keyctl-Xabbrev.c \
keyctl-Xraw.c keyctl-Xverbose.c kill.c kill_child.c ksysent.c \
lchown.c lchown32.c link.c linkat.c list_sigaction_signum.c \
- llseek.c localtime.c lookup_dcookie.c lseek.c lstat.c lstat64.c \
- madvise.c mbind.c membarrier.c memfd_create.c migrate_pages.c \
- mincore.c mkdir.c mkdirat.c mknod.c mknodat.c mlock.c mlock2.c \
- mlockall.c mmap.c mmap-Xabbrev.c mmap-Xraw.c mmap-Xverbose.c \
- mmap64.c mmap64-Xabbrev.c mmap64-Xraw.c mmap64-Xverbose.c \
+ llseek.c localtime.c lookup_dcookie.c looping_threads.c \
+ lseek.c lstat.c lstat64.c madvise.c mbind.c membarrier.c \
+ memfd_create.c migrate_pages.c mincore.c mkdir.c mkdirat.c \
+ mknod.c mknodat.c mlock.c mlock2.c mlockall.c mmap.c \
+ mmap-Xabbrev.c mmap-Xraw.c mmap-Xverbose.c mmap64.c \
+ mmap64-Xabbrev.c mmap64-Xraw.c mmap64-Xverbose.c \
mmsg.c mmsg-silent.c mmsg_name.c mmsg_name-v.c modify_ldt.c \
mount.c mount-Xabbrev.c mount-Xraw.c mount-Xverbose.c \
move_pages.c mq.c mq_sendrecv.c mq_sendrecv-read.c \
@@ -3922,6 +3927,7 @@
fstatat64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
ftruncate64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
localtime_LDADD = $(clock_LIBS) $(LDADD)
+looping_threads_LDADD = -lpthread $(LDADD)
lstat64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
mmap64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
mmap64_Xabbrev_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
@@ -4242,6 +4248,7 @@
kill_child.test \
ksysent.test \
localtime.test \
+ looping_threads.test \
opipe.test \
options-syntax.test \
pc.test \
@@ -5243,6 +5250,10 @@
@rm -f lookup_dcookie$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(lookup_dcookie_OBJECTS) $(lookup_dcookie_LDADD) $(LIBS)
+looping_threads$(EXEEXT): $(looping_threads_OBJECTS) $(looping_threads_DEPENDENCIES) $(EXTRA_looping_threads_DEPENDENCIES)
+ @rm -f looping_threads$(EXEEXT)
+ $(AM_V_CCLD)$(LINK) $(looping_threads_OBJECTS) $(looping_threads_LDADD) $(LIBS)
+
lseek$(EXEEXT): $(lseek_OBJECTS) $(lseek_DEPENDENCIES) $(EXTRA_lseek_DEPENDENCIES)
@rm -f lseek$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(lseek_OBJECTS) $(lseek_LDADD) $(LIBS)
@@ -6912,6 +6923,7 @@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/llseek.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/localtime.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lookup_dcookie.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/looping_threads.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lseek.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lstat.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lstat64-lstat64.Po@am__quote@
Index: strace-4.24/tests-mx32/Makefile.in
===================================================================
--- strace-4.24.orig/tests-mx32/Makefile.in 2019-03-10 05:57:19.939643305 +0100
+++ strace-4.24/tests-mx32/Makefile.in 2019-03-10 06:06:42.992005079 +0100
@@ -155,7 +155,7 @@
ioctl_perf-success$(EXEEXT) ioctl_rtc-v$(EXEEXT) \
is_linux_mips_n64$(EXEEXT) kill_child$(EXEEXT) \
ksysent$(EXEEXT) list_sigaction_signum$(EXEEXT) \
- localtime$(EXEEXT) \
+ localtime$(EXEEXT) looping_threads$(EXEEXT) \
mmsg-silent$(EXEEXT) mmsg_name-v$(EXEEXT) \
msg_control-v$(EXEEXT) net-accept-connect$(EXEEXT) \
net-tpacket_stats-success$(EXEEXT) netlink_inet_diag$(EXEEXT) \
@@ -1226,6 +1226,9 @@
lookup_dcookie_OBJECTS = lookup_dcookie.$(OBJEXT)
lookup_dcookie_LDADD = $(LDADD)
lookup_dcookie_DEPENDENCIES = libtests.a
+looping_threads_SOURCES = looping_threads.c
+looping_threads_OBJECTS = looping_threads.$(OBJEXT)
+looping_threads_DEPENDENCIES = $(LDADD)
lseek_SOURCES = lseek.c
lseek_OBJECTS = lseek.$(OBJEXT)
lseek_LDADD = $(LDADD)
@@ -2752,11 +2755,12 @@
kexec_file_load.c kexec_load.c keyctl.c keyctl-Xabbrev.c \
keyctl-Xraw.c keyctl-Xverbose.c kill.c kill_child.c ksysent.c \
lchown.c lchown32.c link.c linkat.c list_sigaction_signum.c \
- llseek.c localtime.c lookup_dcookie.c lseek.c lstat.c lstat64.c \
- madvise.c mbind.c membarrier.c memfd_create.c migrate_pages.c \
- mincore.c mkdir.c mkdirat.c mknod.c mknodat.c mlock.c mlock2.c \
- mlockall.c mmap.c mmap-Xabbrev.c mmap-Xraw.c mmap-Xverbose.c \
- mmap64.c mmap64-Xabbrev.c mmap64-Xraw.c mmap64-Xverbose.c \
+ llseek.c localtime.c lookup_dcookie.c looping_threads.c \
+ lseek.c lstat.c lstat64.c madvise.c mbind.c membarrier.c \
+ memfd_create.c migrate_pages.c mincore.c mkdir.c mkdirat.c \
+ mknod.c mknodat.c mlock.c mlock2.c mlockall.c mmap.c \
+ mmap-Xabbrev.c mmap-Xraw.c mmap-Xverbose.c mmap64.c \
+ mmap64-Xabbrev.c mmap64-Xraw.c mmap64-Xverbose.c \
mmsg.c mmsg-silent.c mmsg_name.c mmsg_name-v.c modify_ldt.c \
mount.c mount-Xabbrev.c mount-Xraw.c mount-Xverbose.c \
move_pages.c mq.c mq_sendrecv.c mq_sendrecv-read.c \
@@ -2898,11 +2902,12 @@
kexec_file_load.c kexec_load.c keyctl.c keyctl-Xabbrev.c \
keyctl-Xraw.c keyctl-Xverbose.c kill.c kill_child.c ksysent.c \
lchown.c lchown32.c link.c linkat.c list_sigaction_signum.c \
- llseek.c localtime.c lookup_dcookie.c lseek.c lstat.c lstat64.c \
- madvise.c mbind.c membarrier.c memfd_create.c migrate_pages.c \
- mincore.c mkdir.c mkdirat.c mknod.c mknodat.c mlock.c mlock2.c \
- mlockall.c mmap.c mmap-Xabbrev.c mmap-Xraw.c mmap-Xverbose.c \
- mmap64.c mmap64-Xabbrev.c mmap64-Xraw.c mmap64-Xverbose.c \
+ llseek.c localtime.c lookup_dcookie.c looping_threads.c \
+ lseek.c lstat.c lstat64.c madvise.c mbind.c membarrier.c \
+ memfd_create.c migrate_pages.c mincore.c mkdir.c mkdirat.c \
+ mknod.c mknodat.c mlock.c mlock2.c mlockall.c mmap.c \
+ mmap-Xabbrev.c mmap-Xraw.c mmap-Xverbose.c mmap64.c \
+ mmap64-Xabbrev.c mmap64-Xraw.c mmap64-Xverbose.c \
mmsg.c mmsg-silent.c mmsg_name.c mmsg_name-v.c modify_ldt.c \
mount.c mount-Xabbrev.c mount-Xraw.c mount-Xverbose.c \
move_pages.c mq.c mq_sendrecv.c mq_sendrecv-read.c \
@@ -3922,6 +3927,7 @@
fstatat64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
ftruncate64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
localtime_LDADD = $(clock_LIBS) $(LDADD)
+looping_threads_LDADD = -lpthread $(LDADD)
lstat64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
mmap64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
mmap64_Xabbrev_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
@@ -4242,6 +4248,7 @@
kill_child.test \
ksysent.test \
localtime.test \
+ looping_threads.test \
opipe.test \
options-syntax.test \
pc.test \
@@ -5243,6 +5250,10 @@
@rm -f lookup_dcookie$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(lookup_dcookie_OBJECTS) $(lookup_dcookie_LDADD) $(LIBS)
+looping_threads$(EXEEXT): $(looping_threads_OBJECTS) $(looping_threads_DEPENDENCIES) $(EXTRA_looping_threads_DEPENDENCIES)
+ @rm -f looping_threads$(EXEEXT)
+ $(AM_V_CCLD)$(LINK) $(looping_threads_OBJECTS) $(looping_threads_LDADD) $(LIBS)
+
lseek$(EXEEXT): $(lseek_OBJECTS) $(lseek_DEPENDENCIES) $(EXTRA_lseek_DEPENDENCIES)
@rm -f lseek$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(lseek_OBJECTS) $(lseek_LDADD) $(LIBS)
@@ -6912,6 +6923,7 @@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/llseek.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/localtime.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lookup_dcookie.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/looping_threads.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lseek.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lstat.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lstat64-lstat64.Po@am__quote@

View File

@ -1,368 +0,0 @@
From 31a5eee990d64a98a071ce74cd4d53190c0fe94b Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Sun, 11 Sep 2016 12:11:45 +0300
Subject: [PATCH 26/27] Add a generic list implementation
Similar to the one used in the Linux kernel.
* macros.h (cast_ptr, containerof): New macros.
* list.h: New file.
* Makefile.am (strace_SOURCES): Add it.
---
Makefile.am | 1 +
list.h | 300 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
macros.h | 19 ++++
3 files changed, 320 insertions(+)
create mode 100644 list.h
diff --git a/Makefile.am b/Makefile.am
index f6679a3..f252bda 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -165,6 +165,7 @@ strace_SOURCES = \
linux/asm_stat.h \
linux/x32/asm_stat.h \
linux/x86_64/asm_stat.h \
+ list.h \
listen.c \
lookup_dcookie.c \
loop.c \
diff --git a/list.h b/list.h
new file mode 100644
index 0000000..cf68fa7
--- /dev/null
+++ b/list.h
@@ -0,0 +1,300 @@
+/*
+ * Some simple implementation of lists similar to the one used in the kernel.
+ *
+ * Copyright (c) 2016-2019 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#ifndef STRACE_LIST_H
+#define STRACE_LIST_H
+
+/*
+ * struct list_item and related macros and functions provide an interface
+ * for manipulating and iterating linked lists. In order to have list
+ * associated with its payload, struct list_item has to be embedded into
+ * a structure type representing payload, and (optionally) an additional
+ * struct list_item should be added somewhere as a starting point for list
+ * iteration (creating a list with a designated head). A situation where
+ * no designated head exists, and each embedded struct list_head is considered
+ * a head (i.e. starting point for list iteration), is also possible.
+ *
+ * List head has to be initialised with list_init() call. Statically allocated
+ * list heads can also be defined with an EMPTY_LIST() macro.
+ *
+ * In order to get a pointer to list item from a struct list_item, list_elem
+ * macro is used.
+ *
+ * When a designated head is used, list_head() and list_tail() can be used
+ * for getting pointer to the first and the last list item, respectively.
+ *
+ * list_next() and list_prev() macros can be used for obtaining pointers
+ * to the next and the previous items in the list, respectively. Note that
+ * they do not perform additional checks for the validity of these pointers,
+ * so they have to be guarded with respective list_head/list_tail checks in case
+ * of lists with designated heads (where the list's head is not embedded withing
+ * a list item.
+ *
+ * list_{insert,append,remove,remove_tail,remove_head,replace} provide some
+ * basic means of list manipulation.
+ *
+ * list_foreach() and list_foreach_safe() are wrapper macros for simplifying
+ * iteration over a list, with the latter having an additional argument
+ * for storing temporary pointer, thus allowing list manipulations during
+ * its iteration.
+ *
+ * A simple example:
+ *
+ * struct my_struct {
+ * int a;
+ * struct list_item l1;
+ * struct list_item l2;
+ * };
+ *
+ * EMPTY_LIST(list_1); <--- Defining a designated head for list
+ *
+ * struct my_struct *item =
+ * calloc(1, sizeof(*item));
+ * list_init(&item->l2); <--- Initialising structure field that
+ * is used for lists without designated
+ * head.
+ * list_insert(&list_1, &item->l1); <--- Inserting an item into the list
+ *
+ * item = calloc(1, sizeof(*item));
+ * list_init(&item->l2);
+ *
+ * list_append(&(list_head(list_1, struct my_struct, l1)->l2), &item->l2);
+ *
+ * struct my_struct *cur = item; <--- Iteration over a headless list
+ * do {
+ * printf("%d\n", cur->a);
+ * } while ((cur = list_next(&cur, l2)) != item);
+ *
+ * struct my_struct *i;
+ * list_foreach(i, list_1, l1) { <--- Iteration over list_1 without list
+ * printf("%d\n", i->a); modification
+ * }
+ *
+ * struct my_struct *tmp; <--- Iteration with modification
+ * list_foreach_safe(i, list_1, l1, tmp) {
+ * list_remove(&i->l1);
+ * free(i);
+ * }
+ *
+ * See also:
+ * "Linux kernel design patterns - part 2", section "Linked Lists"
+ * https://lwn.net/Articles/336255/
+ */
+
+#include "macros.h"
+
+struct list_item {
+ struct list_item *prev;
+ struct list_item *next;
+};
+
+/**
+ * Define an empty list head.
+ *
+ * @param l_ List head variable name.
+ */
+#define EMPTY_LIST(l_) struct list_item l_ = { &l_, &l_ }
+
+/** Initialise an empty list. */
+static inline void
+list_init(struct list_item *l)
+{
+ l->prev = l;
+ l->next = l;
+}
+
+/** Check whether list is empty. */
+static inline bool
+list_is_empty(const struct list_item *l)
+{
+ return ((l->next == l) && (l->prev == l))
+ /*
+ * XXX This could be the case when struct list_item hasn't been
+ * initialised at all; we should probably also call some
+ * errror_func_msg() in that case, as it looks like sloppy
+ * programming.
+ */
+ || (!l->next && !l->prev);
+}
+
+/**
+ * Convert a pointer to a struct list_item to a pointer to a list item.
+ *
+ * @param var Pointer to struct list_item.
+ * @param type Type of the list's item.
+ * @param field Name of the field that holds the respective struct list_item.
+ */
+#define list_elem(var, type, field) containerof((var), type, field)
+
+/**
+ * Get the first element in a list.
+ *
+ * @param head Pointer to the list's head.
+ * @param type Type of the list's item.
+ * @param field Name of the field that holds the respective struct list_item.
+ */
+#define list_head(head, type, field) \
+ (list_is_empty(head) ? NULL : list_elem((head)->next, type, field))
+/**
+ * Get the last element in a list.
+ *
+ * @param head Pointer to the list's head.
+ * @param type Type of the list's item.
+ * @param field Name of the field that holds the respective struct list_item.
+ */
+#define list_tail(head, type, field) \
+ (list_is_empty(head) ? NULL : list_elem((head)->prev, type, field))
+
+/**
+ * Get the next element in a list.
+ *
+ * @param var Pointer to a list item.
+ * @param field Name of the field that holds the respective struct list_item.
+ */
+#define list_next(var, field) \
+ list_elem((var)->field.next, typeof(*(var)), field)
+/**
+ * Get the previous element in a list.
+ *
+ * @param var Pointer to a list item.
+ * @param field Name of the field that holds the respective struct list_item.
+ */
+#define list_prev(var, field) \
+ list_elem((var)->field.prev, typeof(*(var)), field)
+
+/**
+ * Insert an item into a list. The item is placed as the next list item
+ * to the head.
+ */
+static inline void
+list_insert(struct list_item *head, struct list_item *item)
+{
+ item->next = head->next;
+ item->prev = head;
+ head->next->prev = item;
+ head->next = item;
+}
+
+/**
+ * Insert an item into a list. The item is placed as the previous list item
+ * to the head.
+ */
+static inline void
+list_append(struct list_item *head, struct list_item *item)
+{
+ item->next = head;
+ item->prev = head->prev;
+ head->prev->next = item;
+ head->prev = item;
+}
+
+/**
+ * Remove an item from a list.
+ *
+ * @param item Pointer to struct list_item of the item to be removed.
+ * @return Whether the action has been performed.
+ */
+static inline bool
+list_remove(struct list_item *item)
+{
+ if (!item->next || !item->prev || list_is_empty(item))
+ return false;
+
+ item->prev->next = item->next;
+ item->next->prev = item->prev;
+ item->next = item->prev = item;
+
+ return true;
+}
+
+/**
+ * Remove the last element of a list.
+ *
+ * @param head Pointer to the list's head.
+ * @return Pointer to struct list_item removed from the list;
+ * or NULL, if the list is empty.
+ */
+static inline struct list_item *
+list_remove_tail(struct list_item *head)
+{
+ struct list_item *t = list_is_empty(head) ? NULL : head->prev;
+
+ if (t)
+ list_remove(t);
+
+ return t;
+}
+
+/**
+ * Remove the first element of a list.
+ *
+ * @param head Pointer to the list's head.
+ * @return Pointer to struct list_item removed from the list;
+ * or NULL, if the list is empty.
+ */
+static inline struct list_item *
+list_remove_head(struct list_item *head)
+{
+ struct list_item *h = list_is_empty(head) ? NULL : head->next;
+
+ if (h)
+ list_remove(h);
+
+ return h;
+}
+
+/**
+ * Replace an old struct list_item in a list with the new one.
+ *
+ * @param old Pointer to struct list_item of the item to be replaced.
+ * @param new Pointer to struct list_item of the item to be replaced with.
+ * @return Whether the replacement has been performed.
+ */
+static inline bool
+list_replace(struct list_item *old, struct list_item *new)
+{
+ if (!old->next || !old->prev || list_is_empty(old))
+ return false;
+
+ new->next = old->next;
+ new->prev = old->prev;
+ old->prev->next = new;
+ old->next->prev = new;
+ old->next = old->prev = old;
+
+ return true;
+}
+
+/**
+ * List iteration wrapper for non-destructive operations.
+ *
+ * @param var_ Variable holding pointer to a current list item.
+ * @param head_ Pointer to the list's head.
+ * @param field_ Name of the field containing the respective struct list_item
+ * inside list items.
+ */
+#define list_foreach(var_, head_, field_) \
+ for (var_ = list_elem((head_)->next, typeof(*var_), field_); \
+ &(var_->field_) != (head_); var_ = list_next(var_, field_))
+
+/**
+ * List iteration wrapper for destructive operations.
+ *
+ * @param var_ Variable holding pointer to a current list item.
+ * @param head_ Pointer to the list's head.
+ * @param field_ Name of the field containing the respective struct list_item
+ * inside list items.
+ * @param _tmp Temporary variable for storing pointer to the next item.
+ */
+#define list_foreach_safe(var_, head_, field_, _tmp) \
+ for (var_ = list_elem((head_)->next, typeof(*var_), field_), \
+ _tmp = list_elem((var_)->field_.next, typeof(*var_), field_); \
+ &var_->field_ != head_; var_ = _tmp, _tmp = list_next(_tmp, field_))
+
+#endif /* !STRACE_LIST_H */
diff --git a/macros.h b/macros.h
index 9346d90..6951928 100644
--- a/macros.h
+++ b/macros.h
@@ -33,6 +33,25 @@
(offsetof(type_, member_) + sizeof(((type_ *)0)->member_))
#endif
+#ifndef cast_ptr
+# define cast_ptr(type_, var_) \
+ ((type_) (uintptr_t) (const volatile void *) (var_))
+#endif
+
+#ifndef containerof
+/**
+ * Return a pointer to a structure that contains the provided variable.
+ *
+ * @param ptr_ Pointer to data that is a field of the container structure.
+ * @param struct_ Type of the container structure.
+ * @param member_ Name of the member field.
+ * @return Pointer to the container structure.
+ */
+# define containerof(ptr_, struct_, member_) \
+ cast_ptr(struct_ *, \
+ (const volatile char *) (ptr_) - offsetof(struct_, member_))
+#endif
+
static inline bool
is_filled(const char *ptr, char fill, size_t size)
{
--
2.1.4

View File

@ -1,611 +0,0 @@
From 496f922dad9b58b891f417b937ac5fb0b0a8649a Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Wed, 8 Aug 2018 21:41:39 +0200
Subject: [PATCH 27/27] Implement queueing of threads before dispatching them
It is possible that some tracees call a lot of cheap syscalls too fast,
and that can stress the tracer to the point some tracees are not served
for indefinite amount of time. In order to avoid that unfairness, try
to collect all the pending tracees first along with the relevant
information and only then dispatch the events.
* defs.h: Include "list.h".
(struct tcb): Add wait_data_idx, delayed_wait_data, and wait_list
fields.
* strace.c (struct tcb_wait_data): Add "msg" field.
(tcb_wait_tab, tcb_wait_tab_size): New static variables.
(alloctcb): Initialize wait_list.
(droptcb): Remove tcp from wait_list.
(maybe_switch_tcbs): Get old pid from
tcb_wait_tab[tcp->wait_data_idx].msg instead of calling
ptrace(PTRACE_GETEVENTMSG).
(trace_wait_data_size, init_trace_wait_data, copy_trace_wait_data,
free_trace_wait_data, tcb_wait_tab_check_size): New functions, in order
to allow the code outside next_event to operate with wait_data as with
an opaque object (needed for dispatch_event and restart_delayed_tcb).
(next_event): Add pending_tcps, extra_tcp, wait_nohang, elem, and
wait_tab_pos variables; check for elements in pending_tcps and skip
waiting if the list is not empty; check for extra_tcp and skip waiting
along with swapping wait_data_idx with wait_extra_data_idx;
after the initial wait4(), call wait4() in loop with WNOHANG flag set;
fetch siginfo on signal and eventmsg on PTRACE_EVENT_EXEC;
return the first tcp in pending_tcps list.
(dispatch_event): Store a pointer to a copy of tcb_wait_data in
tcp->delayed_wait_data if tcp's restart has to be delayed.
(restart_delayed_tcb): Use tcp->delayed_wait_data, create a stub
tcb_wait_data if it is NULL, free temporary trace_wait_data.
* tests/Makefile.am (XFAIL_TEST): Remove looping_threads.test.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=478419
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=526740
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=851457
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1609318
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1610774
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
Co-Authored-by: Denys Vlasenko <dvlasenk@redhat.com>
Co-Authored-by: Andreas Schwab <aschwab@redhat.com>
Co-Authored-by: Jeff Law <law@redhat.com>
Co-Authored-by: DJ Delorie <dj@redhat.com>
Conflicts:
defs.h
tests/Makefile.am
---
defs.h | 12 ++
strace.c | 393 +++++++++++++++++++++++++++++++++++++-----------------
tests/Makefile.am | 3 +-
3 files changed, 283 insertions(+), 125 deletions(-)
diff --git a/defs.h b/defs.h
index 811bb0d..2a614a7 100644
--- a/defs.h
+++ b/defs.h
@@ -36,6 +36,7 @@
#include "arch_defs.h"
#include "error_prints.h"
#include "gcc_compat.h"
+#include "list.h"
#include "kernel_types.h"
#include "macros.h"
#include "mpers_type.h"
@@ -218,6 +219,17 @@ struct tcb {
struct mmap_cache_t *mmap_cache;
+ /*
+ * Data that is stored during process wait traversal.
+ * We use indices as the actual data is stored in an array
+ * that is realloc'ed at runtime.
+ */
+ size_t wait_data_idx;
+ /** Wait data storage for a delayed process. */
+ struct tcb_wait_data *delayed_wait_data;
+ struct list_item wait_list;
+
+
#ifdef HAVE_LINUX_KVM_H
struct vcpu_info *vcpu_info_list;
#endif
diff --git a/strace.c b/strace.c
index 0745838..0914dc7 100644
--- a/strace.c
+++ b/strace.c
@@ -141,6 +141,7 @@ static struct tcb *current_tcp;
struct tcb_wait_data {
enum trace_event te; /**< Event passed to dispatch_event() */
int status; /**< status, returned by wait4() */
+ unsigned long msg; /**< Value returned by PTRACE_GETEVENTMSG */
siginfo_t si; /**< siginfo, returned by PTRACE_GETSIGINFO */
};
@@ -148,6 +149,10 @@ static struct tcb **tcbtab;
static unsigned int nprocs;
static size_t tcbtabsize;
+static struct tcb_wait_data *tcb_wait_tab;
+static size_t tcb_wait_tab_size;
+
+
#ifndef HAVE_PROGRAM_INVOCATION_NAME
char *program_invocation_name;
#endif
@@ -745,6 +750,7 @@ alloctcb(int pid)
tcp = tcbtab[i];
if (!tcp->pid) {
memset(tcp, 0, sizeof(*tcp));
+ list_init(&tcp->wait_list);
tcp->pid = pid;
#if SUPPORTED_PERSONALITIES > 1
tcp->currpers = current_personality;
@@ -833,6 +839,8 @@ droptcb(struct tcb *tcp)
if (printing_tcp == tcp)
printing_tcp = NULL;
+ list_remove(&tcp->wait_list);
+
memset(tcp, 0, sizeof(*tcp));
}
@@ -2051,10 +2059,8 @@ maybe_switch_tcbs(struct tcb *tcp, const int pid)
{
FILE *fp;
struct tcb *execve_thread;
- long old_pid = 0;
+ long old_pid = tcb_wait_tab[tcp->wait_data_idx].msg;
- if (ptrace(PTRACE_GETEVENTMSG, pid, NULL, &old_pid) < 0)
- return tcp;
/* Avoid truncation in pid2tcb() param passing */
if (old_pid <= 0 || old_pid == pid)
return tcp;
@@ -2207,20 +2213,74 @@ print_event_exit(struct tcb *tcp)
line_ended();
}
-static const struct tcb_wait_data *
-next_event(void)
+static size_t
+trace_wait_data_size(struct tcb *tcp)
{
- static struct tcb_wait_data wait_data;
+ return sizeof(struct tcb_wait_data);
+}
- int pid;
- int status;
- struct tcb *tcp;
- struct tcb_wait_data *wd = &wait_data;
- struct rusage ru;
+static struct tcb_wait_data *
+init_trace_wait_data(void *p)
+{
+ struct tcb_wait_data *wd = p;
+
+ memset(wd, 0, sizeof(*wd));
+
+ return wd;
+}
+static struct tcb_wait_data *
+copy_trace_wait_data(const struct tcb_wait_data *wd)
+{
+ struct tcb_wait_data *new_wd = xmalloc(sizeof(*new_wd));
+
+ memcpy(new_wd, wd, sizeof(*wd));
+
+ return new_wd;
+}
+
+static void
+free_trace_wait_data(struct tcb_wait_data *wd)
+{
+ free(wd);
+}
+
+static void
+tcb_wait_tab_check_size(const size_t size)
+{
+ while (size >= tcb_wait_tab_size) {
+ tcb_wait_tab = xgrowarray(tcb_wait_tab,
+ &tcb_wait_tab_size,
+ sizeof(tcb_wait_tab[0]));
+ }
+}
+
+static const struct tcb_wait_data *
+next_event(void)
+{
if (interrupted)
return NULL;
+ struct tcb *tcp = NULL;
+ struct list_item *elem;
+
+ static EMPTY_LIST(pending_tcps);
+ /* Handle the queued tcbs before waiting for new events. */
+ if (!list_is_empty(&pending_tcps))
+ goto next_event_get_tcp;
+
+ static struct tcb *extra_tcp;
+ static size_t wait_extra_data_idx;
+ /* Handle the extra tcb event. */
+ if (extra_tcp) {
+ tcp = extra_tcp;
+ extra_tcp = NULL;
+ tcp->wait_data_idx = wait_extra_data_idx;
+
+ debug_msg("dequeued extra event for pid %u", tcp->pid);
+ goto next_event_exit;
+ }
+
/*
* Used to exit simply when nprocs hits zero, but in this testcase:
* int main(void) { _exit(!!fork()); }
@@ -2262,8 +2322,10 @@ next_event(void)
* then the system call will be interrupted and
* the expiration will be handled by the signal handler.
*/
- pid = wait4(-1, &status, __WALL, (cflag ? &ru : NULL));
- const int wait_errno = errno;
+ int status;
+ struct rusage ru;
+ int pid = wait4(-1, &status, __WALL, (cflag ? &ru : NULL));
+ int wait_errno = errno;
/*
* The window of opportunity to handle expirations
@@ -2279,135 +2341,202 @@ next_event(void)
return NULL;
}
- if (pid < 0) {
- if (wait_errno == EINTR) {
- wd->te = TE_NEXT;
- return wd;
+ size_t wait_tab_pos = 0;
+ bool wait_nohang = false;
+
+ /*
+ * Wait for new events until wait4() returns 0 (meaning that there's
+ * nothing more to wait for for now), or a second event for some tcb
+ * appears (which may happen if a tracee was SIGKILL'ed, for example).
+ */
+ for (;;) {
+ struct tcb_wait_data *wd;
+
+ if (pid < 0) {
+ if (wait_errno == EINTR)
+ break;
+ if (wait_nohang)
+ break;
+ if (nprocs == 0 && wait_errno == ECHILD)
+ return NULL;
+ /*
+ * If nprocs > 0, ECHILD is not expected,
+ * treat it as any other error here:
+ */
+ errno = wait_errno;
+ perror_msg_and_die("wait4(__WALL)");
}
- if (nprocs == 0 && wait_errno == ECHILD)
- return NULL;
- /*
- * If nprocs > 0, ECHILD is not expected,
- * treat it as any other error here:
- */
- errno = wait_errno;
- perror_msg_and_die("wait4(__WALL)");
- }
- wd->status = status;
+ if (!pid)
+ break;
- if (pid == popen_pid) {
- if (!WIFSTOPPED(status))
- popen_pid = 0;
- wd->te = TE_NEXT;
- return wd;
- }
+ if (pid == popen_pid) {
+ if (!WIFSTOPPED(status))
+ popen_pid = 0;
+ break;
+ }
- if (debug_flag)
- print_debug_info(pid, status);
+ if (debug_flag)
+ print_debug_info(pid, status);
- /* Look up 'pid' in our table. */
- tcp = pid2tcb(pid);
+ /* Look up 'pid' in our table. */
+ tcp = pid2tcb(pid);
- if (!tcp) {
- tcp = maybe_allocate_tcb(pid, status);
if (!tcp) {
- wd->te = TE_NEXT;
- return wd;
+ tcp = maybe_allocate_tcb(pid, status);
+ if (!tcp)
+ goto next_event_wait_next;
}
- }
- clear_regs(tcp);
+ if (cflag) {
+ struct timespec stime = {
+ .tv_sec = ru.ru_stime.tv_sec,
+ .tv_nsec = ru.ru_stime.tv_usec * 1000
+ };
+ ts_sub(&tcp->dtime, &stime, &tcp->stime);
+ tcp->stime = stime;
+ }
- /* Set current output file */
- set_current_tcp(tcp);
+ tcb_wait_tab_check_size(wait_tab_pos);
- if (cflag) {
- struct timespec stime = {
- .tv_sec = ru.ru_stime.tv_sec,
- .tv_nsec = ru.ru_stime.tv_usec * 1000
- };
- ts_sub(&tcp->dtime, &stime, &tcp->stime);
- tcp->stime = stime;
- }
+ /* Initialise a new wait data structure. */
+ wd = tcb_wait_tab + wait_tab_pos;
+ init_trace_wait_data(wd);
+ wd->status = status;
- if (WIFSIGNALED(status)) {
- wd->te = TE_SIGNALLED;
- return wd;
- }
+ if (WIFSIGNALED(status)) {
+ wd->te = TE_SIGNALLED;
+ } else if (WIFEXITED(status)) {
+ wd->te = TE_EXITED;
+ } else {
+ /*
+ * As WCONTINUED flag has not been specified to wait4,
+ * it cannot be WIFCONTINUED(status), so the only case
+ * that remains is WIFSTOPPED(status).
+ */
- if (WIFEXITED(status)) {
- wd->te = TE_EXITED;
- return wd;
+ const unsigned int sig = WSTOPSIG(status);
+ const unsigned int event = (unsigned int) status >> 16;
+
+ switch (event) {
+ case 0:
+ /*
+ * Is this post-attach SIGSTOP?
+ * Interestingly, the process may stop
+ * with STOPSIG equal to some other signal
+ * than SIGSTOP if we happened to attach
+ * just before the process takes a signal.
+ */
+ if (sig == SIGSTOP &&
+ (tcp->flags & TCB_IGNORE_ONE_SIGSTOP)) {
+ debug_func_msg("ignored SIGSTOP on "
+ "pid %d", tcp->pid);
+ tcp->flags &= ~TCB_IGNORE_ONE_SIGSTOP;
+ wd->te = TE_RESTART;
+ } else if (sig == syscall_trap_sig) {
+ wd->te = TE_SYSCALL_STOP;
+ } else {
+ /*
+ * True if tracee is stopped by signal
+ * (as opposed to "tracee received
+ * signal").
+ * TODO: shouldn't we check for
+ * errno == EINVAL too?
+ * We can get ESRCH instead, you know...
+ */
+ bool stopped = ptrace(PTRACE_GETSIGINFO,
+ pid, 0, &wd->si) < 0;
+
+ wd->te = stopped ? TE_GROUP_STOP
+ : TE_SIGNAL_DELIVERY_STOP;
+ }
+ break;
+ case PTRACE_EVENT_STOP:
+ /*
+ * PTRACE_INTERRUPT-stop or group-stop.
+ * PTRACE_INTERRUPT-stop has sig == SIGTRAP here.
+ */
+ switch (sig) {
+ case SIGSTOP:
+ case SIGTSTP:
+ case SIGTTIN:
+ case SIGTTOU:
+ wd->te = TE_GROUP_STOP;
+ break;
+ default:
+ wd->te = TE_RESTART;
+ }
+ break;
+ case PTRACE_EVENT_EXEC:
+ /*
+ * TODO: shouldn't we check for
+ * errno == EINVAL here, too?
+ * We can get ESRCH instead, you know...
+ */
+ if (ptrace(PTRACE_GETEVENTMSG, pid, NULL,
+ &wd->msg) < 0)
+ wd->msg = 0;
+
+ wd->te = TE_STOP_BEFORE_EXECVE;
+ break;
+ case PTRACE_EVENT_EXIT:
+ wd->te = TE_STOP_BEFORE_EXIT;
+ break;
+ default:
+ wd->te = TE_RESTART;
+ }
+ }
+
+ if (!wd->te)
+ error_func_msg("Tracing event hasn't been determined "
+ "for pid %d, status %0#x", pid, status);
+
+ if (!list_is_empty(&tcp->wait_list)) {
+ wait_extra_data_idx = wait_tab_pos;
+ extra_tcp = tcp;
+ debug_func_msg("queued extra pid %d", tcp->pid);
+ } else {
+ tcp->wait_data_idx = wait_tab_pos;
+ list_append(&pending_tcps, &tcp->wait_list);
+ debug_func_msg("queued pid %d", tcp->pid);
+ }
+
+ wait_tab_pos++;
+
+ if (extra_tcp)
+ break;
+
+next_event_wait_next:
+ pid = wait4(-1, &status, __WALL | WNOHANG, (cflag ? &ru : NULL));
+ wait_errno = errno;
+ wait_nohang = true;
}
- /*
- * As WCONTINUED flag has not been specified to wait4,
- * it cannot be WIFCONTINUED(status), so the only case
- * that remains is WIFSTOPPED(status).
- */
+next_event_get_tcp:
+ elem = list_remove_head(&pending_tcps);
+
+ if (!elem) {
+ tcb_wait_tab_check_size(0);
+ memset(tcb_wait_tab, 0, sizeof(*tcb_wait_tab));
+ tcb_wait_tab->te = TE_NEXT;
+ return tcb_wait_tab;
+ } else {
+ tcp = list_elem(elem, struct tcb, wait_list);
+ debug_func_msg("dequeued pid %d", tcp->pid);
+ }
+
+next_event_exit:
/* Is this the very first time we see this tracee stopped? */
if (tcp->flags & TCB_STARTUP)
startup_tcb(tcp);
- const unsigned int sig = WSTOPSIG(status);
- const unsigned int event = (unsigned int) status >> 16;
+ clear_regs(tcp);
- switch (event) {
- case 0:
- /*
- * Is this post-attach SIGSTOP?
- * Interestingly, the process may stop
- * with STOPSIG equal to some other signal
- * than SIGSTOP if we happened to attach
- * just before the process takes a signal.
- */
- if (sig == SIGSTOP && (tcp->flags & TCB_IGNORE_ONE_SIGSTOP)) {
- debug_func_msg("ignored SIGSTOP on pid %d", tcp->pid);
- tcp->flags &= ~TCB_IGNORE_ONE_SIGSTOP;
- wd->te = TE_RESTART;
- } else if (sig == syscall_trap_sig) {
- wd->te = TE_SYSCALL_STOP;
- } else {
- memset(&wd->si, 0, sizeof(wd->si));
- /*
- * True if tracee is stopped by signal
- * (as opposed to "tracee received signal").
- * TODO: shouldn't we check for errno == EINVAL too?
- * We can get ESRCH instead, you know...
- */
- bool stopped = ptrace(PTRACE_GETSIGINFO, pid, 0, &wd->si) < 0;
- wd->te = stopped ? TE_GROUP_STOP : TE_SIGNAL_DELIVERY_STOP;
- }
- break;
- case PTRACE_EVENT_STOP:
- /*
- * PTRACE_INTERRUPT-stop or group-stop.
- * PTRACE_INTERRUPT-stop has sig == SIGTRAP here.
- */
- switch (sig) {
- case SIGSTOP:
- case SIGTSTP:
- case SIGTTIN:
- case SIGTTOU:
- wd->te = TE_GROUP_STOP;
- break;
- default:
- wd->te = TE_RESTART;
- }
- break;
- case PTRACE_EVENT_EXEC:
- wd->te = TE_STOP_BEFORE_EXECVE;
- break;
- case PTRACE_EVENT_EXIT:
- wd->te = TE_STOP_BEFORE_EXIT;
- break;
- default:
- wd->te = TE_RESTART;
- }
+ /* Set current output file */
+ set_current_tcp(tcp);
- return wd;
+ return tcb_wait_tab + tcp->wait_data_idx;
}
static int
@@ -2569,8 +2698,15 @@ dispatch_event(const struct tcb_wait_data *wd)
return false;
/* If the process is being delayed, do not ptrace_restart just yet */
- if (syscall_delayed(current_tcp))
+ if (syscall_delayed(current_tcp)) {
+ if (current_tcp->delayed_wait_data)
+ error_func_msg("pid %d has delayed wait data set"
+ " already", current_tcp->pid);
+
+ current_tcp->delayed_wait_data = copy_trace_wait_data(wd);
+
return true;
+ }
if (ptrace_restart(restart_op, current_tcp, restart_sig) < 0) {
/* Note: ptrace_restart emitted error message */
@@ -2583,7 +2719,15 @@ dispatch_event(const struct tcb_wait_data *wd)
static bool
restart_delayed_tcb(struct tcb *const tcp)
{
- const struct tcb_wait_data wd = { .te = TE_RESTART };
+ struct tcb_wait_data *wd = tcp->delayed_wait_data;
+
+ if (!wd) {
+ error_func_msg("No delayed wait data found for pid %d",
+ tcp->pid);
+ wd = init_trace_wait_data(alloca(trace_wait_data_size(tcp)));
+ }
+
+ wd->te = TE_RESTART;
debug_func_msg("pid %d", tcp->pid);
@@ -2591,9 +2735,12 @@ restart_delayed_tcb(struct tcb *const tcp)
struct tcb *const prev_tcp = current_tcp;
current_tcp = tcp;
- bool ret = dispatch_event(&wd);
+ bool ret = dispatch_event(wd);
current_tcp = prev_tcp;
+ free_trace_wait_data(tcp->delayed_wait_data);
+ tcp->delayed_wait_data = NULL;
+
return ret;
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index de7a3d2..51f00a9 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -350,8 +350,7 @@ XFAIL_TESTS_m32 = $(STACKTRACE_TESTS)
XFAIL_TESTS_mx32 = $(STACKTRACE_TESTS)
XFAIL_TESTS_x86_64 = int_0x80.gen.test
XFAIL_TESTS_x32 = int_0x80.gen.test
-XFAIL_TESTS = $(XFAIL_TESTS_$(MPERS_NAME)) $(XFAIL_TESTS_$(ARCH)) \
- looping_threads.test
+XFAIL_TESTS = $(XFAIL_TESTS_$(MPERS_NAME)) $(XFAIL_TESTS_$(ARCH))
TEST_LOG_COMPILER = env
AM_TEST_LOG_FLAGS = STRACE_ARCH=$(ARCH) STRACE_NATIVE_ARCH=$(NATIVE_ARCH) \
--
2.1.4

View File

@ -1,25 +0,0 @@
From cbbf708b4d2f8a66b07cf805f82edbe892c0bbf7 Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Sun, 2 Sep 2018 18:15:40 +0200
Subject: [PATCH] macros: add ROUNDUP macro
* macros.h (ROUNDUP): New macro.
---
macros.h | 4 ++++
1 file changed, 4 insertions(+)
Index: strace-4.24/macros.h
===================================================================
--- strace-4.24.orig/macros.h 2019-08-01 18:40:47.322659137 +0200
+++ strace-4.24/macros.h 2019-08-01 19:49:00.405972298 +0200
@@ -28,6 +28,10 @@
#endif
#define CLAMP(val, min, max) MIN(MAX(min, val), max)
+#ifndef ROUNDUP
+# define ROUNDUP(val_, div_) ((((val_) + (div_) - 1) / (div_)) * (div_))
+#endif
+
#ifndef offsetofend
# define offsetofend(type_, member_) \
(offsetof(type_, member_) + sizeof(((type_ *)0)->member_))

View File

@ -1,49 +0,0 @@
From 79acbcf2550f3a55108240558efb8b9c36eb8399 Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Tue, 19 Feb 2019 03:10:11 +0100
Subject: [PATCH] util: update dumpstr
Use a buffer of a limited size, use proper type for dump amount, avoid
hard-coding of byte counts, calculate output buffer size more accurately
and minimise its rewriting, pad offset with zeros in accordance
with expected output amount.
* defs.h (dumpstr): Change the type of len argument from int to
kernel_ulong_t.
* macros.h (ROUNDUP_DIV): New macro.
(ROUNDUP): Rewrite using ROUNDUP_DIV.
* util.c (ILOG2_ITER_): New macro.
(ilog2_64, ilog2_32): New functions.
(ilog2_klong): New macro, wrapper around ilog2_32/ilog2_64, so (potentially
more expensive) ilog2_64 is not used for ilog2 calculation
of a kernel_ulong_t-typed variable on architectures with 32-bit kernel long.
(dumpstr): Update.
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
---
defs.h | 2 +-
macros.h | 6 +-
util.c | 205 ++++++++++++++++++++++++++++++++++++++++++++++++++-------------
3 files changed, 169 insertions(+), 44 deletions(-)
diff --git a/macros.h b/macros.h
index 7f019480..61abf826 100644
--- a/macros.h
+++ b/macros.h
@@ -28,8 +28,12 @@
#endif
#define CLAMP(val, min, max) MIN(MAX(min, val), max)
+#ifndef ROUNDUP_DIV
+# define ROUNDUP_DIV(val_, div_) (((val_) + (div_) - 1) / (div_))
+#endif
+
#ifndef ROUNDUP
-# define ROUNDUP(val_, div_) ((((val_) + (div_) - 1) / (div_)) * (div_))
+# define ROUNDUP(val_, div_) (ROUNDUP_DIV((val_), (div_)) * (div_))
#endif
#ifndef offsetofend
--
2.13.6

View File

@ -1,42 +0,0 @@
From 7ada13f3a40e2f58aea335cf910666378e7dd99a Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Fri, 12 Jul 2019 14:38:33 +0200
Subject: [PATCH 1/3] evdev: avoid bit vector decoding on non-successful and 0
return codes
Reported by Clang.
strace/evdev.c:157:3: note: The value 0 is assigned to 'size'
# size = tcp->u_rval * 8;
# ^~~~~~~~~~~~~~~~~~~~~~
strace/evdev.c:158:2: warning: Declared variable-length array (VLA)
has zero size
# char decoded_arg[size];
# ^
* evdev.c (decode_bitset_): Bail out before decoded_arg VLA definition.
---
evdev.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/evdev.c b/evdev.c
index e402d26e..4b811cf8 100644
--- a/evdev.c
+++ b/evdev.c
@@ -155,6 +155,13 @@ decode_bitset_(struct tcb *const tcp, const kernel_ulong_t arg,
size = max_nr;
else
size = tcp->u_rval * 8;
+
+ if (syserror(tcp) || !size) {
+ printaddr(arg);
+
+ return RVAL_IOCTL_DECODED;
+ }
+
char decoded_arg[size];
if (umove_or_printaddr(tcp, arg, &decoded_arg))
--
2.13.6

View File

@ -1,57 +0,0 @@
From 96194ed74158f0b9976fae43a910ad14eaea141e Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Fri, 12 Jul 2019 14:57:28 +0200
Subject: [PATCH 2/3] evdev: fix array size calculation in decode_bitset_
max_nr is in bits (as it is a number of flags), result is in bytes, and
the array allocation has to be in personality words.
There's still an open question, however, what to do on big-endian
architectures when a non-divisible-by-4 value is returned.
* evdev.c (decode_bitset_): Declare size_bits, initialise it and use it
later instead of size; round up size by personality's word boundary.
---
evdev.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/evdev.c b/evdev.c
index 4b811cf8..a3d9cb55 100644
--- a/evdev.c
+++ b/evdev.c
@@ -151,10 +151,14 @@ decode_bitset_(struct tcb *const tcp, const kernel_ulong_t arg,
tprints(", ");
unsigned int size;
+ unsigned int size_bits;
+
if ((kernel_ulong_t) tcp->u_rval > max_nr / 8)
- size = max_nr;
+ size_bits = max_nr;
else
- size = tcp->u_rval * 8;
+ size_bits = tcp->u_rval * 8;
+
+ size = ROUNDUP(ROUNDUP_DIV(size_bits, 8), current_wordsize);
if (syserror(tcp) || !size) {
printaddr(arg);
@@ -170,13 +174,13 @@ decode_bitset_(struct tcb *const tcp, const kernel_ulong_t arg,
tprints("[");
int bit_displayed = 0;
- int i = next_set_bit(decoded_arg, 0, size);
+ int i = next_set_bit(decoded_arg, 0, size_bits);
if (i < 0) {
tprints(" 0 ");
} else {
printxval_dispatch(decode_nr, decode_nr_size, i, dflt, xt);
- while ((i = next_set_bit(decoded_arg, i + 1, size)) > 0) {
+ while ((i = next_set_bit(decoded_arg, i + 1, size_bits)) > 0) {
if (abbrev(tcp) && bit_displayed >= 3) {
tprints(", ...");
break;
--
2.13.6

View File

@ -1,795 +0,0 @@
From cdd8206af74fcb961f0179e21eacf5d55d23f0ac Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Fri, 12 Jul 2019 14:31:44 +0200
Subject: [PATCH 3/3] tests: test evdev bitset decoding more thoroughly
* tests/ioctl_evdev-success-v.test: Inject various values.
* tests/ioctl_evdev-success.test: Likewise.
* tests/ioctl_evdev-success.c (NUM_WORDS): New macro.
(struct evdev_check): Constify arg_ptr and print_arg args.
(invoke_test_syscall, test_evdev, print_input_absinfo, print_input_id,
print_mtslots): Add const qualifiers.
(print_getbit): Add const qualifiers, rewrite to expect trailing NULL
in the string array instead of leading string count.
(main): Set size for ev_more, ev_less, ev_zero arrays; replace leading
count element in ev_more_str, ev_less_str, ev_zero_str with trailing
NULL; replace ev_more_str and ev_less_str with ev_more_str_2/ev_less_str_2
and ev_more_str_3/ev_less_str_3 that differ by presence of flags that reside
beyond first two bytes; add static and const qualifiers where possible;
add key/key_sts_8/key_str_16 values; update a to provide either ev_more_str_2
or ev_more_str_3 and either key_str_8 or key_str_16 depending on inject_retval
value.
---
tests/ioctl_evdev-success-v.test | 15 +++---
tests/ioctl_evdev-success.c | 100 ++++++++++++++++++++++++++-------------
tests/ioctl_evdev-success.test | 15 +++---
3 files changed, 84 insertions(+), 46 deletions(-)
Index: strace-4.24/tests/ioctl_evdev-success-v.test
===================================================================
--- strace-4.24.orig/tests/ioctl_evdev-success-v.test 2019-08-01 18:40:58.009521546 +0200
+++ strace-4.24/tests/ioctl_evdev-success-v.test 2019-08-01 19:21:32.297062218 +0200
@@ -3,11 +3,14 @@
. "${srcdir=.}/scno_tampering.sh"
: ${IOCTL_INJECT_START=256}
-: ${IOCTL_INJECT_RETVAL=8}
run_prog
-run_strace -a16 -v -e trace=ioctl \
- -e inject=ioctl:retval="${IOCTL_INJECT_RETVAL}":when="${IOCTL_INJECT_START}+" \
- ../ioctl_evdev-success-v "${IOCTL_INJECT_START}" "${IOCTL_INJECT_RETVAL}"> "$EXP"
-grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT"
-match_diff "$OUT" "$EXP"
+
+for ret in 0 2 8 15 16; do
+ run_strace -a16 -v -e trace=ioctl \
+ -e inject=ioctl:retval="${ret}":when="${IOCTL_INJECT_START}+" \
+ ../ioctl_evdev-success-v \
+ "${IOCTL_INJECT_START}" "${ret}"> "$EXP.$ret"
+ grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT.$ret"
+ match_diff "$OUT.$ret" "$EXP.$ret"
+done
Index: strace-4.24/tests/ioctl_evdev-success.c
===================================================================
--- strace-4.24.orig/tests/ioctl_evdev-success.c 2019-08-01 18:40:58.009521546 +0200
+++ strace-4.24/tests/ioctl_evdev-success.c 2019-08-01 19:21:32.297062218 +0200
@@ -2,6 +2,7 @@
#ifdef HAVE_LINUX_INPUT_H
+# include <assert.h>
# include <inttypes.h>
# include <stdio.h>
# include <stdlib.h>
@@ -9,17 +10,19 @@
# include <linux/input.h>
# include "print_fields.h"
+# define NUM_WORDS 4
+
static const char *errstr;
struct evdev_check {
unsigned long cmd;
const char *cmd_str;
- void *arg_ptr;
- void (*print_arg)(long rc, void *ptr, void *arg);
+ const void *arg_ptr;
+ void (*print_arg)(long rc, const void *ptr, const void *arg);
};
static long
-invoke_test_syscall(unsigned long cmd, void *p)
+invoke_test_syscall(unsigned long cmd, const void *p)
{
long rc = ioctl(-1, cmd, p);
errstr = sprintrc(rc);
@@ -31,7 +34,7 @@
}
static void
-test_evdev(struct evdev_check *check, void *arg)
+test_evdev(struct evdev_check *check, const void *arg)
{
long rc = invoke_test_syscall(check->cmd, check->arg_ptr);
printf("ioctl(-1, %s, ", check->cmd_str);
@@ -43,9 +46,9 @@
}
static void
-print_input_absinfo(long rc, void *ptr, void *arg)
+print_input_absinfo(long rc, const void *ptr, const void *arg)
{
- struct input_absinfo *absinfo = ptr;
+ const struct input_absinfo *absinfo = ptr;
if (rc < 0) {
printf("%p", absinfo);
@@ -67,9 +70,9 @@
}
static void
-print_input_id(long rc, void *ptr, void *arg)
+print_input_id(long rc, const void *ptr, const void *arg)
{
- struct input_id *id = ptr;
+ const struct input_id *id = ptr;
if (rc < 0) {
printf("%p", id);
@@ -84,10 +87,10 @@
# ifdef EVIOCGMTSLOTS
static void
-print_mtslots(long rc, void *ptr, void *arg)
+print_mtslots(long rc, const void *ptr, const void *arg)
{
- int *buffer = ptr;
- const char **str = arg;
+ const int *buffer = ptr;
+ const char * const * str = arg;
int num = atoi(*(str + 1));
if (rc < 0) {
@@ -104,27 +107,26 @@
# endif
static void
-print_getbit(long rc, void *ptr, void *arg)
+print_getbit(long rc, const void *ptr, const void *arg)
{
- const char **str = arg;
- int num = atoi(*str);
+ const char * const *str = arg;
- if (rc < 0) {
+ if (rc <= 0) {
printf("%p", ptr);
return;
}
printf("[");
- printf("%s", *(str + 1));
- for (unsigned int i = 2; i <= (unsigned) num; i++) {
+ for (unsigned long i = 0; str[i]; i++) {
# if ! VERBOSE
- if (i > 4) {
+ if (i >= 4) {
printf(", ...");
break;
}
# endif
- printf(", ");
- printf("%s", *(str + i));
+ if (i)
+ printf(", ");
+ printf("%s", str[i]);
}
printf("]");
}
@@ -170,6 +172,7 @@
TAIL_ALLOC_OBJECT_CONST_PTR(struct input_id, id);
TAIL_ALLOC_OBJECT_CONST_PTR(struct input_absinfo, absinfo);
TAIL_ALLOC_OBJECT_CONST_PTR(int, bad_addr_slot);
+
# ifdef EVIOCGMTSLOTS
int mtslots[] = { ABS_MT_SLOT, 1, 3 };
/* we use the second element to indicate the number of values */
@@ -183,36 +186,65 @@
const char *invalid_mtslot_str[] = { invalid_str, "1", "1" };
# endif
+ enum { ULONG_BIT = sizeof(unsigned long) * 8 };
+
/* set more than 4 bits */
- unsigned long ev_more[] = { 1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED | 1 << EV_SND | 1 << EV_PWR };
- /* we use the first element to indicate the number of set bits */
- /* ev_more_str[0] is "5" so the number of set bits is 5 */
- const char *ev_more_str[] = { "5", "EV_ABS", "EV_MSC", "EV_LED", "EV_SND", "EV_PWR" };
+ static const unsigned long ev_more[NUM_WORDS] = {
+ 1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED | 1 << EV_SND
+ | 1 << EV_PWR };
+ static const char * const ev_more_str_2[] = {
+ "EV_ABS", "EV_MSC", NULL };
+ static const char * const ev_more_str_3[] = {
+ "EV_ABS", "EV_MSC", "EV_LED", "EV_SND", "EV_PWR", NULL };
/* set less than 4 bits */
- unsigned long ev_less[] = { 1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED };
- const char *ev_less_str[] = { "3", "EV_ABS", "EV_MSC", "EV_LED" };
+ static const unsigned long ev_less[NUM_WORDS] = {
+ 1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED };
+ static const char * const ev_less_str_2[] = {
+ "EV_ABS", "EV_MSC", NULL };
+ static const char * const ev_less_str_3[] = {
+ "EV_ABS", "EV_MSC", "EV_LED", NULL };
/* set zero bit */
- unsigned long ev_zero[] = { 0x0 };
- const char *ev_zero_str[] = { "0", " 0 " };
+ static const unsigned long ev_zero[NUM_WORDS] = { 0x0 };
+ static const char * const ev_zero_str[] = { " 0 ", NULL };
/* KEY_MAX is 0x2ff which is greater than retval * 8 */
- unsigned long key[] = { 1 << KEY_1 | 1 << KEY_2, 0 };
- const char *key_str[] = { "2", "KEY_1", "KEY_2" };
+ static const unsigned long key[NUM_WORDS] = {
+ 1 << KEY_1 | 1 << KEY_2,
+ [ KEY_F12 / ULONG_BIT ] = 1 << (KEY_F12 % ULONG_BIT) };
+
+ static const char * const key_str_8[] = {
+ "KEY_1", "KEY_2", NULL };
+ static const char * const key_str_16[] = {
+ "KEY_1", "KEY_2", "KEY_F12", NULL };
+
+ assert(sizeof(ev_more) >= (unsigned long) inject_retval);
+ assert(sizeof(ev_less) >= (unsigned long) inject_retval);
+ assert(sizeof(ev_zero) >= (unsigned long) inject_retval);
+ assert(sizeof(key) >= (unsigned long) inject_retval);
struct {
struct evdev_check check;
- void *ptr;
+ const void *ptr;
} a[] = {
{ { ARG_STR(EVIOCGID), id, print_input_id }, NULL },
{ { ARG_STR(EVIOCGABS(ABS_X)), absinfo, print_input_absinfo }, NULL },
{ { ARG_STR(EVIOCGABS(ABS_Y)), absinfo, print_input_absinfo }, NULL },
{ { ARG_STR(EVIOCGABS(ABS_Y)), absinfo, print_input_absinfo }, NULL },
- { { ARG_STR(EVIOCGBIT(0, 0)), ev_more, print_getbit }, &ev_more_str },
- { { ARG_STR(EVIOCGBIT(0, 0)), ev_less, print_getbit }, &ev_less_str },
+ { { ARG_STR(EVIOCGBIT(0, 0)), ev_more, print_getbit },
+ inject_retval * 8 <= EV_LED
+ ? (const void *) &ev_more_str_2
+ : (const void *) &ev_more_str_3 },
+ { { ARG_STR(EVIOCGBIT(0, 0)), ev_less, print_getbit },
+ inject_retval * 8 <= EV_LED
+ ? (const void *) &ev_less_str_2
+ : (const void *) &ev_less_str_3 },
{ { ARG_STR(EVIOCGBIT(0, 0)), ev_zero, print_getbit }, &ev_zero_str },
- { { ARG_STR(EVIOCGBIT(EV_KEY, 0)), key, print_getbit }, &key_str},
+ { { ARG_STR(EVIOCGBIT(EV_KEY, 0)), key, print_getbit },
+ inject_retval * 8 <= KEY_F12
+ ? (const void *) &key_str_8
+ : (const void *) &key_str_16 },
# ifdef EVIOCGMTSLOTS
{ { ARG_STR(EVIOCGMTSLOTS(12)), mtslots, print_mtslots }, &mtslots_str },
{ { ARG_STR(EVIOCGMTSLOTS(8)), invalid_mtslot, print_mtslots }, &invalid_mtslot_str }
Index: strace-4.24/tests/ioctl_evdev-success.test
===================================================================
--- strace-4.24.orig/tests/ioctl_evdev-success.test 2019-08-01 18:40:58.009521546 +0200
+++ strace-4.24/tests/ioctl_evdev-success.test 2019-08-01 19:21:32.298062205 +0200
@@ -3,11 +3,14 @@
. "${srcdir=.}/scno_tampering.sh"
: ${IOCTL_INJECT_START=256}
-: ${IOCTL_INJECT_RETVAL=8}
run_prog
-run_strace -a16 -e trace=ioctl \
- -e inject=ioctl:retval="${IOCTL_INJECT_RETVAL}":when="${IOCTL_INJECT_START}+" \
- ../ioctl_evdev-success "${IOCTL_INJECT_START}" "${IOCTL_INJECT_RETVAL}"> "$EXP"
-grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT"
-match_diff "$OUT" "$EXP"
+
+for ret in 0 2 8 15 16; do
+ run_strace -a16 -e trace=ioctl \
+ -e inject=ioctl:retval="${ret}":when="${IOCTL_INJECT_START}+" \
+ ../ioctl_evdev-success \
+ "${IOCTL_INJECT_START}" "${ret}"> "$EXP.${ret}"
+ grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT.$ret"
+ match_diff "$OUT.$ret" "$EXP.$ret"
+done
Index: strace-4.24/tests-m32/ioctl_evdev-success-v.test
===================================================================
--- strace-4.24.orig/tests-m32/ioctl_evdev-success-v.test 2019-08-01 18:40:58.009521546 +0200
+++ strace-4.24/tests-m32/ioctl_evdev-success-v.test 2019-08-01 19:21:32.298062205 +0200
@@ -3,11 +3,14 @@
. "${srcdir=.}/scno_tampering.sh"
: ${IOCTL_INJECT_START=256}
-: ${IOCTL_INJECT_RETVAL=8}
run_prog
-run_strace -a16 -v -e trace=ioctl \
- -e inject=ioctl:retval="${IOCTL_INJECT_RETVAL}":when="${IOCTL_INJECT_START}+" \
- ../ioctl_evdev-success-v "${IOCTL_INJECT_START}" "${IOCTL_INJECT_RETVAL}"> "$EXP"
-grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT"
-match_diff "$OUT" "$EXP"
+
+for ret in 0 2 8 15 16; do
+ run_strace -a16 -v -e trace=ioctl \
+ -e inject=ioctl:retval="${ret}":when="${IOCTL_INJECT_START}+" \
+ ../ioctl_evdev-success-v \
+ "${IOCTL_INJECT_START}" "${ret}"> "$EXP.$ret"
+ grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT.$ret"
+ match_diff "$OUT.$ret" "$EXP.$ret"
+done
Index: strace-4.24/tests-m32/ioctl_evdev-success.test
===================================================================
--- strace-4.24.orig/tests-m32/ioctl_evdev-success.test 2019-08-01 18:40:58.009521546 +0200
+++ strace-4.24/tests-m32/ioctl_evdev-success.test 2019-08-01 19:21:32.298062205 +0200
@@ -3,11 +3,14 @@
. "${srcdir=.}/scno_tampering.sh"
: ${IOCTL_INJECT_START=256}
-: ${IOCTL_INJECT_RETVAL=8}
run_prog
-run_strace -a16 -e trace=ioctl \
- -e inject=ioctl:retval="${IOCTL_INJECT_RETVAL}":when="${IOCTL_INJECT_START}+" \
- ../ioctl_evdev-success "${IOCTL_INJECT_START}" "${IOCTL_INJECT_RETVAL}"> "$EXP"
-grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT"
-match_diff "$OUT" "$EXP"
+
+for ret in 0 2 8 15 16; do
+ run_strace -a16 -e trace=ioctl \
+ -e inject=ioctl:retval="${ret}":when="${IOCTL_INJECT_START}+" \
+ ../ioctl_evdev-success \
+ "${IOCTL_INJECT_START}" "${ret}"> "$EXP.${ret}"
+ grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT.$ret"
+ match_diff "$OUT.$ret" "$EXP.$ret"
+done
Index: strace-4.24/tests-mx32/ioctl_evdev-success-v.test
===================================================================
--- strace-4.24.orig/tests-mx32/ioctl_evdev-success-v.test 2019-08-01 18:40:58.009521546 +0200
+++ strace-4.24/tests-mx32/ioctl_evdev-success-v.test 2019-08-01 19:21:32.298062205 +0200
@@ -3,11 +3,14 @@
. "${srcdir=.}/scno_tampering.sh"
: ${IOCTL_INJECT_START=256}
-: ${IOCTL_INJECT_RETVAL=8}
run_prog
-run_strace -a16 -v -e trace=ioctl \
- -e inject=ioctl:retval="${IOCTL_INJECT_RETVAL}":when="${IOCTL_INJECT_START}+" \
- ../ioctl_evdev-success-v "${IOCTL_INJECT_START}" "${IOCTL_INJECT_RETVAL}"> "$EXP"
-grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT"
-match_diff "$OUT" "$EXP"
+
+for ret in 0 2 8 15 16; do
+ run_strace -a16 -v -e trace=ioctl \
+ -e inject=ioctl:retval="${ret}":when="${IOCTL_INJECT_START}+" \
+ ../ioctl_evdev-success-v \
+ "${IOCTL_INJECT_START}" "${ret}"> "$EXP.$ret"
+ grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT.$ret"
+ match_diff "$OUT.$ret" "$EXP.$ret"
+done
Index: strace-4.24/tests-mx32/ioctl_evdev-success.test
===================================================================
--- strace-4.24.orig/tests-mx32/ioctl_evdev-success.test 2019-08-01 18:40:58.009521546 +0200
+++ strace-4.24/tests-mx32/ioctl_evdev-success.test 2019-08-01 19:21:32.299062192 +0200
@@ -3,11 +3,14 @@
. "${srcdir=.}/scno_tampering.sh"
: ${IOCTL_INJECT_START=256}
-: ${IOCTL_INJECT_RETVAL=8}
run_prog
-run_strace -a16 -e trace=ioctl \
- -e inject=ioctl:retval="${IOCTL_INJECT_RETVAL}":when="${IOCTL_INJECT_START}+" \
- ../ioctl_evdev-success "${IOCTL_INJECT_START}" "${IOCTL_INJECT_RETVAL}"> "$EXP"
-grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT"
-match_diff "$OUT" "$EXP"
+
+for ret in 0 2 8 15 16; do
+ run_strace -a16 -e trace=ioctl \
+ -e inject=ioctl:retval="${ret}":when="${IOCTL_INJECT_START}+" \
+ ../ioctl_evdev-success \
+ "${IOCTL_INJECT_START}" "${ret}"> "$EXP.${ret}"
+ grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT.$ret"
+ match_diff "$OUT.$ret" "$EXP.$ret"
+done
Index: strace-4.24/tests-m32/ioctl_evdev-success.c
===================================================================
--- strace-4.24.orig/tests-m32/ioctl_evdev-success.c 2019-08-01 18:40:58.009521546 +0200
+++ strace-4.24/tests-m32/ioctl_evdev-success.c 2019-08-29 12:09:27.898700830 +0200
@@ -2,6 +2,7 @@
#ifdef HAVE_LINUX_INPUT_H
+# include <assert.h>
# include <inttypes.h>
# include <stdio.h>
# include <stdlib.h>
@@ -9,17 +10,19 @@
# include <linux/input.h>
# include "print_fields.h"
+# define NUM_WORDS 4
+
static const char *errstr;
struct evdev_check {
unsigned long cmd;
const char *cmd_str;
- void *arg_ptr;
- void (*print_arg)(long rc, void *ptr, void *arg);
+ const void *arg_ptr;
+ void (*print_arg)(long rc, const void *ptr, const void *arg);
};
static long
-invoke_test_syscall(unsigned long cmd, void *p)
+invoke_test_syscall(unsigned long cmd, const void *p)
{
long rc = ioctl(-1, cmd, p);
errstr = sprintrc(rc);
@@ -31,7 +34,7 @@
}
static void
-test_evdev(struct evdev_check *check, void *arg)
+test_evdev(struct evdev_check *check, const void *arg)
{
long rc = invoke_test_syscall(check->cmd, check->arg_ptr);
printf("ioctl(-1, %s, ", check->cmd_str);
@@ -43,9 +46,9 @@
}
static void
-print_input_absinfo(long rc, void *ptr, void *arg)
+print_input_absinfo(long rc, const void *ptr, const void *arg)
{
- struct input_absinfo *absinfo = ptr;
+ const struct input_absinfo *absinfo = ptr;
if (rc < 0) {
printf("%p", absinfo);
@@ -67,9 +70,9 @@
}
static void
-print_input_id(long rc, void *ptr, void *arg)
+print_input_id(long rc, const void *ptr, const void *arg)
{
- struct input_id *id = ptr;
+ const struct input_id *id = ptr;
if (rc < 0) {
printf("%p", id);
@@ -84,10 +87,10 @@
# ifdef EVIOCGMTSLOTS
static void
-print_mtslots(long rc, void *ptr, void *arg)
+print_mtslots(long rc, const void *ptr, const void *arg)
{
- int *buffer = ptr;
- const char **str = arg;
+ const int *buffer = ptr;
+ const char * const * str = arg;
int num = atoi(*(str + 1));
if (rc < 0) {
@@ -104,27 +107,26 @@
# endif
static void
-print_getbit(long rc, void *ptr, void *arg)
+print_getbit(long rc, const void *ptr, const void *arg)
{
- const char **str = arg;
- int num = atoi(*str);
+ const char * const *str = arg;
- if (rc < 0) {
+ if (rc <= 0) {
printf("%p", ptr);
return;
}
printf("[");
- printf("%s", *(str + 1));
- for (unsigned int i = 2; i <= (unsigned) num; i++) {
+ for (unsigned long i = 0; str[i]; i++) {
# if ! VERBOSE
- if (i > 4) {
+ if (i >= 4) {
printf(", ...");
break;
}
# endif
- printf(", ");
- printf("%s", *(str + i));
+ if (i)
+ printf(", ");
+ printf("%s", str[i]);
}
printf("]");
}
@@ -170,6 +172,7 @@
TAIL_ALLOC_OBJECT_CONST_PTR(struct input_id, id);
TAIL_ALLOC_OBJECT_CONST_PTR(struct input_absinfo, absinfo);
TAIL_ALLOC_OBJECT_CONST_PTR(int, bad_addr_slot);
+
# ifdef EVIOCGMTSLOTS
int mtslots[] = { ABS_MT_SLOT, 1, 3 };
/* we use the second element to indicate the number of values */
@@ -183,36 +186,65 @@
const char *invalid_mtslot_str[] = { invalid_str, "1", "1" };
# endif
+ enum { ULONG_BIT = sizeof(unsigned long) * 8 };
+
/* set more than 4 bits */
- unsigned long ev_more[] = { 1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED | 1 << EV_SND | 1 << EV_PWR };
- /* we use the first element to indicate the number of set bits */
- /* ev_more_str[0] is "5" so the number of set bits is 5 */
- const char *ev_more_str[] = { "5", "EV_ABS", "EV_MSC", "EV_LED", "EV_SND", "EV_PWR" };
+ static const unsigned long ev_more[NUM_WORDS] = {
+ 1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED | 1 << EV_SND
+ | 1 << EV_PWR };
+ static const char * const ev_more_str_2[] = {
+ "EV_ABS", "EV_MSC", NULL };
+ static const char * const ev_more_str_3[] = {
+ "EV_ABS", "EV_MSC", "EV_LED", "EV_SND", "EV_PWR", NULL };
/* set less than 4 bits */
- unsigned long ev_less[] = { 1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED };
- const char *ev_less_str[] = { "3", "EV_ABS", "EV_MSC", "EV_LED" };
+ static const unsigned long ev_less[NUM_WORDS] = {
+ 1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED };
+ static const char * const ev_less_str_2[] = {
+ "EV_ABS", "EV_MSC", NULL };
+ static const char * const ev_less_str_3[] = {
+ "EV_ABS", "EV_MSC", "EV_LED", NULL };
/* set zero bit */
- unsigned long ev_zero[] = { 0x0 };
- const char *ev_zero_str[] = { "0", " 0 " };
+ static const unsigned long ev_zero[NUM_WORDS] = { 0x0 };
+ static const char * const ev_zero_str[] = { " 0 ", NULL };
/* KEY_MAX is 0x2ff which is greater than retval * 8 */
- unsigned long key[] = { 1 << KEY_1 | 1 << KEY_2, 0 };
- const char *key_str[] = { "2", "KEY_1", "KEY_2" };
+ static const unsigned long key[NUM_WORDS] = {
+ 1 << KEY_1 | 1 << KEY_2,
+ [ KEY_F12 / ULONG_BIT ] = 1 << (KEY_F12 % ULONG_BIT) };
+
+ static const char * const key_str_8[] = {
+ "KEY_1", "KEY_2", NULL };
+ static const char * const key_str_16[] = {
+ "KEY_1", "KEY_2", "KEY_F12", NULL };
+
+ assert(sizeof(ev_more) >= (unsigned long) inject_retval);
+ assert(sizeof(ev_less) >= (unsigned long) inject_retval);
+ assert(sizeof(ev_zero) >= (unsigned long) inject_retval);
+ assert(sizeof(key) >= (unsigned long) inject_retval);
struct {
struct evdev_check check;
- void *ptr;
+ const void *ptr;
} a[] = {
{ { ARG_STR(EVIOCGID), id, print_input_id }, NULL },
{ { ARG_STR(EVIOCGABS(ABS_X)), absinfo, print_input_absinfo }, NULL },
{ { ARG_STR(EVIOCGABS(ABS_Y)), absinfo, print_input_absinfo }, NULL },
{ { ARG_STR(EVIOCGABS(ABS_Y)), absinfo, print_input_absinfo }, NULL },
- { { ARG_STR(EVIOCGBIT(0, 0)), ev_more, print_getbit }, &ev_more_str },
- { { ARG_STR(EVIOCGBIT(0, 0)), ev_less, print_getbit }, &ev_less_str },
+ { { ARG_STR(EVIOCGBIT(0, 0)), ev_more, print_getbit },
+ inject_retval * 8 <= EV_LED
+ ? (const void *) &ev_more_str_2
+ : (const void *) &ev_more_str_3 },
+ { { ARG_STR(EVIOCGBIT(0, 0)), ev_less, print_getbit },
+ inject_retval * 8 <= EV_LED
+ ? (const void *) &ev_less_str_2
+ : (const void *) &ev_less_str_3 },
{ { ARG_STR(EVIOCGBIT(0, 0)), ev_zero, print_getbit }, &ev_zero_str },
- { { ARG_STR(EVIOCGBIT(EV_KEY, 0)), key, print_getbit }, &key_str},
+ { { ARG_STR(EVIOCGBIT(EV_KEY, 0)), key, print_getbit },
+ inject_retval * 8 <= KEY_F12
+ ? (const void *) &key_str_8
+ : (const void *) &key_str_16 },
# ifdef EVIOCGMTSLOTS
{ { ARG_STR(EVIOCGMTSLOTS(12)), mtslots, print_mtslots }, &mtslots_str },
{ { ARG_STR(EVIOCGMTSLOTS(8)), invalid_mtslot, print_mtslots }, &invalid_mtslot_str }
Index: strace-4.24/tests-mx32/ioctl_evdev-success.c
===================================================================
--- strace-4.24.orig/tests-mx32/ioctl_evdev-success.c 2019-08-01 18:40:58.009521546 +0200
+++ strace-4.24/tests-mx32/ioctl_evdev-success.c 2019-08-29 12:09:30.350669261 +0200
@@ -2,6 +2,7 @@
#ifdef HAVE_LINUX_INPUT_H
+# include <assert.h>
# include <inttypes.h>
# include <stdio.h>
# include <stdlib.h>
@@ -9,17 +10,19 @@
# include <linux/input.h>
# include "print_fields.h"
+# define NUM_WORDS 4
+
static const char *errstr;
struct evdev_check {
unsigned long cmd;
const char *cmd_str;
- void *arg_ptr;
- void (*print_arg)(long rc, void *ptr, void *arg);
+ const void *arg_ptr;
+ void (*print_arg)(long rc, const void *ptr, const void *arg);
};
static long
-invoke_test_syscall(unsigned long cmd, void *p)
+invoke_test_syscall(unsigned long cmd, const void *p)
{
long rc = ioctl(-1, cmd, p);
errstr = sprintrc(rc);
@@ -31,7 +34,7 @@
}
static void
-test_evdev(struct evdev_check *check, void *arg)
+test_evdev(struct evdev_check *check, const void *arg)
{
long rc = invoke_test_syscall(check->cmd, check->arg_ptr);
printf("ioctl(-1, %s, ", check->cmd_str);
@@ -43,9 +46,9 @@
}
static void
-print_input_absinfo(long rc, void *ptr, void *arg)
+print_input_absinfo(long rc, const void *ptr, const void *arg)
{
- struct input_absinfo *absinfo = ptr;
+ const struct input_absinfo *absinfo = ptr;
if (rc < 0) {
printf("%p", absinfo);
@@ -67,9 +70,9 @@
}
static void
-print_input_id(long rc, void *ptr, void *arg)
+print_input_id(long rc, const void *ptr, const void *arg)
{
- struct input_id *id = ptr;
+ const struct input_id *id = ptr;
if (rc < 0) {
printf("%p", id);
@@ -84,10 +87,10 @@
# ifdef EVIOCGMTSLOTS
static void
-print_mtslots(long rc, void *ptr, void *arg)
+print_mtslots(long rc, const void *ptr, const void *arg)
{
- int *buffer = ptr;
- const char **str = arg;
+ const int *buffer = ptr;
+ const char * const * str = arg;
int num = atoi(*(str + 1));
if (rc < 0) {
@@ -104,27 +107,26 @@
# endif
static void
-print_getbit(long rc, void *ptr, void *arg)
+print_getbit(long rc, const void *ptr, const void *arg)
{
- const char **str = arg;
- int num = atoi(*str);
+ const char * const *str = arg;
- if (rc < 0) {
+ if (rc <= 0) {
printf("%p", ptr);
return;
}
printf("[");
- printf("%s", *(str + 1));
- for (unsigned int i = 2; i <= (unsigned) num; i++) {
+ for (unsigned long i = 0; str[i]; i++) {
# if ! VERBOSE
- if (i > 4) {
+ if (i >= 4) {
printf(", ...");
break;
}
# endif
- printf(", ");
- printf("%s", *(str + i));
+ if (i)
+ printf(", ");
+ printf("%s", str[i]);
}
printf("]");
}
@@ -170,6 +172,7 @@
TAIL_ALLOC_OBJECT_CONST_PTR(struct input_id, id);
TAIL_ALLOC_OBJECT_CONST_PTR(struct input_absinfo, absinfo);
TAIL_ALLOC_OBJECT_CONST_PTR(int, bad_addr_slot);
+
# ifdef EVIOCGMTSLOTS
int mtslots[] = { ABS_MT_SLOT, 1, 3 };
/* we use the second element to indicate the number of values */
@@ -183,36 +186,65 @@
const char *invalid_mtslot_str[] = { invalid_str, "1", "1" };
# endif
+ enum { ULONG_BIT = sizeof(unsigned long) * 8 };
+
/* set more than 4 bits */
- unsigned long ev_more[] = { 1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED | 1 << EV_SND | 1 << EV_PWR };
- /* we use the first element to indicate the number of set bits */
- /* ev_more_str[0] is "5" so the number of set bits is 5 */
- const char *ev_more_str[] = { "5", "EV_ABS", "EV_MSC", "EV_LED", "EV_SND", "EV_PWR" };
+ static const unsigned long ev_more[NUM_WORDS] = {
+ 1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED | 1 << EV_SND
+ | 1 << EV_PWR };
+ static const char * const ev_more_str_2[] = {
+ "EV_ABS", "EV_MSC", NULL };
+ static const char * const ev_more_str_3[] = {
+ "EV_ABS", "EV_MSC", "EV_LED", "EV_SND", "EV_PWR", NULL };
/* set less than 4 bits */
- unsigned long ev_less[] = { 1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED };
- const char *ev_less_str[] = { "3", "EV_ABS", "EV_MSC", "EV_LED" };
+ static const unsigned long ev_less[NUM_WORDS] = {
+ 1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED };
+ static const char * const ev_less_str_2[] = {
+ "EV_ABS", "EV_MSC", NULL };
+ static const char * const ev_less_str_3[] = {
+ "EV_ABS", "EV_MSC", "EV_LED", NULL };
/* set zero bit */
- unsigned long ev_zero[] = { 0x0 };
- const char *ev_zero_str[] = { "0", " 0 " };
+ static const unsigned long ev_zero[NUM_WORDS] = { 0x0 };
+ static const char * const ev_zero_str[] = { " 0 ", NULL };
/* KEY_MAX is 0x2ff which is greater than retval * 8 */
- unsigned long key[] = { 1 << KEY_1 | 1 << KEY_2, 0 };
- const char *key_str[] = { "2", "KEY_1", "KEY_2" };
+ static const unsigned long key[NUM_WORDS] = {
+ 1 << KEY_1 | 1 << KEY_2,
+ [ KEY_F12 / ULONG_BIT ] = 1 << (KEY_F12 % ULONG_BIT) };
+
+ static const char * const key_str_8[] = {
+ "KEY_1", "KEY_2", NULL };
+ static const char * const key_str_16[] = {
+ "KEY_1", "KEY_2", "KEY_F12", NULL };
+
+ assert(sizeof(ev_more) >= (unsigned long) inject_retval);
+ assert(sizeof(ev_less) >= (unsigned long) inject_retval);
+ assert(sizeof(ev_zero) >= (unsigned long) inject_retval);
+ assert(sizeof(key) >= (unsigned long) inject_retval);
struct {
struct evdev_check check;
- void *ptr;
+ const void *ptr;
} a[] = {
{ { ARG_STR(EVIOCGID), id, print_input_id }, NULL },
{ { ARG_STR(EVIOCGABS(ABS_X)), absinfo, print_input_absinfo }, NULL },
{ { ARG_STR(EVIOCGABS(ABS_Y)), absinfo, print_input_absinfo }, NULL },
{ { ARG_STR(EVIOCGABS(ABS_Y)), absinfo, print_input_absinfo }, NULL },
- { { ARG_STR(EVIOCGBIT(0, 0)), ev_more, print_getbit }, &ev_more_str },
- { { ARG_STR(EVIOCGBIT(0, 0)), ev_less, print_getbit }, &ev_less_str },
+ { { ARG_STR(EVIOCGBIT(0, 0)), ev_more, print_getbit },
+ inject_retval * 8 <= EV_LED
+ ? (const void *) &ev_more_str_2
+ : (const void *) &ev_more_str_3 },
+ { { ARG_STR(EVIOCGBIT(0, 0)), ev_less, print_getbit },
+ inject_retval * 8 <= EV_LED
+ ? (const void *) &ev_less_str_2
+ : (const void *) &ev_less_str_3 },
{ { ARG_STR(EVIOCGBIT(0, 0)), ev_zero, print_getbit }, &ev_zero_str },
- { { ARG_STR(EVIOCGBIT(EV_KEY, 0)), key, print_getbit }, &key_str},
+ { { ARG_STR(EVIOCGBIT(EV_KEY, 0)), key, print_getbit },
+ inject_retval * 8 <= KEY_F12
+ ? (const void *) &key_str_8
+ : (const void *) &key_str_16 },
# ifdef EVIOCGMTSLOTS
{ { ARG_STR(EVIOCGMTSLOTS(12)), mtslots, print_mtslots }, &mtslots_str },
{ { ARG_STR(EVIOCGMTSLOTS(8)), invalid_mtslot, print_mtslots }, &invalid_mtslot_str }

View File

@ -1,37 +0,0 @@
From f476724ea13d6fae08219aba75a7669eb3e836b3 Mon Sep 17 00:00:00 2001
From: Janosch Frank <frankja@linux.ibm.com>
Date: Fri, 30 Nov 2018 16:41:39 +0100
Subject: [PATCH] s390x: beautify sthyi data tail prints
The test already expects a ", " before the print of struct
padding. Let's add it to s390.c to make the output look a bit nicer and
fix test runs on z/VM that have padding at the end of the STHYI structs.
* s390.c (decode_ebcdic): Add missing comma.
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
---
s390.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/s390.c b/s390.c
index 422c08d..a00c274 100644
--- a/s390.c
+++ b/s390.c
@@ -472,10 +472,12 @@ decode_ebcdic(const char *ebcdic, char *ascii, size_t size)
do { \
if ((size_) > sizeof(*(hdr_)) && \
!is_filled((char *) ((hdr_) + 1), '\0', \
- (size_) - sizeof(*(hdr_)))) \
+ (size_) - sizeof(*(hdr_)))) { \
+ tprints(", "); \
print_quoted_string((char *) ((hdr_) + 1), \
(size_) - sizeof(*(hdr_)), \
QUOTE_FORCE_HEX); \
+ } \
} while (0)
static void
--
2.1.4

View File

@ -1,32 +0,0 @@
From 91281fec7823f1cd3df3374fbcbd14af52a3fa1b Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Wed, 14 Aug 2019 17:15:47 +0200
Subject: [PATCH] v4l2: avoid shifting left a signed number by 31 bit
cppcheck warns about it with the following diagnostics:
error[shiftTooManyBitsSigned]: Shifting signed 32-bit value by 31 bits is
undefined behaviour
* v4l2.c [!v4l2_fourcc_be] (v4l2_fourcc_be): Shift left 1U and not 1 in
order to get 0x80000000.
---
v4l2.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/v4l2.c b/v4l2.c
index 5da457c..505e7b8 100644
--- a/v4l2.c
+++ b/v4l2.c
@@ -47,7 +47,7 @@ typedef struct v4l2_standard struct_v4l2_standard;
/* v4l2_fourcc_be was added by Linux commit v3.18-rc1~101^2^2~127 */
#ifndef v4l2_fourcc_be
-# define v4l2_fourcc_be(a, b, c, d) (v4l2_fourcc(a, b, c, d) | (1 << 31))
+# define v4l2_fourcc_be(a, b, c, d) (v4l2_fourcc(a, b, c, d) | (1U << 31))
#endif
#define FMT_FRACT "%u/%u"
--
2.1.4

View File

@ -1,55 +0,0 @@
From 522ad3a0e73148dadd2480cd9cec84d9112b2e57 Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Tue, 4 Sep 2018 14:48:13 +0200
Subject: [PATCH] syscall.c: avoid infinite loop in subcalls parsing
clang complains about it, so it might be a good reason to refactor it
into something more linear.
* syscall.c (syscall_entering_decode): Put syscall subcall decoding
before ipc/socket subcall decoding, remove the loop.
---
syscall.c | 19 ++++++-------------
1 file changed, 6 insertions(+), 13 deletions(-)
diff --git a/syscall.c b/syscall.c
index bae7343..a67d744 100644
--- a/syscall.c
+++ b/syscall.c
@@ -579,11 +579,13 @@ syscall_entering_decode(struct tcb *tcp)
return res;
}
+# ifdef SYS_syscall_subcall
+ if (tcp_sysent(tcp)->sen == SEN_syscall)
+ decode_syscall_subcall(tcp);
+# endif
#if defined SYS_ipc_subcall \
- || defined SYS_socket_subcall \
- || defined SYS_syscall_subcall
- for (;;) {
- switch (tcp_sysent(tcp)->sen) {
+ || defined SYS_socket_subcall
+ switch (tcp_sysent(tcp)->sen) {
# ifdef SYS_ipc_subcall
case SEN_ipc:
decode_ipc_subcall(tcp);
@@ -594,15 +596,6 @@ syscall_entering_decode(struct tcb *tcp)
decode_socket_subcall(tcp);
break;
# endif
-# ifdef SYS_syscall_subcall
- case SEN_syscall:
- decode_syscall_subcall(tcp);
- if (tcp_sysent(tcp)->sen != SEN_syscall)
- continue;
- break;
-# endif
- }
- break;
}
#endif
--
2.1.4

View File

@ -1,36 +0,0 @@
From 9446038e9face3313373ca5f7539476789fd4660 Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Tue, 18 Dec 2018 05:37:30 +0100
Subject: [PATCH] kvm: avoid bogus vcpu_info assignment in vcpu_register
Also reformat code a bit to make nesting a bit clearer.
Reported by Clang.
* kvm.c (vcpu_register): Do not assign vcpu_alloc result to vcpu_info
as this value is not used afterwards in the function.
---
kvm.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/kvm.c b/kvm.c
index 984a75e..8bdf1cc 100644
--- a/kvm.c
+++ b/kvm.c
@@ -76,10 +76,9 @@ vcpu_register(struct tcb *const tcp, int fd, int cpuid)
struct vcpu_info *vcpu_info = vcpu_find(tcp, fd);
- if (!vcpu_info)
- vcpu_info = vcpu_alloc(tcp, fd, cpuid);
- else if (vcpu_info->cpuid != cpuid)
- {
+ if (!vcpu_info) {
+ vcpu_alloc(tcp, fd, cpuid);
+ } else if (vcpu_info->cpuid != cpuid) {
vcpu_info->cpuid = cpuid;
vcpu_info->resolved = false;
}
--
2.1.4

View File

@ -1,365 +0,0 @@
From c26541c73c3b4be2977e719d77287255eb346cdf Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Thu, 17 Oct 2019 13:13:45 +0200
Subject: [PATCH] xlat: use unsgined type for mount_flags fallback values
Reported by cppcheck:
strace/xlat/mount_flags.h:256: error[shiftTooManyBitsSigned]:
Shifting signed 32-bit value by 31 bits is undefined behaviour
# 254| XLAT(MS_BORN),
# 255| XLAT(MS_ACTIVE),
# 256|-> XLAT(MS_NOUSER),
# 257| XLAT_END
# 258| };
* xlat/mount_flags.in: Use 1U instead of 1 as a bit shifting operand.
References: https://bugzilla.redhat.com/show_bug.cgi?id=1747524
---
xlat/mount_flags.in | 60 ++++++++++++++++++++++++++---------------------------
1 file changed, 30 insertions(+), 30 deletions(-)
Index: strace-4.24/xlat/mount_flags.in
===================================================================
--- strace-4.24.orig/xlat/mount_flags.in 2018-04-24 02:35:27.000000000 +0200
+++ strace-4.24/xlat/mount_flags.in 2019-12-02 18:37:39.403710911 +0100
@@ -1,30 +1,30 @@
-MS_RDONLY 1
-MS_NOSUID 2
-MS_NODEV 4
-MS_NOEXEC 8
-MS_SYNCHRONOUS 16
-MS_REMOUNT 32
-MS_MANDLOCK 64
-MS_DIRSYNC 128
-MS_NOATIME 1024
-MS_NODIRATIME 2048
-MS_BIND 4096
-MS_MOVE 8192
-MS_REC 16384
-MS_SILENT 32768
-MS_POSIXACL (1<<16)
-MS_UNBINDABLE (1<<17)
-MS_PRIVATE (1<<18)
-MS_SLAVE (1<<19)
-MS_SHARED (1<<20)
-MS_RELATIME (1<<21)
-MS_KERNMOUNT (1<<22)
-MS_I_VERSION (1<<23)
-MS_STRICTATIME (1<<24)
-MS_LAZYTIME (1<<25)
-MS_SUBMOUNT (1<<26)
-MS_NOREMOTELOCK (1<<27)
-MS_NOSEC (1<<28)
-MS_BORN (1<<29)
-MS_ACTIVE (1<<30)
-MS_NOUSER (1<<31)
+MS_RDONLY (1U<<0)
+MS_NOSUID (1U<<1)
+MS_NODEV (1U<<2)
+MS_NOEXEC (1U<<3)
+MS_SYNCHRONOUS (1U<<4)
+MS_REMOUNT (1U<<5)
+MS_MANDLOCK (1U<<6)
+MS_DIRSYNC (1U<<7)
+MS_NOATIME (1U<<10)
+MS_NODIRATIME (1U<<11)
+MS_BIND (1U<<12)
+MS_MOVE (1U<<13)
+MS_REC (1U<<14)
+MS_SILENT (1U<<15)
+MS_POSIXACL (1U<<16)
+MS_UNBINDABLE (1U<<17)
+MS_PRIVATE (1U<<18)
+MS_SLAVE (1U<<19)
+MS_SHARED (1U<<20)
+MS_RELATIME (1U<<21)
+MS_KERNMOUNT (1U<<22)
+MS_I_VERSION (1U<<23)
+MS_STRICTATIME (1U<<24)
+MS_LAZYTIME (1U<<25)
+MS_SUBMOUNT (1U<<26)
+MS_NOREMOTELOCK (1U<<27)
+MS_NOSEC (1U<<28)
+MS_BORN (1U<<29)
+MS_ACTIVE (1U<<30)
+MS_NOUSER (1U<<31)
Index: strace-4.24/xlat/mount_flags.h
===================================================================
--- strace-4.24.orig/xlat/mount_flags.h 2018-08-14 02:44:19.000000000 +0200
+++ strace-4.24/xlat/mount_flags.h 2019-12-02 18:38:36.102900164 +0100
@@ -5,213 +5,213 @@
#if defined(MS_RDONLY) || (defined(HAVE_DECL_MS_RDONLY) && HAVE_DECL_MS_RDONLY)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
-static_assert((MS_RDONLY) == (1), "MS_RDONLY != 1");
+static_assert((MS_RDONLY) == ((1U<<0)), "MS_RDONLY != (1U<<0)");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
-# define MS_RDONLY 1
+# define MS_RDONLY (1U<<0)
#endif
#if defined(MS_NOSUID) || (defined(HAVE_DECL_MS_NOSUID) && HAVE_DECL_MS_NOSUID)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
-static_assert((MS_NOSUID) == (2), "MS_NOSUID != 2");
+static_assert((MS_NOSUID) == ((1U<<1)), "MS_NOSUID != (1U<<1)");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
-# define MS_NOSUID 2
+# define MS_NOSUID (1U<<1)
#endif
#if defined(MS_NODEV) || (defined(HAVE_DECL_MS_NODEV) && HAVE_DECL_MS_NODEV)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
-static_assert((MS_NODEV) == (4), "MS_NODEV != 4");
+static_assert((MS_NODEV) == ((1U<<2)), "MS_NODEV != (1U<<2)");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
-# define MS_NODEV 4
+# define MS_NODEV (1U<<2)
#endif
#if defined(MS_NOEXEC) || (defined(HAVE_DECL_MS_NOEXEC) && HAVE_DECL_MS_NOEXEC)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
-static_assert((MS_NOEXEC) == (8), "MS_NOEXEC != 8");
+static_assert((MS_NOEXEC) == ((1U<<3)), "MS_NOEXEC != (1U<<3)");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
-# define MS_NOEXEC 8
+# define MS_NOEXEC (1U<<3)
#endif
#if defined(MS_SYNCHRONOUS) || (defined(HAVE_DECL_MS_SYNCHRONOUS) && HAVE_DECL_MS_SYNCHRONOUS)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
-static_assert((MS_SYNCHRONOUS) == (16), "MS_SYNCHRONOUS != 16");
+static_assert((MS_SYNCHRONOUS) == ((1U<<4)), "MS_SYNCHRONOUS != (1U<<4)");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
-# define MS_SYNCHRONOUS 16
+# define MS_SYNCHRONOUS (1U<<4)
#endif
#if defined(MS_REMOUNT) || (defined(HAVE_DECL_MS_REMOUNT) && HAVE_DECL_MS_REMOUNT)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
-static_assert((MS_REMOUNT) == (32), "MS_REMOUNT != 32");
+static_assert((MS_REMOUNT) == ((1U<<5)), "MS_REMOUNT != (1U<<5)");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
-# define MS_REMOUNT 32
+# define MS_REMOUNT (1U<<5)
#endif
#if defined(MS_MANDLOCK) || (defined(HAVE_DECL_MS_MANDLOCK) && HAVE_DECL_MS_MANDLOCK)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
-static_assert((MS_MANDLOCK) == (64), "MS_MANDLOCK != 64");
+static_assert((MS_MANDLOCK) == ((1U<<6)), "MS_MANDLOCK != (1U<<6)");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
-# define MS_MANDLOCK 64
+# define MS_MANDLOCK (1U<<6)
#endif
#if defined(MS_DIRSYNC) || (defined(HAVE_DECL_MS_DIRSYNC) && HAVE_DECL_MS_DIRSYNC)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
-static_assert((MS_DIRSYNC) == (128), "MS_DIRSYNC != 128");
+static_assert((MS_DIRSYNC) == ((1U<<7)), "MS_DIRSYNC != (1U<<7)");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
-# define MS_DIRSYNC 128
+# define MS_DIRSYNC (1U<<7)
#endif
#if defined(MS_NOATIME) || (defined(HAVE_DECL_MS_NOATIME) && HAVE_DECL_MS_NOATIME)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
-static_assert((MS_NOATIME) == (1024), "MS_NOATIME != 1024");
+static_assert((MS_NOATIME) == ((1U<<10)), "MS_NOATIME != (1U<<10)");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
-# define MS_NOATIME 1024
+# define MS_NOATIME (1U<<10)
#endif
#if defined(MS_NODIRATIME) || (defined(HAVE_DECL_MS_NODIRATIME) && HAVE_DECL_MS_NODIRATIME)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
-static_assert((MS_NODIRATIME) == (2048), "MS_NODIRATIME != 2048");
+static_assert((MS_NODIRATIME) == ((1U<<11)), "MS_NODIRATIME != (1U<<11)");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
-# define MS_NODIRATIME 2048
+# define MS_NODIRATIME (1U<<11)
#endif
#if defined(MS_BIND) || (defined(HAVE_DECL_MS_BIND) && HAVE_DECL_MS_BIND)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
-static_assert((MS_BIND) == (4096), "MS_BIND != 4096");
+static_assert((MS_BIND) == ((1U<<12)), "MS_BIND != (1U<<12)");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
-# define MS_BIND 4096
+# define MS_BIND (1U<<12)
#endif
#if defined(MS_MOVE) || (defined(HAVE_DECL_MS_MOVE) && HAVE_DECL_MS_MOVE)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
-static_assert((MS_MOVE) == (8192), "MS_MOVE != 8192");
+static_assert((MS_MOVE) == ((1U<<13)), "MS_MOVE != (1U<<13)");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
-# define MS_MOVE 8192
+# define MS_MOVE (1U<<13)
#endif
#if defined(MS_REC) || (defined(HAVE_DECL_MS_REC) && HAVE_DECL_MS_REC)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
-static_assert((MS_REC) == (16384), "MS_REC != 16384");
+static_assert((MS_REC) == ((1U<<14)), "MS_REC != (1U<<14)");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
-# define MS_REC 16384
+# define MS_REC (1U<<14)
#endif
#if defined(MS_SILENT) || (defined(HAVE_DECL_MS_SILENT) && HAVE_DECL_MS_SILENT)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
-static_assert((MS_SILENT) == (32768), "MS_SILENT != 32768");
+static_assert((MS_SILENT) == ((1U<<15)), "MS_SILENT != (1U<<15)");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
-# define MS_SILENT 32768
+# define MS_SILENT (1U<<15)
#endif
#if defined(MS_POSIXACL) || (defined(HAVE_DECL_MS_POSIXACL) && HAVE_DECL_MS_POSIXACL)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
-static_assert((MS_POSIXACL) == ((1<<16)), "MS_POSIXACL != (1<<16)");
+static_assert((MS_POSIXACL) == ((1U<<16)), "MS_POSIXACL != (1U<<16)");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
-# define MS_POSIXACL (1<<16)
+# define MS_POSIXACL (1U<<16)
#endif
#if defined(MS_UNBINDABLE) || (defined(HAVE_DECL_MS_UNBINDABLE) && HAVE_DECL_MS_UNBINDABLE)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
-static_assert((MS_UNBINDABLE) == ((1<<17)), "MS_UNBINDABLE != (1<<17)");
+static_assert((MS_UNBINDABLE) == ((1U<<17)), "MS_UNBINDABLE != (1U<<17)");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
-# define MS_UNBINDABLE (1<<17)
+# define MS_UNBINDABLE (1U<<17)
#endif
#if defined(MS_PRIVATE) || (defined(HAVE_DECL_MS_PRIVATE) && HAVE_DECL_MS_PRIVATE)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
-static_assert((MS_PRIVATE) == ((1<<18)), "MS_PRIVATE != (1<<18)");
+static_assert((MS_PRIVATE) == ((1U<<18)), "MS_PRIVATE != (1U<<18)");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
-# define MS_PRIVATE (1<<18)
+# define MS_PRIVATE (1U<<18)
#endif
#if defined(MS_SLAVE) || (defined(HAVE_DECL_MS_SLAVE) && HAVE_DECL_MS_SLAVE)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
-static_assert((MS_SLAVE) == ((1<<19)), "MS_SLAVE != (1<<19)");
+static_assert((MS_SLAVE) == ((1U<<19)), "MS_SLAVE != (1U<<19)");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
-# define MS_SLAVE (1<<19)
+# define MS_SLAVE (1U<<19)
#endif
#if defined(MS_SHARED) || (defined(HAVE_DECL_MS_SHARED) && HAVE_DECL_MS_SHARED)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
-static_assert((MS_SHARED) == ((1<<20)), "MS_SHARED != (1<<20)");
+static_assert((MS_SHARED) == ((1U<<20)), "MS_SHARED != (1U<<20)");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
-# define MS_SHARED (1<<20)
+# define MS_SHARED (1U<<20)
#endif
#if defined(MS_RELATIME) || (defined(HAVE_DECL_MS_RELATIME) && HAVE_DECL_MS_RELATIME)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
-static_assert((MS_RELATIME) == ((1<<21)), "MS_RELATIME != (1<<21)");
+static_assert((MS_RELATIME) == ((1U<<21)), "MS_RELATIME != (1U<<21)");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
-# define MS_RELATIME (1<<21)
+# define MS_RELATIME (1U<<21)
#endif
#if defined(MS_KERNMOUNT) || (defined(HAVE_DECL_MS_KERNMOUNT) && HAVE_DECL_MS_KERNMOUNT)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
-static_assert((MS_KERNMOUNT) == ((1<<22)), "MS_KERNMOUNT != (1<<22)");
+static_assert((MS_KERNMOUNT) == ((1U<<22)), "MS_KERNMOUNT != (1U<<22)");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
-# define MS_KERNMOUNT (1<<22)
+# define MS_KERNMOUNT (1U<<22)
#endif
#if defined(MS_I_VERSION) || (defined(HAVE_DECL_MS_I_VERSION) && HAVE_DECL_MS_I_VERSION)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
-static_assert((MS_I_VERSION) == ((1<<23)), "MS_I_VERSION != (1<<23)");
+static_assert((MS_I_VERSION) == ((1U<<23)), "MS_I_VERSION != (1U<<23)");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
-# define MS_I_VERSION (1<<23)
+# define MS_I_VERSION (1U<<23)
#endif
#if defined(MS_STRICTATIME) || (defined(HAVE_DECL_MS_STRICTATIME) && HAVE_DECL_MS_STRICTATIME)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
-static_assert((MS_STRICTATIME) == ((1<<24)), "MS_STRICTATIME != (1<<24)");
+static_assert((MS_STRICTATIME) == ((1U<<24)), "MS_STRICTATIME != (1U<<24)");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
-# define MS_STRICTATIME (1<<24)
+# define MS_STRICTATIME (1U<<24)
#endif
#if defined(MS_LAZYTIME) || (defined(HAVE_DECL_MS_LAZYTIME) && HAVE_DECL_MS_LAZYTIME)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
-static_assert((MS_LAZYTIME) == ((1<<25)), "MS_LAZYTIME != (1<<25)");
+static_assert((MS_LAZYTIME) == ((1U<<25)), "MS_LAZYTIME != (1U<<25)");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
-# define MS_LAZYTIME (1<<25)
+# define MS_LAZYTIME (1U<<25)
#endif
#if defined(MS_SUBMOUNT) || (defined(HAVE_DECL_MS_SUBMOUNT) && HAVE_DECL_MS_SUBMOUNT)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
-static_assert((MS_SUBMOUNT) == ((1<<26)), "MS_SUBMOUNT != (1<<26)");
+static_assert((MS_SUBMOUNT) == ((1U<<26)), "MS_SUBMOUNT != (1U<<26)");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
-# define MS_SUBMOUNT (1<<26)
+# define MS_SUBMOUNT (1U<<26)
#endif
#if defined(MS_NOREMOTELOCK) || (defined(HAVE_DECL_MS_NOREMOTELOCK) && HAVE_DECL_MS_NOREMOTELOCK)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
-static_assert((MS_NOREMOTELOCK) == ((1<<27)), "MS_NOREMOTELOCK != (1<<27)");
+static_assert((MS_NOREMOTELOCK) == ((1U<<27)), "MS_NOREMOTELOCK != (1U<<27)");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
-# define MS_NOREMOTELOCK (1<<27)
+# define MS_NOREMOTELOCK (1U<<27)
#endif
#if defined(MS_NOSEC) || (defined(HAVE_DECL_MS_NOSEC) && HAVE_DECL_MS_NOSEC)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
-static_assert((MS_NOSEC) == ((1<<28)), "MS_NOSEC != (1<<28)");
+static_assert((MS_NOSEC) == ((1U<<28)), "MS_NOSEC != (1U<<28)");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
-# define MS_NOSEC (1<<28)
+# define MS_NOSEC (1U<<28)
#endif
#if defined(MS_BORN) || (defined(HAVE_DECL_MS_BORN) && HAVE_DECL_MS_BORN)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
-static_assert((MS_BORN) == ((1<<29)), "MS_BORN != (1<<29)");
+static_assert((MS_BORN) == ((1U<<29)), "MS_BORN != (1U<<29)");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
-# define MS_BORN (1<<29)
+# define MS_BORN (1U<<29)
#endif
#if defined(MS_ACTIVE) || (defined(HAVE_DECL_MS_ACTIVE) && HAVE_DECL_MS_ACTIVE)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
-static_assert((MS_ACTIVE) == ((1<<30)), "MS_ACTIVE != (1<<30)");
+static_assert((MS_ACTIVE) == ((1U<<30)), "MS_ACTIVE != (1U<<30)");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
-# define MS_ACTIVE (1<<30)
+# define MS_ACTIVE (1U<<30)
#endif
#if defined(MS_NOUSER) || (defined(HAVE_DECL_MS_NOUSER) && HAVE_DECL_MS_NOUSER)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
-static_assert((MS_NOUSER) == ((1<<31)), "MS_NOUSER != (1<<31)");
+static_assert((MS_NOUSER) == ((1U<<31)), "MS_NOUSER != (1U<<31)");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
-# define MS_NOUSER (1<<31)
+# define MS_NOUSER (1U<<31)
#endif
#ifndef XLAT_MACROS_ONLY

View File

@ -1,37 +0,0 @@
From 0b051a218d5e7e51677c26c691dcf619a7d894e9 Mon Sep 17 00:00:00 2001
From: "Dmitry V. Levin" <ldv@altlinux.org>
Date: Mon, 11 Feb 2019 23:35:07 +0000
Subject: [PATCH] Wire up rseq syscall on architectures that use generic
unistd.h
* linux/32/syscallent.h [293]: Wire up rseq syscall introduced by linux
commit v4.19-rc1~109^2~47.
* linux/64/syscallent.h [293]: Likewise.
* NEWS: Mention this.
---
NEWS | 2 ++
linux/32/syscallent.h | 1 +
linux/64/syscallent.h | 1 +
3 files changed, 4 insertions(+)
Index: strace-4.24/linux/32/syscallent.h
===================================================================
--- strace-4.24.orig/linux/32/syscallent.h 2019-06-13 01:05:32.297055881 +0200
+++ strace-4.24/linux/32/syscallent.h 2019-06-13 01:05:42.887824722 +0200
@@ -283,6 +283,7 @@
[290] = { 1, 0, SEN(pkey_free), "pkey_free" },
[291] = { 5, TD|TF|TSTA, SEN(statx), "statx" },
[292] = { 6, 0, SEN(io_pgetevents), "io_pgetevents" },
+[293] = { 4, 0, SEN(rseq), "rseq" },
#undef sys_ARCH_mmap
#undef ARCH_WANT_SYNC_FILE_RANGE2
Index: strace-4.24/linux/64/syscallent.h
===================================================================
--- strace-4.24.orig/linux/64/syscallent.h 2019-06-13 01:05:32.297055881 +0200
+++ strace-4.24/linux/64/syscallent.h 2019-06-13 01:05:42.888824700 +0200
@@ -276,3 +276,4 @@
[290] = { 1, 0, SEN(pkey_free), "pkey_free" },
[291] = { 5, TD|TF|TSTA, SEN(statx), "statx" },
[292] = { 6, 0, SEN(io_pgetevents), "io_pgetevents" },
+[293] = { 4, 0, SEN(rseq), "rseq" },

View File

@ -1,39 +0,0 @@
From 898f0ad0bc498c45734bc95917b74cfdc6466c26 Mon Sep 17 00:00:00 2001
From: "Dmitry V. Levin" <ldv@altlinux.org>
Date: Mon, 11 Feb 2019 23:35:07 +0000
Subject: [PATCH] Wire up kexec_file_load syscall on architectures that use
generic unistd.h
* linux/32/syscallent.h [294]: Wire up kexec_file_load syscall
introduced by linux commit v5.0-rc1~35^2~41^2~15.
* linux/64/syscallent.h [294]: Likewise.
* NEWS: Mention this.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1676045
---
NEWS | 2 +-
linux/32/syscallent.h | 1 +
linux/64/syscallent.h | 1 +
3 files changed, 3 insertions(+), 1 deletion(-)
Index: strace-4.24/linux/32/syscallent.h
===================================================================
--- strace-4.24.orig/linux/32/syscallent.h 2019-06-13 01:05:42.887824722 +0200
+++ strace-4.24/linux/32/syscallent.h 2019-06-13 01:06:00.405442367 +0200
@@ -284,6 +284,7 @@
[291] = { 5, TD|TF|TSTA, SEN(statx), "statx" },
[292] = { 6, 0, SEN(io_pgetevents), "io_pgetevents" },
[293] = { 4, 0, SEN(rseq), "rseq" },
+[294] = { 5, TD, SEN(kexec_file_load), "kexec_file_load" },
#undef sys_ARCH_mmap
#undef ARCH_WANT_SYNC_FILE_RANGE2
Index: strace-4.24/linux/64/syscallent.h
===================================================================
--- strace-4.24.orig/linux/64/syscallent.h 2019-06-13 01:05:42.888824700 +0200
+++ strace-4.24/linux/64/syscallent.h 2019-06-13 01:06:00.405442367 +0200
@@ -277,3 +277,4 @@
[291] = { 5, TD|TF|TSTA, SEN(statx), "statx" },
[292] = { 6, 0, SEN(io_pgetevents), "io_pgetevents" },
[293] = { 4, 0, SEN(rseq), "rseq" },
+[294] = { 5, TD, SEN(kexec_file_load), "kexec_file_load" },

View File

@ -0,0 +1,58 @@
From 2bf069698a384ff2bc62d2a10544d49d766b4d7f Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Mon, 27 Jun 2022 18:00:17 +0200
Subject: [PATCH] src/xlat: remove remnants of unnecessary idx usage in xlookup
As there is no idx saving between calls anymore, there's no need to use
(and update) idx in the XT_SORTED case. Reported by clang as a dead store:
Error: CLANG_WARNING:
strace-5.18/src/xlat.c:84:4: warning[deadcode.DeadStores]: Value stored to 'idx' is never read
* src/xlat.c (xlookup): Remove idx declaration; declare idx inside
of the for loop in the XT_NORMAL case; do not offset x->data and x->size
by offs in the XT_SORTED case and do not update idx upon successful
lookup.
Complements: v5.15~164 "xlat: no longer interpret NULL xlat as continuation"
---
src/xlat.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
Index: strace-5.18/src/xlat.c
===================================================================
--- strace-5.18.orig/src/xlat.c 2022-07-12 17:11:52.660927011 +0200
+++ strace-5.18/src/xlat.c 2022-07-12 17:16:18.116794139 +0200
@@ -61,7 +61,6 @@
const char *
xlookup(const struct xlat *x, const uint64_t val)
{
- size_t idx = 0;
const struct xlat_data *e;
if (!x || !x->data)
@@ -69,21 +68,18 @@
switch (x->type) {
case XT_NORMAL:
- for (; idx < x->size; idx++)
+ for (size_t idx = 0; idx < x->size; idx++)
if (x->data[idx].val == val)
return x->data[idx].str;
break;
case XT_SORTED:
e = bsearch((const void *) &val,
- x->data + idx,
- x->size - idx,
+ x->data, x->size,
sizeof(x->data[0]),
xlat_bsearch_compare);
- if (e) {
- idx = e - x->data;
+ if (e)
return e->str;
- }
break;
case XT_INDEXED:

View File

@ -0,0 +1,56 @@
From e604d7bfd18cf5f29e6723091cc1db2945c918c9 Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Tue, 28 Jun 2022 16:46:53 +0200
Subject: [PATCH] strauss: tips whitespace and phrasing cleanups
* src/strauss.c (tips_tricks_tweaks): Fix some whitespace and phrasing
issues.
---
src/strauss.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
Index: strace-5.18/src/strauss.c
===================================================================
--- strace-5.18.orig/src/strauss.c 2022-07-12 17:17:08.712197019 +0200
+++ strace-5.18/src/strauss.c 2022-07-12 17:17:20.685055717 +0200
@@ -128,8 +128,8 @@
{ "strace is about as old as the Linux kernel.",
"It has been originally written for SunOS",
"by Paul Kranenburg in 1991. The support",
- "for all OSes except Linux has been dropped",
- "since 2012, though, in strace 4.7." },
+ "for all OSes except Linux was dropped"
+ "in 2012, though, in strace 4.7." },
{ "strace is able to decode netlink messages.",
"It does so automatically for I/O performed",
"on netlink sockets. Try it yourself:", "",
@@ -187,7 +187,7 @@
"want to try --seccomp-bpf option, maybe you",
"will feel better." },
{ "-v is a shorthand for -e abbrev=none and not",
- " for -e verbose=all. It is idiosyncratic,",
+ "for -e verbose=all. It is idiosyncratic,",
"but it is the historic behaviour." },
{ "strace uses netlink for printing",
"protocol-specific information about socket",
@@ -254,7 +254,7 @@
"by invoking it with the following options:", "",
" strace -DDDqqq -enone --signal=none" },
{ "Historically, supplying -o option to strace",
- "led to silencing of messages about tracee",
+ "leads to silencing of messages about tracee",
"attach/detach and personality changes.",
"It can be now overridden with --quiet=none",
"option." },
@@ -285,8 +285,9 @@
"will trace all syscalls related to accessing",
"and modifying process's user/group IDs",
"and capability sets. Other pre-defined",
- "syscall classes include %clock, %desc,%file,",
- "%ipc,%memory, %net,%process, and %signal." },
+ "syscall classes include %clock, %desc,"
+ "%file, %ipc, %memory, %net, %process,"
+ "and %signal." },
{ "Trying to figure out communication between",
"tracees inside a different PID namespace",
"(in so-called \"containers\", for example)?",

View File

@ -0,0 +1,48 @@
From 968789d5426442ac43b96eabd65f3e5c0c141e62 Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Tue, 28 Jun 2022 16:47:56 +0200
Subject: [PATCH] strauss: fix off-by-one error in strauss array access
It has to be limited with strauss_lines - 1, not strauss_lines.
Reported by covscan:
Error: OVERRUN (CWE-119):
strace-5.18/src/strauss.c:380: cond_at_least: Checking "4UL + i < 37UL"
implies that "i" is at least 33 on the false branch.
strace-5.18/src/strauss.c:380: overrun-local: Overrunning array "strauss"
of 37 8-byte elements at element index 37 (byte offset 303) using index
"(4UL + i < 37UL) ? 4UL + i : 37UL" (which evaluates to 37).
* src/strauss.c (print_totd): Limit strauss array accesses to
strauss_lines - 1 instead of strauss_lines.
---
src/strauss.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/strauss.c b/src/strauss.c
index 98af183..b22ab6a 100644
--- a/src/strauss.c
+++ b/src/strauss.c
@@ -373,16 +373,16 @@ print_totd(void)
tip_left[MIN(i + 1, ARRAY_SIZE(tip_left) - 1)],
w, w, tips_tricks_tweaks[id][i] ?: "",
tip_right[MIN(i + 1, ARRAY_SIZE(tip_right) - 1)],
- strauss[MIN(3 + i, strauss_lines)]);
+ strauss[MIN(3 + i, strauss_lines - 1)]);
}
fprintf(stderr, "%s%s\n",
- tip_bottom, strauss[MIN(3 + i, strauss_lines)]);
+ tip_bottom, strauss[MIN(3 + i, strauss_lines - 1)]);
do {
fprintf(stderr, "%*s%*s%*s%s\n",
(int) strlen(tip_left[0]), "",
w, "",
(int) strlen(tip_right[0]), "",
- strauss[MIN(4 + i, strauss_lines)]);
+ strauss[MIN(4 + i, strauss_lines - 1)]);
} while ((show_tips == TIPS_FULL) && (4 + ++i < strauss_lines));
printed = true;
--
2.1.4

View File

@ -0,0 +1,62 @@
From 6d3e97e83a7d61cbb2f5109efb4b519383a55712 Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Tue, 28 Jun 2022 16:55:49 +0200
Subject: [PATCH] util: add offs sanity check to print_clock_t
While it is not strictly needed right now, the code that uses
the calculated offs value lacks any checks for possible buf overruns,
which is not defensive enough, so let's add them. Reported by covscan:
Error: OVERRUN (CWE-119):
strace-5.18/src/util.c:248: assignment: Assigning:
"offs" = "ilog10(val / clk_tck)". The value of "offs" is now between
16 and 31 (inclusive).
strace-5.18/src/util.c:249: overrun-local: Overrunning array of 30 bytes
at byte offset 31 by dereferencing pointer "buf + offs". [Note: The source
code implementation of the function has been overridden by a builtin model.]
Error: OVERRUN (CWE-119):
strace-5.18/src/util.c:248: assignment: Assigning:
"offs" = "ilog10(val / clk_tck)". The value of "offs" is now between
16 and 31 (inclusive).
strace-5.18/src/util.c:253: overrun-buffer-arg: Overrunning array "buf"
of 30 bytes by passing it to a function which accesses it at byte offset
32 using argument "offs + 2UL" (which evaluates to 33). [Note: The source
code implementation of the function has been overridden by a builtin model.]
Error: OVERRUN (CWE-119):
strace-5.18/src/util.c:248: assignment: Assigning:
"offs" = "ilog10(val / clk_tck)". The value of "offs" is now between
16 and 31 (inclusive).
strace-5.18/src/util.c:254: overrun-local: Overrunning array "buf"
of 30 bytes at byte offset 32 using index "offs + 1UL" (which evaluates
to 32).
* src/util.c (print_clock_t): Add check that offs is small enough
for it and "offs + 2" not to overrun buf.
---
src/util.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/src/util.c b/src/util.c
index 5f87acb..93aa7b3 100644
--- a/src/util.c
+++ b/src/util.c
@@ -246,6 +246,14 @@ print_clock_t(uint64_t val)
*/
char buf[sizeof(uint64_t) * 3 + sizeof("0.0 s")];
size_t offs = ilog10(val / clk_tck);
+ /*
+ * This check is mostly to appease covscan, which thinks
+ * that offs can go as high as 31 (it cannot), but since
+ * there is no proper sanity checks against offs overrunning
+ * buf down the code, it may as well be here.
+ */
+ if (offs > (sizeof(buf) - sizeof("0.0 s")))
+ return;
int ret = snprintf(buf + offs, sizeof(buf) - offs, "%.*f s",
frac_width,
(double) (val % clk_tck) / clk_tck);
--
2.1.4

View File

@ -0,0 +1,882 @@
From 960e78f208b4f6d48962bbc9cad45588cc8c90ad Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Renaud=20M=C3=A9trich?= <rmetrich@redhat.com>
Date: Tue, 21 Jun 2022 08:43:00 +0200
Subject: [PATCH] secontext: print context of Unix socket's sun_path field
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Renaud Métrich <rmetrich@redhat.com>
* src/sockaddr.c: Include "secontext.h".
(print_sockaddr_data_un): Print the SELinux context of sun_path field
using selinux_printfilecon.
* NEWS: Mention this change.
* tests/secontext.c (raw_secontext_full_fd, get_secontext_field_fd,
raw_secontext_short_fd, secontext_full_fd, secontext_short_fd): New
functions.
* tests/secontext.h (secontext_full_fd, secontext_short_fd,
get_secontext_field_fd): New prototypes.
(SECONTEXT_FD): New macro.
* tests/sockname.c: Include "secontext.h".
(test_sockname_syscall): Update expected output.
* tests/gen_tests.in (getsockname--secontext,
getsockname--secontext_full, getsockname--secontext_full_mismatch,
getsockname--secontext_mismatch): New tests.
Resolves: https://github.com/strace/strace/pull/214
---
NEWS | 1 +
src/sockaddr.c | 3 +++
tests/gen_tests.in | 4 ++++
tests/secontext.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
tests/secontext.h | 12 ++++++++++++
tests/sockname.c | 54 +++++++++++++++++++++++++++++++++++-------------------
6 files changed, 104 insertions(+), 19 deletions(-)
Index: strace-5.18/NEWS
===================================================================
--- strace-5.18.orig/NEWS 2022-07-12 18:20:18.495470531 +0200
+++ strace-5.18/NEWS 2022-07-12 18:20:44.531163262 +0200
@@ -5,6 +5,7 @@
* Added an interface of raising des Strausses awareness.
* Added --tips option to print strace tips, tricks, and tweaks
at the end of the tracing session.
+ * Implemented printing of Unix socket sun_path field's SELinux context.
* Enhanced decoding of bpf and io_uring_register syscalls.
* Implemented decoding of COUNTER_*, RTC_PARAM_GET, and RTC_PARAM_SET ioctl
commands.
Index: strace-5.18/src/sockaddr.c
===================================================================
--- strace-5.18.orig/src/sockaddr.c 2022-07-12 18:17:36.745379483 +0200
+++ strace-5.18/src/sockaddr.c 2022-07-12 18:20:18.495470531 +0200
@@ -63,6 +63,8 @@
#include "xlat/mctp_addrs.h"
#include "xlat/mctp_nets.h"
+#include "secontext.h"
+
#define SIZEOF_SA_FAMILY sizeof_field(struct sockaddr, sa_family)
struct sockaddr_rxrpc {
@@ -115,6 +117,7 @@
if (sa_un->sun_path[0]) {
print_quoted_string(sa_un->sun_path, path_len + 1,
QUOTE_0_TERMINATED);
+ selinux_printfilecon(tcp, sa_un->sun_path);
} else {
tprints("@");
print_quoted_string(sa_un->sun_path + 1, path_len - 1, 0);
Index: strace-5.18/tests/gen_tests.in
===================================================================
--- strace-5.18.orig/tests/gen_tests.in 2022-07-12 18:17:36.746379471 +0200
+++ strace-5.18/tests/gen_tests.in 2022-07-12 18:20:18.496470519 +0200
@@ -225,6 +225,10 @@
getsid -a10
getsid--pidns-translation test_pidns -e trace=getsid -a10
getsockname -a27
+getsockname--secontext -a27 --secontext -e trace=getsockname
+getsockname--secontext_full -a27 --secontext=full -e trace=getsockname
+getsockname--secontext_full_mismatch -a27 --secontext=full,mismatch -e trace=getsockname
+getsockname--secontext_mismatch -a27 --secontext=mismatch -e trace=getsockname
gettid -a9
getuid-creds +getuid.test
getuid32 +getuid.test
Index: strace-5.18/tests/secontext.c
===================================================================
--- strace-5.18.orig/tests/secontext.c 2022-07-12 18:17:36.747379459 +0200
+++ strace-5.18/tests/secontext.c 2022-07-12 18:20:18.496470519 +0200
@@ -141,6 +141,21 @@
return full_secontext;
}
+static char *
+raw_secontext_full_fd(int fd)
+{
+ int saved_errno = errno;
+ char *full_secontext = NULL;
+ char *secontext;
+
+ if (fgetfilecon(fd, &secontext) >= 0) {
+ full_secontext = strip_trailing_newlines(xstrdup(secontext));
+ freecon(secontext);
+ }
+ errno = saved_errno;
+ return full_secontext;
+}
+
char *
get_secontext_field_file(const char *file, enum secontext_field field)
{
@@ -151,6 +166,16 @@
return type;
}
+char *
+get_secontext_field_fd(int fd, enum secontext_field field)
+{
+ char *ctx = raw_secontext_full_fd(fd);
+ char *type = get_secontext_field(ctx, field);
+ free(ctx);
+
+ return type;
+}
+
static char *
raw_secontext_short_file(const char *filename)
{
@@ -158,6 +183,12 @@
}
static char *
+raw_secontext_short_fd(int fd)
+{
+ return get_secontext_field_fd(fd, SECONTEXT_TYPE);
+}
+
+static char *
raw_secontext_full_pid(pid_t pid)
{
int saved_errno = errno;
@@ -205,6 +236,15 @@
}
char *
+secontext_full_fd(int fd)
+{
+ int saved_errno = errno;
+ char *context = raw_secontext_full_fd(fd);
+ errno = saved_errno;
+ return FORMAT_SPACE_BEFORE(context);
+}
+
+char *
secontext_full_pid(pid_t pid)
{
return FORMAT_SPACE_AFTER(raw_secontext_full_pid(pid));
@@ -228,6 +268,15 @@
errno = saved_errno;
return FORMAT_SPACE_BEFORE(context);
}
+
+char *
+secontext_short_fd(int fd)
+{
+ int saved_errno = errno;
+ char *context = raw_secontext_short_fd(fd);
+ errno = saved_errno;
+ return FORMAT_SPACE_BEFORE(context);
+}
char *
secontext_short_pid(pid_t pid)
Index: strace-5.18/tests/secontext.h
===================================================================
--- strace-5.18.orig/tests/secontext.h 2022-07-12 18:17:36.747379459 +0200
+++ strace-5.18/tests/secontext.h 2022-07-12 18:20:18.496470519 +0200
@@ -9,9 +9,11 @@
#include "xmalloc.h"
#include <unistd.h>
+char *secontext_full_fd(int) ATTRIBUTE_MALLOC;
char *secontext_full_file(const char *, bool) ATTRIBUTE_MALLOC;
char *secontext_full_pid(pid_t) ATTRIBUTE_MALLOC;
+char *secontext_short_fd(int) ATTRIBUTE_MALLOC;
char *secontext_short_file(const char *, bool) ATTRIBUTE_MALLOC;
char *secontext_short_pid(pid_t) ATTRIBUTE_MALLOC;
@@ -30,6 +32,7 @@
*/
char *get_secontext_field(const char *full_context, enum secontext_field field);
+char *get_secontext_field_fd(int fd, enum secontext_field field);
char *get_secontext_field_file(const char *file, enum secontext_field field);
void reset_secontext_file(const char *file);
@@ -44,6 +47,7 @@
# else
# define SECONTEXT_FILE(filename) secontext_full_file(filename, false)
# endif
+# define SECONTEXT_FD(fd) secontext_full_fd(fd)
# define SECONTEXT_PID(pid) secontext_full_pid(pid)
# else
@@ -53,6 +57,7 @@
# else
# define SECONTEXT_FILE(filename) secontext_short_file(filename, false)
# endif
+# define SECONTEXT_FD(fd) secontext_short_fd(fd)
# define SECONTEXT_PID(pid) secontext_short_pid(pid)
# endif
@@ -65,6 +70,12 @@
return NULL;
}
static inline char *
+get_secontext_field_fd(int fd, enum secontext_field field)
+{
+ return NULL;
+}
+
+static inline char *
get_secontext_field_file(const char *file, enum secontext_field field)
{
return NULL;
@@ -81,6 +92,7 @@
{
}
+# define SECONTEXT_FD(fd) xstrdup("")
# define SECONTEXT_FILE(filename) xstrdup("")
# define SECONTEXT_PID(pid) xstrdup("")
Index: strace-5.18/tests/sockname.c
===================================================================
--- strace-5.18.orig/tests/sockname.c 2022-07-12 18:17:36.748379448 +0200
+++ strace-5.18/tests/sockname.c 2022-07-12 18:20:18.496470519 +0200
@@ -18,6 +18,8 @@
#include <sys/socket.h>
#include <sys/un.h>
+#include "secontext.h"
+
#ifndef TEST_SYSCALL_NAME
# error TEST_SYSCALL_NAME must be defined
#endif
@@ -59,14 +61,19 @@
*plen = sizeof(struct sockaddr_un);
struct sockaddr_un *addr = tail_alloc(*plen);
+ char *my_secontext = SECONTEXT_PID_MY();
+ char *fd_secontext = SECONTEXT_FD(fd);
+
PREPARE_TEST_SYSCALL_INVOCATION;
int rc = TEST_SYSCALL_NAME(fd PREFIX_S_ARGS, (void *) addr,
plen SUFFIX_ARGS);
if (rc < 0)
perror_msg_and_skip(TEST_SYSCALL_STR);
- printf("%s(%d%s, {sa_family=AF_UNIX, sun_path=\"%s\"}"
+ printf("%s%s(%d%s%s, {sa_family=AF_UNIX, sun_path=\"%s\"%s}"
", [%d => %d]%s) = %d\n",
- TEST_SYSCALL_STR, fd, PREFIX_S_STR, addr->sun_path,
+ my_secontext,
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_S_STR,
+ addr->sun_path, SECONTEXT_FILE(addr->sun_path),
(int) sizeof(struct sockaddr_un), (int) *plen, SUFFIX_STR, rc);
memset(addr, 0, sizeof(*addr));
@@ -75,28 +82,34 @@
plen SUFFIX_ARGS);
if (rc < 0)
perror_msg_and_skip(TEST_SYSCALL_STR);
- printf("%s(%d%s, {sa_family=AF_UNIX, sun_path=\"%s\"}"
+ printf("%s%s(%d%s%s, {sa_family=AF_UNIX, sun_path=\"%s\"%s}"
", [%d]%s) = %d\n",
- TEST_SYSCALL_STR, fd, PREFIX_S_STR, addr->sun_path,
+ my_secontext,
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_S_STR,
+ addr->sun_path, SECONTEXT_FILE(addr->sun_path),
(int) *plen, SUFFIX_STR, rc);
PREPARE_TEST_SYSCALL_INVOCATION;
rc = TEST_SYSCALL_NAME(fd PREFIX_F_ARGS, (void *) addr, 0 SUFFIX_ARGS);
- printf("%s(%d%s, %p, NULL%s) = %s\n",
- TEST_SYSCALL_STR, fd, PREFIX_F_STR, addr, SUFFIX_STR,
- sprintrc(rc));
+ printf("%s%s(%d%s%s, %p, NULL%s) = %s\n",
+ my_secontext,
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_F_STR,
+ addr, SUFFIX_STR, sprintrc(rc));
PREPARE_TEST_SYSCALL_INVOCATION;
rc = TEST_SYSCALL_NAME(fd PREFIX_S_ARGS, 0, 0 SUFFIX_ARGS);
- printf("%s(%d%s, NULL, NULL%s) = %s\n",
- TEST_SYSCALL_STR, fd, rc == -1 ? PREFIX_F_STR : PREFIX_S_STR,
+ printf("%s%s(%d%s%s, NULL, NULL%s) = %s\n",
+ my_secontext,
+ TEST_SYSCALL_STR, fd, fd_secontext,
+ rc == -1 ? PREFIX_F_STR : PREFIX_S_STR,
SUFFIX_STR, sprintrc(rc));
PREPARE_TEST_SYSCALL_INVOCATION;
rc = TEST_SYSCALL_NAME(fd PREFIX_F_ARGS, (void *) addr,
plen + 1 SUFFIX_ARGS);
- printf("%s(%d%s, %p, %p%s) = %s\n",
- TEST_SYSCALL_STR, fd, PREFIX_F_STR, addr,
+ printf("%s%s(%d%s%s, %p, %p%s) = %s\n",
+ my_secontext,
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_F_STR, addr,
plen + 1, SUFFIX_STR, sprintrc(rc));
const size_t offsetof_sun_path = offsetof(struct sockaddr_un, sun_path);
@@ -108,8 +121,9 @@
plen SUFFIX_ARGS);
if (rc < 0)
perror_msg_and_skip(TEST_SYSCALL_STR);
- printf("%s(%d%s, {sa_family=AF_UNIX}, [%d => %d]%s) = %d\n",
- TEST_SYSCALL_STR, fd, PREFIX_S_STR,
+ printf("%s%s(%d%s%s, {sa_family=AF_UNIX}, [%d => %d]%s) = %d\n",
+ my_secontext,
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_S_STR,
(int) offsetof_sun_path, (int) *plen, SUFFIX_STR, rc);
++addr;
@@ -121,17 +135,19 @@
plen SUFFIX_ARGS);
if (rc < 0)
perror_msg_and_skip(TEST_SYSCALL_STR);
- printf("%s(%d%s, {sa_family=AF_UNIX, sun_path=\"%.*s\"}"
+ printf("%s%s(%d%s%s, {sa_family=AF_UNIX, sun_path=\"%.*s\"%s}"
", [%d => %d]%s) = %d\n",
- TEST_SYSCALL_STR, fd, PREFIX_S_STR,
+ my_secontext,
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_S_STR,
(int) (sizeof(struct sockaddr) - offsetof_sun_path),
- addr->sun_path, (int) sizeof(struct sockaddr),
- (int) *plen, SUFFIX_STR, rc);
+ addr->sun_path, SECONTEXT_FILE(addr->sun_path),
+ (int) sizeof(struct sockaddr), (int) *plen, SUFFIX_STR, rc);
PREPARE_TEST_SYSCALL_INVOCATION;
rc = TEST_SYSCALL_NAME(fd PREFIX_F_ARGS, (void *) addr,
plen SUFFIX_ARGS);
- printf("%s(%d%s, %p, [%d]%s) = %s\n",
- TEST_SYSCALL_STR, fd, PREFIX_F_STR, addr,
+ printf("%s%s(%d%s%s, %p, [%d]%s) = %s\n",
+ my_secontext,
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_F_STR, addr,
*plen, SUFFIX_STR, sprintrc(rc));
}
Index: strace-5.18/tests-m32/secontext.c
===================================================================
--- strace-5.18.orig/tests-m32/secontext.c 2022-07-12 18:17:36.747379459 +0200
+++ strace-5.18/tests-m32/secontext.c 2022-07-12 18:20:18.496470519 +0200
@@ -141,6 +141,21 @@
return full_secontext;
}
+static char *
+raw_secontext_full_fd(int fd)
+{
+ int saved_errno = errno;
+ char *full_secontext = NULL;
+ char *secontext;
+
+ if (fgetfilecon(fd, &secontext) >= 0) {
+ full_secontext = strip_trailing_newlines(xstrdup(secontext));
+ freecon(secontext);
+ }
+ errno = saved_errno;
+ return full_secontext;
+}
+
char *
get_secontext_field_file(const char *file, enum secontext_field field)
{
@@ -151,6 +166,16 @@
return type;
}
+char *
+get_secontext_field_fd(int fd, enum secontext_field field)
+{
+ char *ctx = raw_secontext_full_fd(fd);
+ char *type = get_secontext_field(ctx, field);
+ free(ctx);
+
+ return type;
+}
+
static char *
raw_secontext_short_file(const char *filename)
{
@@ -158,6 +183,12 @@
}
static char *
+raw_secontext_short_fd(int fd)
+{
+ return get_secontext_field_fd(fd, SECONTEXT_TYPE);
+}
+
+static char *
raw_secontext_full_pid(pid_t pid)
{
int saved_errno = errno;
@@ -205,6 +236,15 @@
}
char *
+secontext_full_fd(int fd)
+{
+ int saved_errno = errno;
+ char *context = raw_secontext_full_fd(fd);
+ errno = saved_errno;
+ return FORMAT_SPACE_BEFORE(context);
+}
+
+char *
secontext_full_pid(pid_t pid)
{
return FORMAT_SPACE_AFTER(raw_secontext_full_pid(pid));
@@ -228,6 +268,15 @@
errno = saved_errno;
return FORMAT_SPACE_BEFORE(context);
}
+
+char *
+secontext_short_fd(int fd)
+{
+ int saved_errno = errno;
+ char *context = raw_secontext_short_fd(fd);
+ errno = saved_errno;
+ return FORMAT_SPACE_BEFORE(context);
+}
char *
secontext_short_pid(pid_t pid)
Index: strace-5.18/tests-m32/secontext.h
===================================================================
--- strace-5.18.orig/tests-m32/secontext.h 2022-07-12 18:17:36.747379459 +0200
+++ strace-5.18/tests-m32/secontext.h 2022-07-12 18:20:18.496470519 +0200
@@ -9,9 +9,11 @@
#include "xmalloc.h"
#include <unistd.h>
+char *secontext_full_fd(int) ATTRIBUTE_MALLOC;
char *secontext_full_file(const char *, bool) ATTRIBUTE_MALLOC;
char *secontext_full_pid(pid_t) ATTRIBUTE_MALLOC;
+char *secontext_short_fd(int) ATTRIBUTE_MALLOC;
char *secontext_short_file(const char *, bool) ATTRIBUTE_MALLOC;
char *secontext_short_pid(pid_t) ATTRIBUTE_MALLOC;
@@ -30,6 +32,7 @@
*/
char *get_secontext_field(const char *full_context, enum secontext_field field);
+char *get_secontext_field_fd(int fd, enum secontext_field field);
char *get_secontext_field_file(const char *file, enum secontext_field field);
void reset_secontext_file(const char *file);
@@ -44,6 +47,7 @@
# else
# define SECONTEXT_FILE(filename) secontext_full_file(filename, false)
# endif
+# define SECONTEXT_FD(fd) secontext_full_fd(fd)
# define SECONTEXT_PID(pid) secontext_full_pid(pid)
# else
@@ -53,6 +57,7 @@
# else
# define SECONTEXT_FILE(filename) secontext_short_file(filename, false)
# endif
+# define SECONTEXT_FD(fd) secontext_short_fd(fd)
# define SECONTEXT_PID(pid) secontext_short_pid(pid)
# endif
@@ -65,6 +70,12 @@
return NULL;
}
static inline char *
+get_secontext_field_fd(int fd, enum secontext_field field)
+{
+ return NULL;
+}
+
+static inline char *
get_secontext_field_file(const char *file, enum secontext_field field)
{
return NULL;
@@ -81,6 +92,7 @@
{
}
+# define SECONTEXT_FD(fd) xstrdup("")
# define SECONTEXT_FILE(filename) xstrdup("")
# define SECONTEXT_PID(pid) xstrdup("")
Index: strace-5.18/tests-m32/sockname.c
===================================================================
--- strace-5.18.orig/tests-m32/sockname.c 2022-07-12 18:17:36.748379448 +0200
+++ strace-5.18/tests-m32/sockname.c 2022-07-12 18:20:18.496470519 +0200
@@ -18,6 +18,8 @@
#include <sys/socket.h>
#include <sys/un.h>
+#include "secontext.h"
+
#ifndef TEST_SYSCALL_NAME
# error TEST_SYSCALL_NAME must be defined
#endif
@@ -59,14 +61,19 @@
*plen = sizeof(struct sockaddr_un);
struct sockaddr_un *addr = tail_alloc(*plen);
+ char *my_secontext = SECONTEXT_PID_MY();
+ char *fd_secontext = SECONTEXT_FD(fd);
+
PREPARE_TEST_SYSCALL_INVOCATION;
int rc = TEST_SYSCALL_NAME(fd PREFIX_S_ARGS, (void *) addr,
plen SUFFIX_ARGS);
if (rc < 0)
perror_msg_and_skip(TEST_SYSCALL_STR);
- printf("%s(%d%s, {sa_family=AF_UNIX, sun_path=\"%s\"}"
+ printf("%s%s(%d%s%s, {sa_family=AF_UNIX, sun_path=\"%s\"%s}"
", [%d => %d]%s) = %d\n",
- TEST_SYSCALL_STR, fd, PREFIX_S_STR, addr->sun_path,
+ my_secontext,
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_S_STR,
+ addr->sun_path, SECONTEXT_FILE(addr->sun_path),
(int) sizeof(struct sockaddr_un), (int) *plen, SUFFIX_STR, rc);
memset(addr, 0, sizeof(*addr));
@@ -75,28 +82,34 @@
plen SUFFIX_ARGS);
if (rc < 0)
perror_msg_and_skip(TEST_SYSCALL_STR);
- printf("%s(%d%s, {sa_family=AF_UNIX, sun_path=\"%s\"}"
+ printf("%s%s(%d%s%s, {sa_family=AF_UNIX, sun_path=\"%s\"%s}"
", [%d]%s) = %d\n",
- TEST_SYSCALL_STR, fd, PREFIX_S_STR, addr->sun_path,
+ my_secontext,
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_S_STR,
+ addr->sun_path, SECONTEXT_FILE(addr->sun_path),
(int) *plen, SUFFIX_STR, rc);
PREPARE_TEST_SYSCALL_INVOCATION;
rc = TEST_SYSCALL_NAME(fd PREFIX_F_ARGS, (void *) addr, 0 SUFFIX_ARGS);
- printf("%s(%d%s, %p, NULL%s) = %s\n",
- TEST_SYSCALL_STR, fd, PREFIX_F_STR, addr, SUFFIX_STR,
- sprintrc(rc));
+ printf("%s%s(%d%s%s, %p, NULL%s) = %s\n",
+ my_secontext,
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_F_STR,
+ addr, SUFFIX_STR, sprintrc(rc));
PREPARE_TEST_SYSCALL_INVOCATION;
rc = TEST_SYSCALL_NAME(fd PREFIX_S_ARGS, 0, 0 SUFFIX_ARGS);
- printf("%s(%d%s, NULL, NULL%s) = %s\n",
- TEST_SYSCALL_STR, fd, rc == -1 ? PREFIX_F_STR : PREFIX_S_STR,
+ printf("%s%s(%d%s%s, NULL, NULL%s) = %s\n",
+ my_secontext,
+ TEST_SYSCALL_STR, fd, fd_secontext,
+ rc == -1 ? PREFIX_F_STR : PREFIX_S_STR,
SUFFIX_STR, sprintrc(rc));
PREPARE_TEST_SYSCALL_INVOCATION;
rc = TEST_SYSCALL_NAME(fd PREFIX_F_ARGS, (void *) addr,
plen + 1 SUFFIX_ARGS);
- printf("%s(%d%s, %p, %p%s) = %s\n",
- TEST_SYSCALL_STR, fd, PREFIX_F_STR, addr,
+ printf("%s%s(%d%s%s, %p, %p%s) = %s\n",
+ my_secontext,
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_F_STR, addr,
plen + 1, SUFFIX_STR, sprintrc(rc));
const size_t offsetof_sun_path = offsetof(struct sockaddr_un, sun_path);
@@ -108,8 +121,9 @@
plen SUFFIX_ARGS);
if (rc < 0)
perror_msg_and_skip(TEST_SYSCALL_STR);
- printf("%s(%d%s, {sa_family=AF_UNIX}, [%d => %d]%s) = %d\n",
- TEST_SYSCALL_STR, fd, PREFIX_S_STR,
+ printf("%s%s(%d%s%s, {sa_family=AF_UNIX}, [%d => %d]%s) = %d\n",
+ my_secontext,
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_S_STR,
(int) offsetof_sun_path, (int) *plen, SUFFIX_STR, rc);
++addr;
@@ -121,17 +135,19 @@
plen SUFFIX_ARGS);
if (rc < 0)
perror_msg_and_skip(TEST_SYSCALL_STR);
- printf("%s(%d%s, {sa_family=AF_UNIX, sun_path=\"%.*s\"}"
+ printf("%s%s(%d%s%s, {sa_family=AF_UNIX, sun_path=\"%.*s\"%s}"
", [%d => %d]%s) = %d\n",
- TEST_SYSCALL_STR, fd, PREFIX_S_STR,
+ my_secontext,
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_S_STR,
(int) (sizeof(struct sockaddr) - offsetof_sun_path),
- addr->sun_path, (int) sizeof(struct sockaddr),
- (int) *plen, SUFFIX_STR, rc);
+ addr->sun_path, SECONTEXT_FILE(addr->sun_path),
+ (int) sizeof(struct sockaddr), (int) *plen, SUFFIX_STR, rc);
PREPARE_TEST_SYSCALL_INVOCATION;
rc = TEST_SYSCALL_NAME(fd PREFIX_F_ARGS, (void *) addr,
plen SUFFIX_ARGS);
- printf("%s(%d%s, %p, [%d]%s) = %s\n",
- TEST_SYSCALL_STR, fd, PREFIX_F_STR, addr,
+ printf("%s%s(%d%s%s, %p, [%d]%s) = %s\n",
+ my_secontext,
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_F_STR, addr,
*plen, SUFFIX_STR, sprintrc(rc));
}
Index: strace-5.18/tests-mx32/secontext.c
===================================================================
--- strace-5.18.orig/tests-mx32/secontext.c 2022-07-12 18:17:36.747379459 +0200
+++ strace-5.18/tests-mx32/secontext.c 2022-07-12 18:20:18.496470519 +0200
@@ -141,6 +141,21 @@
return full_secontext;
}
+static char *
+raw_secontext_full_fd(int fd)
+{
+ int saved_errno = errno;
+ char *full_secontext = NULL;
+ char *secontext;
+
+ if (fgetfilecon(fd, &secontext) >= 0) {
+ full_secontext = strip_trailing_newlines(xstrdup(secontext));
+ freecon(secontext);
+ }
+ errno = saved_errno;
+ return full_secontext;
+}
+
char *
get_secontext_field_file(const char *file, enum secontext_field field)
{
@@ -151,6 +166,16 @@
return type;
}
+char *
+get_secontext_field_fd(int fd, enum secontext_field field)
+{
+ char *ctx = raw_secontext_full_fd(fd);
+ char *type = get_secontext_field(ctx, field);
+ free(ctx);
+
+ return type;
+}
+
static char *
raw_secontext_short_file(const char *filename)
{
@@ -158,6 +183,12 @@
}
static char *
+raw_secontext_short_fd(int fd)
+{
+ return get_secontext_field_fd(fd, SECONTEXT_TYPE);
+}
+
+static char *
raw_secontext_full_pid(pid_t pid)
{
int saved_errno = errno;
@@ -205,6 +236,15 @@
}
char *
+secontext_full_fd(int fd)
+{
+ int saved_errno = errno;
+ char *context = raw_secontext_full_fd(fd);
+ errno = saved_errno;
+ return FORMAT_SPACE_BEFORE(context);
+}
+
+char *
secontext_full_pid(pid_t pid)
{
return FORMAT_SPACE_AFTER(raw_secontext_full_pid(pid));
@@ -228,6 +268,15 @@
errno = saved_errno;
return FORMAT_SPACE_BEFORE(context);
}
+
+char *
+secontext_short_fd(int fd)
+{
+ int saved_errno = errno;
+ char *context = raw_secontext_short_fd(fd);
+ errno = saved_errno;
+ return FORMAT_SPACE_BEFORE(context);
+}
char *
secontext_short_pid(pid_t pid)
Index: strace-5.18/tests-mx32/secontext.h
===================================================================
--- strace-5.18.orig/tests-mx32/secontext.h 2022-07-12 18:17:36.747379459 +0200
+++ strace-5.18/tests-mx32/secontext.h 2022-07-12 18:20:18.496470519 +0200
@@ -9,9 +9,11 @@
#include "xmalloc.h"
#include <unistd.h>
+char *secontext_full_fd(int) ATTRIBUTE_MALLOC;
char *secontext_full_file(const char *, bool) ATTRIBUTE_MALLOC;
char *secontext_full_pid(pid_t) ATTRIBUTE_MALLOC;
+char *secontext_short_fd(int) ATTRIBUTE_MALLOC;
char *secontext_short_file(const char *, bool) ATTRIBUTE_MALLOC;
char *secontext_short_pid(pid_t) ATTRIBUTE_MALLOC;
@@ -30,6 +32,7 @@
*/
char *get_secontext_field(const char *full_context, enum secontext_field field);
+char *get_secontext_field_fd(int fd, enum secontext_field field);
char *get_secontext_field_file(const char *file, enum secontext_field field);
void reset_secontext_file(const char *file);
@@ -44,6 +47,7 @@
# else
# define SECONTEXT_FILE(filename) secontext_full_file(filename, false)
# endif
+# define SECONTEXT_FD(fd) secontext_full_fd(fd)
# define SECONTEXT_PID(pid) secontext_full_pid(pid)
# else
@@ -53,6 +57,7 @@
# else
# define SECONTEXT_FILE(filename) secontext_short_file(filename, false)
# endif
+# define SECONTEXT_FD(fd) secontext_short_fd(fd)
# define SECONTEXT_PID(pid) secontext_short_pid(pid)
# endif
@@ -65,6 +70,12 @@
return NULL;
}
static inline char *
+get_secontext_field_fd(int fd, enum secontext_field field)
+{
+ return NULL;
+}
+
+static inline char *
get_secontext_field_file(const char *file, enum secontext_field field)
{
return NULL;
@@ -81,6 +92,7 @@
{
}
+# define SECONTEXT_FD(fd) xstrdup("")
# define SECONTEXT_FILE(filename) xstrdup("")
# define SECONTEXT_PID(pid) xstrdup("")
Index: strace-5.18/tests-mx32/sockname.c
===================================================================
--- strace-5.18.orig/tests-mx32/sockname.c 2022-07-12 18:17:36.748379448 +0200
+++ strace-5.18/tests-mx32/sockname.c 2022-07-12 18:20:18.496470519 +0200
@@ -18,6 +18,8 @@
#include <sys/socket.h>
#include <sys/un.h>
+#include "secontext.h"
+
#ifndef TEST_SYSCALL_NAME
# error TEST_SYSCALL_NAME must be defined
#endif
@@ -59,14 +61,19 @@
*plen = sizeof(struct sockaddr_un);
struct sockaddr_un *addr = tail_alloc(*plen);
+ char *my_secontext = SECONTEXT_PID_MY();
+ char *fd_secontext = SECONTEXT_FD(fd);
+
PREPARE_TEST_SYSCALL_INVOCATION;
int rc = TEST_SYSCALL_NAME(fd PREFIX_S_ARGS, (void *) addr,
plen SUFFIX_ARGS);
if (rc < 0)
perror_msg_and_skip(TEST_SYSCALL_STR);
- printf("%s(%d%s, {sa_family=AF_UNIX, sun_path=\"%s\"}"
+ printf("%s%s(%d%s%s, {sa_family=AF_UNIX, sun_path=\"%s\"%s}"
", [%d => %d]%s) = %d\n",
- TEST_SYSCALL_STR, fd, PREFIX_S_STR, addr->sun_path,
+ my_secontext,
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_S_STR,
+ addr->sun_path, SECONTEXT_FILE(addr->sun_path),
(int) sizeof(struct sockaddr_un), (int) *plen, SUFFIX_STR, rc);
memset(addr, 0, sizeof(*addr));
@@ -75,28 +82,34 @@
plen SUFFIX_ARGS);
if (rc < 0)
perror_msg_and_skip(TEST_SYSCALL_STR);
- printf("%s(%d%s, {sa_family=AF_UNIX, sun_path=\"%s\"}"
+ printf("%s%s(%d%s%s, {sa_family=AF_UNIX, sun_path=\"%s\"%s}"
", [%d]%s) = %d\n",
- TEST_SYSCALL_STR, fd, PREFIX_S_STR, addr->sun_path,
+ my_secontext,
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_S_STR,
+ addr->sun_path, SECONTEXT_FILE(addr->sun_path),
(int) *plen, SUFFIX_STR, rc);
PREPARE_TEST_SYSCALL_INVOCATION;
rc = TEST_SYSCALL_NAME(fd PREFIX_F_ARGS, (void *) addr, 0 SUFFIX_ARGS);
- printf("%s(%d%s, %p, NULL%s) = %s\n",
- TEST_SYSCALL_STR, fd, PREFIX_F_STR, addr, SUFFIX_STR,
- sprintrc(rc));
+ printf("%s%s(%d%s%s, %p, NULL%s) = %s\n",
+ my_secontext,
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_F_STR,
+ addr, SUFFIX_STR, sprintrc(rc));
PREPARE_TEST_SYSCALL_INVOCATION;
rc = TEST_SYSCALL_NAME(fd PREFIX_S_ARGS, 0, 0 SUFFIX_ARGS);
- printf("%s(%d%s, NULL, NULL%s) = %s\n",
- TEST_SYSCALL_STR, fd, rc == -1 ? PREFIX_F_STR : PREFIX_S_STR,
+ printf("%s%s(%d%s%s, NULL, NULL%s) = %s\n",
+ my_secontext,
+ TEST_SYSCALL_STR, fd, fd_secontext,
+ rc == -1 ? PREFIX_F_STR : PREFIX_S_STR,
SUFFIX_STR, sprintrc(rc));
PREPARE_TEST_SYSCALL_INVOCATION;
rc = TEST_SYSCALL_NAME(fd PREFIX_F_ARGS, (void *) addr,
plen + 1 SUFFIX_ARGS);
- printf("%s(%d%s, %p, %p%s) = %s\n",
- TEST_SYSCALL_STR, fd, PREFIX_F_STR, addr,
+ printf("%s%s(%d%s%s, %p, %p%s) = %s\n",
+ my_secontext,
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_F_STR, addr,
plen + 1, SUFFIX_STR, sprintrc(rc));
const size_t offsetof_sun_path = offsetof(struct sockaddr_un, sun_path);
@@ -108,8 +121,9 @@
plen SUFFIX_ARGS);
if (rc < 0)
perror_msg_and_skip(TEST_SYSCALL_STR);
- printf("%s(%d%s, {sa_family=AF_UNIX}, [%d => %d]%s) = %d\n",
- TEST_SYSCALL_STR, fd, PREFIX_S_STR,
+ printf("%s%s(%d%s%s, {sa_family=AF_UNIX}, [%d => %d]%s) = %d\n",
+ my_secontext,
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_S_STR,
(int) offsetof_sun_path, (int) *plen, SUFFIX_STR, rc);
++addr;
@@ -121,17 +135,19 @@
plen SUFFIX_ARGS);
if (rc < 0)
perror_msg_and_skip(TEST_SYSCALL_STR);
- printf("%s(%d%s, {sa_family=AF_UNIX, sun_path=\"%.*s\"}"
+ printf("%s%s(%d%s%s, {sa_family=AF_UNIX, sun_path=\"%.*s\"%s}"
", [%d => %d]%s) = %d\n",
- TEST_SYSCALL_STR, fd, PREFIX_S_STR,
+ my_secontext,
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_S_STR,
(int) (sizeof(struct sockaddr) - offsetof_sun_path),
- addr->sun_path, (int) sizeof(struct sockaddr),
- (int) *plen, SUFFIX_STR, rc);
+ addr->sun_path, SECONTEXT_FILE(addr->sun_path),
+ (int) sizeof(struct sockaddr), (int) *plen, SUFFIX_STR, rc);
PREPARE_TEST_SYSCALL_INVOCATION;
rc = TEST_SYSCALL_NAME(fd PREFIX_F_ARGS, (void *) addr,
plen SUFFIX_ARGS);
- printf("%s(%d%s, %p, [%d]%s) = %s\n",
- TEST_SYSCALL_STR, fd, PREFIX_F_STR, addr,
+ printf("%s%s(%d%s%s, %p, [%d]%s) = %s\n",
+ my_secontext,
+ TEST_SYSCALL_STR, fd, fd_secontext, PREFIX_F_STR, addr,
*plen, SUFFIX_STR, sprintrc(rc));
}

View File

@ -0,0 +1,374 @@
From 676979fa9cc7920e5e4d547814f9c0edb597fa0d Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Thu, 30 Jun 2022 16:01:05 +0200
Subject: [PATCH] pathtrace, util: do not print " (deleted)" as part of the
path
In order to allow to discern the unlinked paths from the paths that
do indeed end with " (deleted)".
* src/defs.h (getfdpath_pid): Add deleted parameter.
(getfdpath): Pass NULL as deleted parameter to getfdpath_pid.
* src/largefile_wrappers.h (lstat_file): New macro.
* src/pathtrace.c: Include <sys/stat.h>, <sys/types.h>, <unistd.h>,
and "largefile_wrappers.h".
(getfdpath_pid): Add deleted parameter, check if path ends with
" (deleted)", and if it is, try to figure out if it is a part
of the path by comparing device/inode numbers of the file procfs
link resolves into and the file pointed by the path read; strip
" (deleted)"; set deleted (if it is non-NULL) to true if the fd
is turned out to be deleted and to false otherwise.
* src/util.c (print_quoted_string_in_angle_brackets): Add deleted
parameter, print "(deleted)" after the closing angle bracket if it is
non-NULL.
(printfd_pid): Add deleted local variable, pass it to getfdpath_pid
and print_quoted_string_in_angle_brackets calls.
* tests/fchmod.c: Add checks for a file with " (deleted)" in the path,
update expected output.
* NEWS: Mention the change.
---
NEWS | 5 +++++
src/defs.h | 5 +++--
src/largefile_wrappers.h | 2 ++
src/pathtrace.c | 48 +++++++++++++++++++++++++++++++++++++++++++++---
src/util.c | 10 +++++++---
tests/fchmod.c | 47 +++++++++++++++++++++++++++++++++++++++++++----
6 files changed, 105 insertions(+), 12 deletions(-)
Index: strace-5.18/NEWS
===================================================================
--- strace-5.18.orig/NEWS 2022-07-13 12:52:48.219784860 +0200
+++ strace-5.18/NEWS 2022-07-13 12:52:48.451782122 +0200
@@ -1,6 +1,11 @@
Noteworthy changes in release 5.18 (2022-06-18)
===============================================
+* Changes in behaviour
+ * The "(deleted)" marker for unlinked paths of file descriptors is now printed
+ outside angle brackets; the matching of unlinked paths of file descriptors
+ no longer includes the " (deleted)" part into consideration.
+
* Improvements
* Added an interface of raising des Strausses awareness.
* Added --tips option to print strace tips, tricks, and tweaks
Index: strace-5.18/src/defs.h
===================================================================
--- strace-5.18.orig/src/defs.h 2022-07-13 12:52:29.405006910 +0200
+++ strace-5.18/src/defs.h 2022-07-13 12:52:54.532710356 +0200
@@ -785,12 +785,13 @@
return pathtrace_match_set(tcp, &global_path_set);
}
-extern int getfdpath_pid(pid_t pid, int fd, char *buf, unsigned bufsize);
+extern int getfdpath_pid(pid_t pid, int fd, char *buf, unsigned bufsize,
+ bool *deleted);
static inline int
getfdpath(struct tcb *tcp, int fd, char *buf, unsigned bufsize)
{
- return getfdpath_pid(tcp->pid, fd, buf, bufsize);
+ return getfdpath_pid(tcp->pid, fd, buf, bufsize, NULL);
}
extern unsigned long getfdinode(struct tcb *, int);
Index: strace-5.18/src/largefile_wrappers.h
===================================================================
--- strace-5.18.orig/src/largefile_wrappers.h 2022-07-13 12:52:29.405006910 +0200
+++ strace-5.18/src/largefile_wrappers.h 2022-07-13 12:52:48.451782122 +0200
@@ -31,6 +31,7 @@
# endif
# define fstat_fd fstat64
# define strace_stat_t struct stat64
+# define lstat_file lstat64
# define stat_file stat64
# define struct_dirent struct dirent64
# define read_dir readdir64
@@ -42,6 +43,7 @@
# define fcntl_fd fcntl
# define fstat_fd fstat
# define strace_stat_t struct stat
+# define lstat_file lstat
# define stat_file stat
# define struct_dirent struct dirent
# define read_dir readdir
Index: strace-5.18/src/pathtrace.c
===================================================================
--- strace-5.18.orig/src/pathtrace.c 2022-07-13 12:52:29.405006910 +0200
+++ strace-5.18/src/pathtrace.c 2022-07-13 12:52:54.532710356 +0200
@@ -10,7 +10,11 @@
#include "defs.h"
#include <limits.h>
#include <poll.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include "largefile_wrappers.h"
#include "number_set.h"
#include "sen.h"
#include "xstring.h"
@@ -77,7 +81,7 @@
* Get path associated with fd of a process with pid.
*/
int
-getfdpath_pid(pid_t pid, int fd, char *buf, unsigned bufsize)
+getfdpath_pid(pid_t pid, int fd, char *buf, unsigned bufsize, bool *deleted)
{
char linkpath[sizeof("/proc/%u/fd/%u") + 2 * sizeof(int)*3];
ssize_t n;
@@ -91,12 +95,50 @@
xsprintf(linkpath, "/proc/%u/fd/%u", proc_pid, fd);
n = readlink(linkpath, buf, bufsize - 1);
+ if (n < 0)
+ goto end;
+
/*
* NB: if buf is too small, readlink doesn't fail,
* it returns truncated result (IOW: n == bufsize - 1).
*/
- if (n >= 0)
- buf[n] = '\0';
+ buf[n] = '\0';
+ if (deleted)
+ *deleted = false;
+
+ /*
+ * Try to figure out if the kernel has appended " (deleted)"
+ * to the end of a potentially unlinked path and set deleted
+ * if it is the case.
+ */
+ static const char del_sfx[] = " (deleted)";
+ if ((size_t) n <= sizeof(del_sfx))
+ goto end;
+
+ char *del = buf + n + 1 - sizeof(del_sfx);
+
+ if (memcmp(del, del_sfx, sizeof(del_sfx)))
+ goto end;
+
+ strace_stat_t st_link;
+ strace_stat_t st_path;
+ int rc = stat_file(linkpath, &st_link);
+
+ if (rc)
+ goto end;
+
+ rc = lstat_file(buf, &st_path);
+
+ if (rc ||
+ (st_link.st_ino != st_path.st_ino) ||
+ (st_link.st_dev != st_path.st_dev)) {
+ *del = '\0';
+ n = del - buf + 1;
+ if (deleted)
+ *deleted = true;
+ }
+
+end:
return n;
}
Index: strace-5.18/src/util.c
===================================================================
--- strace-5.18.orig/src/util.c 2022-07-13 12:52:47.989787575 +0200
+++ strace-5.18/src/util.c 2022-07-13 12:52:48.452782111 +0200
@@ -735,12 +735,15 @@
}
static void
-print_quoted_string_in_angle_brackets(const char *str)
+print_quoted_string_in_angle_brackets(const char *str, const bool deleted)
{
tprints("<");
print_quoted_string_ex(str, strlen(str),
QUOTE_OMIT_LEADING_TRAILING_QUOTES, "<>");
tprints(">");
+
+ if (deleted)
+ tprints("(deleted)");
}
void
@@ -749,8 +752,9 @@
PRINT_VAL_D(fd);
char path[PATH_MAX + 1];
+ bool deleted;
if (pid > 0 && !number_set_array_is_empty(decode_fd_set, 0)
- && getfdpath_pid(pid, fd, path, sizeof(path)) >= 0) {
+ && getfdpath_pid(pid, fd, path, sizeof(path), &deleted) >= 0) {
if (is_number_in_set(DECODE_FD_SOCKET, decode_fd_set) &&
printsocket(tcp, fd, path))
goto printed;
@@ -761,7 +765,7 @@
printpidfd(pid, fd, path))
goto printed;
if (is_number_in_set(DECODE_FD_PATH, decode_fd_set))
- print_quoted_string_in_angle_brackets(path);
+ print_quoted_string_in_angle_brackets(path, deleted);
printed: ;
}
Index: strace-5.18/tests/fchmod.c
===================================================================
--- strace-5.18.orig/tests/fchmod.c 2022-07-13 12:52:29.405006910 +0200
+++ strace-5.18/tests/fchmod.c 2022-07-13 12:52:48.452782111 +0200
@@ -35,10 +35,17 @@
(void) unlink(sample);
int fd = open(sample, O_CREAT|O_RDONLY, 0400);
if (fd == -1)
- perror_msg_and_fail("open");
+ perror_msg_and_fail("open(\"%s\")", sample);
+
+ static const char sample_del[] = "fchmod_sample_file (deleted)";
+ (void) unlink(sample_del);
+ int fd_del = open(sample_del, O_CREAT|O_RDONLY, 0400);
+ if (fd_del == -1)
+ perror_msg_and_fail("open(\"%s\")", sample);
# ifdef YFLAG
char *sample_realpath = get_fd_path(fd);
+ char *sample_del_realpath = get_fd_path(fd_del);
# endif
const char *sample_secontext = SECONTEXT_FILE(sample);
@@ -56,12 +63,27 @@
sample_secontext,
sprintrc(rc));
+ const char *sample_del_secontext = SECONTEXT_FILE(sample_del);
+ rc = syscall(__NR_fchmod, fd_del, 0600);
+# ifdef YFLAG
+ printf("%s%s(%d<%s>%s, 0600) = %s\n",
+# else
+ printf("%s%s(%d%s, 0600) = %s\n",
+# endif
+ my_secontext, "fchmod",
+ fd_del,
+# ifdef YFLAG
+ sample_del_realpath,
+# endif
+ sample_del_secontext,
+ sprintrc(rc));
+
if (unlink(sample))
- perror_msg_and_fail("unlink");
+ perror_msg_and_fail("unlink(\"%s\")", sample);
rc = syscall(__NR_fchmod, fd, 051);
# ifdef YFLAG
- printf("%s%s(%d<%s (deleted)>%s, 051) = %s\n",
+ printf("%s%s(%d<%s>(deleted)%s, 051) = %s\n",
# else
printf("%s%s(%d%s, 051) = %s\n",
# endif
@@ -73,9 +95,26 @@
sample_secontext,
sprintrc(rc));
+ if (unlink(sample_del))
+ perror_msg_and_fail("unlink(\"%s\")", sample_del);
+
+ rc = syscall(__NR_fchmod, fd_del, 051);
+# ifdef YFLAG
+ printf("%s%s(%d<%s>(deleted)%s, 051) = %s\n",
+# else
+ printf("%s%s(%d%s, 051) = %s\n",
+# endif
+ my_secontext, "fchmod",
+ fd_del,
+# ifdef YFLAG
+ sample_del_realpath,
+# endif
+ sample_del_secontext,
+ sprintrc(rc));
+
rc = syscall(__NR_fchmod, fd, 004);
# ifdef YFLAG
- printf("%s%s(%d<%s (deleted)>%s, 004) = %s\n",
+ printf("%s%s(%d<%s>(deleted)%s, 004) = %s\n",
# else
printf("%s%s(%d%s, 004) = %s\n",
# endif
Index: strace-5.18/tests-m32/fchmod.c
===================================================================
--- strace-5.18.orig/tests-m32/fchmod.c 2022-07-13 12:52:29.405006910 +0200
+++ strace-5.18/tests-m32/fchmod.c 2022-07-13 12:52:48.452782111 +0200
@@ -35,10 +35,17 @@
(void) unlink(sample);
int fd = open(sample, O_CREAT|O_RDONLY, 0400);
if (fd == -1)
- perror_msg_and_fail("open");
+ perror_msg_and_fail("open(\"%s\")", sample);
+
+ static const char sample_del[] = "fchmod_sample_file (deleted)";
+ (void) unlink(sample_del);
+ int fd_del = open(sample_del, O_CREAT|O_RDONLY, 0400);
+ if (fd_del == -1)
+ perror_msg_and_fail("open(\"%s\")", sample);
# ifdef YFLAG
char *sample_realpath = get_fd_path(fd);
+ char *sample_del_realpath = get_fd_path(fd_del);
# endif
const char *sample_secontext = SECONTEXT_FILE(sample);
@@ -56,12 +63,27 @@
sample_secontext,
sprintrc(rc));
+ const char *sample_del_secontext = SECONTEXT_FILE(sample_del);
+ rc = syscall(__NR_fchmod, fd_del, 0600);
+# ifdef YFLAG
+ printf("%s%s(%d<%s>%s, 0600) = %s\n",
+# else
+ printf("%s%s(%d%s, 0600) = %s\n",
+# endif
+ my_secontext, "fchmod",
+ fd_del,
+# ifdef YFLAG
+ sample_del_realpath,
+# endif
+ sample_del_secontext,
+ sprintrc(rc));
+
if (unlink(sample))
- perror_msg_and_fail("unlink");
+ perror_msg_and_fail("unlink(\"%s\")", sample);
rc = syscall(__NR_fchmod, fd, 051);
# ifdef YFLAG
- printf("%s%s(%d<%s (deleted)>%s, 051) = %s\n",
+ printf("%s%s(%d<%s>(deleted)%s, 051) = %s\n",
# else
printf("%s%s(%d%s, 051) = %s\n",
# endif
@@ -73,9 +95,26 @@
sample_secontext,
sprintrc(rc));
+ if (unlink(sample_del))
+ perror_msg_and_fail("unlink(\"%s\")", sample_del);
+
+ rc = syscall(__NR_fchmod, fd_del, 051);
+# ifdef YFLAG
+ printf("%s%s(%d<%s>(deleted)%s, 051) = %s\n",
+# else
+ printf("%s%s(%d%s, 051) = %s\n",
+# endif
+ my_secontext, "fchmod",
+ fd_del,
+# ifdef YFLAG
+ sample_del_realpath,
+# endif
+ sample_del_secontext,
+ sprintrc(rc));
+
rc = syscall(__NR_fchmod, fd, 004);
# ifdef YFLAG
- printf("%s%s(%d<%s (deleted)>%s, 004) = %s\n",
+ printf("%s%s(%d<%s>(deleted)%s, 004) = %s\n",
# else
printf("%s%s(%d%s, 004) = %s\n",
# endif

View File

@ -0,0 +1,209 @@
From 3f0e5340b651da98251a58cc7923525d69f96032 Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Fri, 1 Jul 2022 10:45:48 +0200
Subject: [PATCH] secontext: fix expected SELinux context check for unlinked
FDs
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
selinux_getfdcon open-coded a part of getfdpath_pid since it tries
to do the same job, figure out a path associated with an FD, for slightly
different purpose: to get the expected SELinux context for it. As the previous
commit shows, it's a bit more complicated in cases when the path ends
with the " (deleted)" string, which is also used for designated unlinked paths
in procfs. Otherwise, it may manifest in test failures such as this:
[unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023] fchmod(4</root/rpmbuild/BUILD/strace-5.13/tests/fchmod-y--secontext_full_mismatch.dir/fchmod_subdir/fchmod_sample_file> [unconfined_u:object_r:admin_home_t:s0!!system_u:object_r:admin_home_t:s0], 0600) = 0
-[unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023] fchmod(4</root/rpmbuild/BUILD/strace-5.13/tests/fchmod-y--secontext_full_mismatch.dir/fchmod_subdir/fchmod_sample_file (deleted)> [unconfined_u:object_r:admin_home_t:s0!!system_u:object_r:admin_home_t:s0], 051) = 0
-[unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023] fchmod(4</root/rpmbuild/BUILD/strace-5.13/tests/fchmod-y--secontext_full_mismatch.dir/fchmod_subdir/fchmod_sample_file (deleted)> [unconfined_u:object_r:admin_home_t:s0!!system_u:object_r:admin_home_t:s0], 004) = 0
+[unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023] fchmod(4</root/rpmbuild/BUILD/strace-5.13/tests/fchmod-y--secontext_full_mismatch.dir/fchmod_subdir/fchmod_sample_file (deleted)> [unconfined_u:object_r:admin_home_t:s0], 051) = 0
+[unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023] fchmod(4</root/rpmbuild/BUILD/strace-5.13/tests/fchmod-y--secontext_full_mismatch.dir/fchmod_subdir/fchmod_sample_file (deleted)> [unconfined_u:object_r:admin_home_t:s0], 004) = 0
+++ exited with 0 +++
+ fail_ '../../src/strace -a15 -y --secontext=full,mismatch -e trace=fchmod ../fchmod-y--secontext_full_mismatch output mismatch'
+ warn_ 'fchmod-y--secontext_full_mismatch.gen.test: failed test: ../../src/strace -a15 -y --secontext=full,mismatch -e trace=fchmod ../fchmod-y--secontext_full_mismatch output mismatch'
+ printf '%s\n' 'fchmod-y--secontext_full_mismatch.gen.test: failed test: ../../src/strace -a15 -y --secontext=full,mismatch -e trace=fchmod ../fchmod-y--secontext_full_mismatch output mismatch'
fchmod-y--secontext_full_mismatch.gen.test: failed test: ../../src/strace -a15 -y --secontext=full,mismatch -e trace=fchmod ../fchmod-y--secontext_full_mismatch output mismatch
+ exit 1
FAIL fchmod-y--secontext_full_mismatch.gen.test (exit status: 1)
that happens due to the fact that the get_expected_filecontext() call
is made against the path with the " (deleted)" part, which is wrong (it
is more wrong than shown above when a file with the path that ends with
" (deleted)" exists). Moreover, it would be incorrect to call stat()
on that path.
Let's factor out the common part of the code and simply call it
from selinux_getfdcon, then use the st_mode from the procfs link.
* src/defs.h (get_proc_pid_fd_path): New declaration.
* src/pathtrace.c (get)proc_pid_fd_path): New function, part
of getfdpath_pid that performs link resolution and processing
of the result.
(getfdpath_pid): Call get_proc_pid_fd_path after PID resolution.
* src/secontext.c (get_expected_filecontext): Add mode parameter, use
it in selabel_lookup call instead of retrieveing file mode using stat()
if it is not -1.
(selinux_getfdcon): Call get_proc_pid_fd_path instead
of open-coding path resolution code, call stat() on the procfs link
and pass the retrieved st_mode to the get_expected_filecontext call.
(selinux_getfilecon): Pass -1 as mode in the get_expected_filecontext
call.
Reported-by: Václav Kadlčík <vkadlcik@redhat.com>
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2087693
---
src/defs.h | 15 +++++++++++++++
src/pathtrace.c | 26 ++++++++++++++++++--------
src/secontext.c | 35 +++++++++++++++++++++--------------
3 files changed, 54 insertions(+), 22 deletions(-)
Index: strace-5.18/src/defs.h
===================================================================
--- strace-5.18.orig/src/defs.h 2022-07-12 18:22:01.563254140 +0200
+++ strace-5.18/src/defs.h 2022-07-12 18:22:06.202199392 +0200
@@ -785,6 +785,21 @@
return pathtrace_match_set(tcp, &global_path_set);
}
+/**
+ * Resolves a path for a fd procfs PID proc_pid (the one got from
+ * get_proc_pid()).
+ *
+ * @param proc_pid PID number in /proc, obtained with get_proc_pid().
+ * @param fd FD to resolve path for.
+ * @param buf Buffer to store the resolved path in.
+ * @param bufsize The size of buf.
+ * @param deleted If non-NULL, set to true if the path associated with the FD
+ * seems to have been unlinked and to false otherwise.
+ * @return Number of bytes written including terminating '\0'.
+ */
+extern int get_proc_pid_fd_path(int proc_pid, int fd, char *buf,
+ unsigned bufsize, bool *deleted);
+
extern int getfdpath_pid(pid_t pid, int fd, char *buf, unsigned bufsize,
bool *deleted);
Index: strace-5.18/src/pathtrace.c
===================================================================
--- strace-5.18.orig/src/pathtrace.c 2022-07-12 18:22:01.532254506 +0200
+++ strace-5.18/src/pathtrace.c 2022-07-12 18:22:06.202199392 +0200
@@ -77,11 +77,9 @@
set->paths_selected[set->num_selected++] = path;
}
-/*
- * Get path associated with fd of a process with pid.
- */
int
-getfdpath_pid(pid_t pid, int fd, char *buf, unsigned bufsize, bool *deleted)
+get_proc_pid_fd_path(int proc_pid, int fd, char *buf, unsigned bufsize,
+ bool *deleted)
{
char linkpath[sizeof("/proc/%u/fd/%u") + 2 * sizeof(int)*3];
ssize_t n;
@@ -89,10 +87,6 @@
if (fd < 0)
return -1;
- int proc_pid = get_proc_pid(pid);
- if (!proc_pid)
- return -1;
-
xsprintf(linkpath, "/proc/%u/fd/%u", proc_pid, fd);
n = readlink(linkpath, buf, bufsize - 1);
if (n < 0)
@@ -143,6 +137,22 @@
}
/*
+ * Get path associated with fd of a process with pid.
+ */
+int
+getfdpath_pid(pid_t pid, int fd, char *buf, unsigned bufsize, bool *deleted)
+{
+ if (fd < 0)
+ return -1;
+
+ int proc_pid = get_proc_pid(pid);
+ if (!proc_pid)
+ return -1;
+
+ return get_proc_pid_fd_path(proc_pid, fd, buf, bufsize, deleted);
+}
+
+/*
* Add a path to the set we're tracing. Also add the canonicalized
* version of the path. Specifying NULL will delete all paths.
*/
Index: strace-5.18/src/secontext.c
===================================================================
--- strace-5.18.orig/src/secontext.c 2022-07-12 18:22:01.564254128 +0200
+++ strace-5.18/src/secontext.c 2022-07-12 18:22:06.203199380 +0200
@@ -62,7 +62,7 @@
}
static int
-get_expected_filecontext(const char *path, char **secontext)
+get_expected_filecontext(const char *path, char **secontext, int mode)
{
static struct selabel_handle *hdl;
@@ -80,12 +80,7 @@
}
}
- strace_stat_t stb;
- if (stat_file(path, &stb) < 0) {
- return -1;
- }
-
- return selabel_lookup(hdl, secontext, path, stb.st_mode);
+ return selabel_lookup(hdl, secontext, path, mode);
}
/*
@@ -130,16 +125,22 @@
/*
* We need to resolve the path, because selabel_lookup() doesn't
- * resolve anything. Using readlink() is sufficient here.
+ * resolve anything.
*/
+ char buf[PATH_MAX + 1];
+ ssize_t n = get_proc_pid_fd_path(proc_pid, fd, buf, sizeof(buf), NULL);
+ if ((size_t) n >= (sizeof(buf) - 1))
+ return 0;
- char buf[PATH_MAX];
- ssize_t n = readlink(linkpath, buf, sizeof(buf));
- if ((size_t) n >= sizeof(buf))
+ /*
+ * We retrieve stat() here since the path the procfs link resolves into
+ * may be reused by a different file with different context.
+ */
+ strace_stat_t st;
+ if (stat_file(linkpath, &st))
return 0;
- buf[n] = '\0';
- get_expected_filecontext(buf, expected);
+ get_expected_filecontext(buf, expected, st.st_mode);
return 0;
}
@@ -190,7 +191,13 @@
if (!resolved)
return 0;
- get_expected_filecontext(resolved, expected);
+ strace_stat_t st;
+ if (stat_file(resolved, &st) < 0)
+ goto out;
+
+ get_expected_filecontext(resolved, expected, st.st_mode);
+
+out:
free(resolved);
return 0;

View File

@ -0,0 +1,70 @@
From 5338636cd9ae7f53ed73f1a7909db03189ea2ff3 Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Mon, 4 Jul 2022 12:29:22 +0200
Subject: [PATCH] tests/bpf: fix sloppy low FD number usage
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
FD 42 can already be opened, so close it. Otherwise, it may lead
to the following test failure:
-bpf(BPF_LINK_CREATE, {link_create={prog_fd=0</dev/full>, target_fd=0</dev/full>, attach_type=BPF_TRACE_ITER, flags=0, iter_info=[{map={map_fd=0</dev/full>}}, {map={map_fd=42}}, {map={map_fd=314159265}}, {map={map_fd=-1159983635}}, {map={map_fd=-1}}], iter_info_len=5}}, 28) = 841540765612359407 (INJECTED)
+bpf(BPF_LINK_CREATE, {link_create={prog_fd=0</dev/full>, target_fd=0</dev/full>, attach_type=BPF_TRACE_ITER, flags=0, iter_info=[{map={map_fd=0</dev/full>}}, {map={map_fd=42</var/tmp/restraintd/logs/146893626/task.log>}}, {map={map_fd=314159265}}, {map={map_fd=-1159983635}}, {map={map_fd=-1}}], iter_info_len=5}}, 28) = 841540765612359407 (INJECTED)
bpf(BPF_LINK_CREATE, 0x3ff95574fe5, 28) = 841540765612359407 (INJECTED)
-bpf(BPF_LINK_CREATE, {link_create={prog_fd=0</dev/full>, target_fd=0</dev/full>, attach_type=BPF_TRACE_ITER, flags=0, iter_info=[{map={map_fd=0</dev/full>}}, {map={map_fd=42}}, {map={map_fd=314159265}}, {map={map_fd=-1159983635}}, {map={map_fd=-1}}, ... /* 0x3ff9555d000 */], iter_info_len=6}}, 28) = 841540765612359407 (INJECTED)
+bpf(BPF_LINK_CREATE, {link_create={prog_fd=0</dev/full>, target_fd=0</dev/full>, attach_type=BPF_TRACE_ITER, flags=0, iter_info=[{map={map_fd=0</dev/full>}}, {map={map_fd=42</var/tmp/restraintd/logs/146893626/task.log>}}, {map={map_fd=314159265}}, {map={map_fd=-1159983635}}, {map={map_fd=-1}}, ... /* 0x3ff9555d000 */], iter_info_len=6}}, 28) = 841540765612359407 (INJECTED)
[...]
FAIL bpf-success-long-y.test (exit status: 1)
* tests/bpf.c (init_BPF_LINK_CREATE_attr7): Close iter_info_data[1] fd.
Fixes: v5.18~18 "bpf: improve bpf(BPF_LINK_CREATE) decoding"
Reported-by: Lenka Špačková <lkuprova@redhat.com>
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2103137
---
tests/bpf.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tests/bpf.c b/tests/bpf.c
index 82d870e..6c1ffd4 100644
--- a/tests/bpf.c
+++ b/tests/bpf.c
@@ -1557,6 +1557,8 @@ init_BPF_LINK_CREATE_attr7(struct bpf_attr_check *check, size_t idx)
{
struct BPF_LINK_CREATE_struct *attr = &check->data.BPF_LINK_CREATE_data;
+ close(iter_info_data[1]);
+
if (!iter_info_data_p) {
iter_info_data_p = tail_memdup(iter_info_data,
sizeof(iter_info_data));
diff --git a/tests-m32/bpf.c b/tests-m32/bpf.c
index 82d870e..6c1ffd4 100644
--- a/tests-m32/bpf.c
+++ b/tests-m32/bpf.c
@@ -1557,6 +1557,8 @@ init_BPF_LINK_CREATE_attr7(struct bpf_attr_check *check, size_t idx)
{
struct BPF_LINK_CREATE_struct *attr = &check->data.BPF_LINK_CREATE_data;
+ close(iter_info_data[1]);
+
if (!iter_info_data_p) {
iter_info_data_p = tail_memdup(iter_info_data,
sizeof(iter_info_data));
diff --git a/tests-mx32/bpf.c b/tests-mx32/bpf.c
index 82d870e..6c1ffd4 100644
--- a/tests-mx32/bpf.c
+++ b/tests-mx32/bpf.c
@@ -1557,6 +1557,8 @@ init_BPF_LINK_CREATE_attr7(struct bpf_attr_check *check, size_t idx)
{
struct BPF_LINK_CREATE_struct *attr = &check->data.BPF_LINK_CREATE_data;
+ close(iter_info_data[1]);
+
if (!iter_info_data_p) {
iter_info_data_p = tail_memdup(iter_info_data,
sizeof(iter_info_data));
--
2.1.4

View File

@ -1,42 +0,0 @@
Limit the scope of qual_fault.tests on aarch64 as otherwise it takes
unacceptable amount of time on available builders (more than an hour).
Index: strace-4.24/tests/qual_fault.test
===================================================================
--- strace-4.24.orig/tests/qual_fault.test 2019-06-13 17:37:10.708269613 +0200
+++ strace-4.24/tests/qual_fault.test 2019-06-13 17:41:29.358829506 +0200
@@ -75,18 +75,32 @@
done
}
-for err in '' ENOSYS 22 einval; do
+
+case "$STRACE_ARCH" in
+ aarch64)
+ NUMBERS1='2'
+ NUMBERS2='3'
+ ERRS='EnoSys 22'
+ ;;
+ *)
+ ERRS='ENOSYS 22 einval'
+ NUMBERS1='1 2 3 5 7 11'
+ NUMBERS2='1 2 3 5 7 11'
+ ;;
+esac
+
+for err in '' $(echo $ERRS); do
for fault in writev desc,51; do
check_fault_injection \
writev $fault "$err" '' '' 1 -efault=chdir
check_fault_injection \
writev $fault "$err" '' '' 1 -efault=chdir -efault=none
- for F in 1 2 3 5 7 11; do
+ for F in $(echo $NUMBERS1); do
check_fault_injection \
writev $fault "$err" $F '' 1
check_fault_injection \
writev $fault "$err" $F + 1
- for S in 1 2 3 5 7 11; do
+ for S in $(echo $NUMBERS2); do
check_fault_injection \
writev $fault "$err" $F $S 1
check_fault_injection \

View File

@ -1,76 +0,0 @@
Unfortunately, strace 5.1 rebase didn't make it into RHEL 8.2.
As a result, ksystent tests now fails due to presence of new io_uring* syscalls.
Disable it for 8.2 in anticipation of a rebase in 8.3 timeframe.
Index: strace-4.24/tests-m32/Makefile.am
===================================================================
--- strace-4.24.orig/tests-m32/Makefile.am 2019-12-02 18:36:41.156516491 +0100
+++ strace-4.24/tests-m32/Makefile.am 2019-12-02 20:32:00.744610221 +0100
@@ -323,7 +323,6 @@
get_regs.test \
inject-nf.test \
interactive_block.test \
- ksysent.test \
localtime.test \
opipe.test \
options-syntax.test \
Index: strace-4.24/tests-m32/Makefile.in
===================================================================
--- strace-4.24.orig/tests-m32/Makefile.in 2019-12-02 18:36:41.079516234 +0100
+++ strace-4.24/tests-m32/Makefile.in 2019-12-02 20:32:07.676582952 +0100
@@ -4246,7 +4246,6 @@
inject-nf.test \
interactive_block.test \
kill_child.test \
- ksysent.test \
localtime.test \
looping_threads.test \
opipe.test \
Index: strace-4.24/tests-mx32/Makefile.am
===================================================================
--- strace-4.24.orig/tests-mx32/Makefile.am 2019-12-02 18:36:41.156516491 +0100
+++ strace-4.24/tests-mx32/Makefile.am 2019-12-02 20:32:33.983479462 +0100
@@ -323,7 +323,6 @@
get_regs.test \
inject-nf.test \
interactive_block.test \
- ksysent.test \
localtime.test \
opipe.test \
options-syntax.test \
Index: strace-4.24/tests-mx32/Makefile.in
===================================================================
--- strace-4.24.orig/tests-mx32/Makefile.in 2019-12-02 18:36:41.080516237 +0100
+++ strace-4.24/tests-mx32/Makefile.in 2019-12-02 20:32:29.375497590 +0100
@@ -4246,7 +4246,6 @@
inject-nf.test \
interactive_block.test \
kill_child.test \
- ksysent.test \
localtime.test \
looping_threads.test \
opipe.test \
Index: strace-4.24/tests/Makefile.am
===================================================================
--- strace-4.24.orig/tests/Makefile.am 2019-12-02 18:36:41.156516491 +0100
+++ strace-4.24/tests/Makefile.am 2019-12-02 20:31:29.951731358 +0100
@@ -308,7 +308,6 @@
inject-nf.test \
interactive_block.test \
kill_child.test \
- ksysent.test \
localtime.test \
looping_threads.test \
opipe.test \
Index: strace-4.24/tests/Makefile.in
===================================================================
--- strace-4.24.orig/tests/Makefile.in 2019-12-02 18:36:41.160516504 +0100
+++ strace-4.24/tests/Makefile.in 2019-12-02 20:31:49.786653329 +0100
@@ -4259,7 +4259,6 @@
inject-nf.test \
interactive_block.test \
kill_child.test \
- ksysent.test \
localtime.test \
looping_threads.test \
opipe.test \

View File

@ -0,0 +1,59 @@
Index: strace-5.17/tests/qual_fault.test
===================================================================
--- strace-5.17.orig/tests/qual_fault.test 2022-06-09 15:47:28.871554186 +0200
+++ strace-5.17/tests/qual_fault.test 2022-06-09 15:50:50.016108370 +0200
@@ -83,19 +83,36 @@
done
}
-for err in '' ENOSYS 22 einval; do
+case "$STRACE_ARCH" in
+ aarch64)
+ ERRS='EnoSys 22'
+ NUMBERS1='2'
+ NUMBERS2='3'
+ NUMBERS3='5'
+ NUMBERS4='7'
+ ;;
+ *)
+ ERRS='ENOSYS 22 einval'
+ NUMBERS1='1 2 3 7'
+ NUMBERS2='1 2 5 11'
+ NUMBERS3='1 2 3 7'
+ NUMBERS4='1 2 7 11'
+ ;;
+esac
+
+for err in '' $(echo $ERRS); do
for fault in writev desc,51; do
check_fault_injection \
writev $fault "$err" '' '' '' 1 -efault=chdir
check_fault_injection \
writev $fault "$err" '' '' '' 1 -efault=chdir -efault=none
- for F in 1 2 3 7; do
+ for F in $(echo $NUMBERS1); do
check_fault_injection \
writev $fault "$err" $F '' '' 1
check_fault_injection \
writev $fault "$err" $F '' + 1
- for L in 1 2 5 11; do
+ for L in $(echo $NUMBERS2); do
[ "$L" -ge "$F" ] ||
continue
check_fault_injection \
@@ -104,12 +121,12 @@
writev $fault "$err" $F $L + 1
done
- for S in 1 2 3 7; do
+ for S in $(echo $NUMBERS3); do
check_fault_injection \
writev $fault "$err" $F '' $S 1
check_fault_injection \
writev $fault "$err" $F '' $S 4
- for L in 1 2 7 11; do
+ for L in $(echo $NUMBERS4); do
[ "$L" -ge "$F" ] ||
continue
check_fault_injection \

View File

@ -1,148 +1,308 @@
Summary: Tracks and displays system calls associated with a running process
Name: strace
Version: 4.24
Release: 6%{?dist}
Version: 5.18
Release: 2%{?dist}
# The test suite is GPLv2+, all the rest is LGPLv2.1+.
License: LGPL-2.1+ and GPL-2.0+
Group: Development/Debuggers
URL: https://strace.io/
Source: https://strace.io/files/%{version}/%{name}-%{version}.tar.xz
BuildRequires: libacl-devel time gcc gzip
BuildRequires: libacl-devel time gcc gzip make
BuildRequires: pkgconfig(bluez)
BuildRequires: elfutils-devel binutils-devel
## General bug fixes
# v4.25~91 "evdev: fix decoding of bit sets"
Patch1: 0001-evdev-fix-decoding-of-bit-sets.patch
# v4.25~90 "evdev: fix decoding of EVIOCGBIT(0, ...)"
Patch2: 0002-evdev-fix-decoding-of-EVIOCGBIT-0.patch
# v4.25~83 "xlat: fix typo in smc_protocols.in"
Patch3: 0003-xlat-fix-typo-in-smc_protocols.in.patch
## Pre-requisite for the queueing patch
# v4.25~82 "strace.c: introduce struct tcb_wait_data"
Patch4: 0004-strace.c-introduce-struct-tcb_wait_data.patch
## Documentation
# v4.26~83 "Document -X option in strace -h output"
Patch5: 0005-Document-X-option-in-strace-h-output.patch
## Addresses https://bugzilla.redhat.com/1660759 ("strace prints "xlat_idx:
## Unexpected xlat value 0 at index 4" messages")
# v4.26~36 "evdev: fix off-by-one error in decode_bitset"
Patch6: 0006-evdev-fix-off-by-one-error-in-decode_bitset.patch
# v4.26~35 "nlattr: fix off-by-one error in indexed xlat lookup"
Patch7: 0007-nlattr-fix-off-by-one-error-in-indexed-xlat-lookup.patch
# v4.26~34 "aio: fix off-by-one error in indexed xlat lookup"
Patch8: 0008-aio-fix-off-by-one-error-in-indexed-xlat-lookup.patch
# v4.26~31 "rtnl_link: fix off-by-one errors in indexed and sorted xlat lookups"
Patch9: 0009-rtnl_link-fix-off-by-one-errors-in-indexed-and-sorte.patch
# v4.26~30 "rtnl_link: fix off-by-one errors in indexed and sorted xlat lookups"
Patch10: 0010-xlat_idx-do-not-issue-warnings-for-holes-in-indices.patch
## man page updates
# v4.26~27 "strace.1.in: print names of entities in bold, provide man page sections"
Patch11: 0011-strace.1.in-print-names-of-entities-in-bold-provide-.patch
# v4.26~26 "strace.1.in: consistently use CTRL-combinations"
Patch12: 0012-strace.1.in-consistently-use-CTRL-combinations.patch
## License change
# v4.26~53 "tests: change the license to GPL-2.0-or-later"
Patch13: 0013-tests-change-the-license-to-GPL-2.0-or-later.patch
# v4.26~52 "Change the license of strace to LGPL-2.1-or-later"
Patch14: 0014-Change-the-license-of-strace-to-LGPL-2.1-or-later.patch
## Tests fixes, can be hit on newer kernels
# v5.0~95 "tests: use tail_alloc instead of calloc in bpf-obj_get_info_by_fd-prog*"
Patch15: 0015-tests-use-tail_alloc-instead-of-calloc-in-bpf-obj_ge.patch
# v5.0~94 "tests: fix prog_info initialization in bpf-obj_get_info_by_fd-prog*"
Patch16: 0016-tests-fix-prog_info-initialization-in-bpf-obj_get_in.patch
## General bug fixes
# v5.0~71 "Merge "<... resumed>" printing"
Patch17: 0017-Merge-.-resumed-printing.patch
# v5.0~69 "Use accessors for tcp->s_ent, return a stub struct if it is NULL"
Patch18: 0018-Use-accessors-for-tcp-s_ent-return-a-stub-struct-if-.patch
# v5.0~66 "syscall.c: set MEMORY_MAPPING_CHANGE in stub sysent"
Patch19: 0019-syscall.c-set-MEMORY_MAPPING_CHANGE-in-stub-sysent.patch
## Addresses https://bugzilla.redhat.com/1662936 ("strace reports
## 'ptrace(SYSCALL): No such process' on multi-threaded testcase on RHEL-8")
# v5.0~67 "Make inline message on failed restart attempt more verbose"
Patch20: 0020-Make-inline-message-on-failed-restart-attempt-more-v.patch
# v5.0~64 "ptrace_restart: do not print diagnostics when ptrace returns ESRCH"
Patch21: 0021-ptrace_restart-do-not-print-diagnostics-when-ptrace-.patch
## Pre-requisites for the queueing patch
# v5.0~60 "tests: add kill_child test"
Patch22: 0022-tests-add-kill_child-test.patch
# v5.0~30 "tests: move PTRACE_SEIZE check to a separate file"
Patch23: 0023-tests-move-PTRACE_SEIZE-check-to-a-separate-file.patch
# v5.0~29 "tests: check tracing of orphaned process group"
Patch24: 0024-tests-check-tracing-of-orphaned-process-group.patch
# v5.0~27 "tests: check tracing of looping threads"
Patch25: 0025-tests-check-tracing-of-looping-threads.patch
## Implementation of tcp queueing
## Addresses https://bugzilla.redhat.com/1609318 ("Some threads are not created
## when strace with -f option is executed") and all previous its incarnations
## (478419, 526740, 851457, 1610774).
# v5.0~26 "Add a generic list implementation"
Patch26: 0026-Add-a-generic-list-implementation.patch
# v5.0~25 "Implement queueing of threads before dispatching them"
Patch27: 0027-Implement-queueing-of-threads-before-dispatching-the.patch
## Pre-requisites for "evdev: fix array size calculation in decode_bitset_"
# v4.25~30 "macros: add ROUNDUP macro"
Patch28: 0028-macros-add-ROUNDUP-macro.patch
# v5.0~45 "util: update dumpstr" (only macros.h change)
Patch29: 0029-util-update-dumpstr.patch
BuildRequires: libselinux-devel
## Reported by covscan
# v5.2-3-g7ada13f "evdev: avoid bit vector decoding on non-successful and 0 return codes"
Patch30: 0030-evdev-avoid-bit-vector-decoding-on-non-successful-an.patch
# v5.2-4-g96194ed "evdev: fix array size calculation in decode_bitset_"
Patch31: 0031-evdev-fix-array-size-calculation-in-decode_bitset_.patch
## v5.2-3-g7ada13f "evdev: avoid bit vector decoding on non-successful and 0 return codes"
#Patch30: 0030-evdev-avoid-bit-vector-decoding-on-non-successful-an.patch
## v5.2-4-g96194ed "evdev: fix array size calculation in decode_bitset_"
#Patch31: 0031-evdev-fix-array-size-calculation-in-decode_bitset_.patch
## Pre-requisite for "tests: test evdev bitset decoding more thoroughly"
# v4.25~89 "tests: check decoding of successful evdev ioctl"
Patch32: 0032-tests-check-decoding-of-successful-evdev-ioctl.patch
### Pre-requisite for "tests: test evdev bitset decoding more thoroughly"
## v4.25~89 "tests: check decoding of successful evdev ioctl"
#Patch32: 0032-tests-check-decoding-of-successful-evdev-ioctl.patch
## Test for patches "evdev: avoid bit vector decoding on non-successful and 0
## return codes" and "evdev: fix array size calculation in decode_bitset_"
# v5.2-5-gcdd8206 "tests: test evdev bitset decoding more thoroughly"
Patch33: 0033-tests-test-evdev-bitset-decoding-more-thoroughly.patch
## v5.2-5-gcdd8206 "tests: test evdev bitset decoding more thoroughly"
#Patch33: 0033-tests-test-evdev-bitset-decoding-more-thoroughly.patch
## https://bugzilla.redhat.com/1747475 https://bugzilla.redhat.com/1747514
# v4.26~65 "s390x: beautify sthyi data tail prints"
Patch34: 0034-s390x-beautify-sthyi-data-tail-prints.patch
### https://bugzilla.redhat.com/1747475 https://bugzilla.redhat.com/1747514
## v4.26~65 "s390x: beautify sthyi data tail prints"
#Patch34: 0034-s390x-beautify-sthyi-data-tail-prints.patch
## Reported by covscan (https://bugzilla.redhat.com/1747524
## https://bugzilla.redhat.com/1747526 https://bugzilla.redhat.com/1747530)
# v5.2-84-g91281fec "v4l2: avoid shifting left a signed number by 31 bit"
Patch35: 0035-v4l2-avoid-shifting-left-a-signed-number-by-31-bit.patch
# v5.2~21 "syscall.c: avoid infinite loop in subcalls parsing"
Patch36: 0036-syscall.c-avoid-infinite-loop-in-subcalls-parsing.patch
# v5.2~19 "kvm: avoid bogus vcpu_info assignment in vcpu_register"
Patch37: 0037-kvm-avoid-bogus-vcpu_info-assignment-in-vcpu_registe.patch
# v5.4~97 "xlat: use unsgined type for mount_flags fallback values"
Patch38: 0038-xlat-use-unsgined-type-for-mount_flags-fallback-valu.patch
## v5.2-84-g91281fec "v4l2: avoid shifting left a signed number by 31 bit"
#Patch35: 0035-v4l2-avoid-shifting-left-a-signed-number-by-31-bit.patch
## v5.2~21 "syscall.c: avoid infinite loop in subcalls parsing"
#Patch36: 0036-syscall.c-avoid-infinite-loop-in-subcalls-parsing.patch
## v5.2~19 "kvm: avoid bogus vcpu_info assignment in vcpu_register"
#Patch37: 0037-kvm-avoid-bogus-vcpu_info-assignment-in-vcpu_registe.patch
## v5.4~97 "xlat: use unsgined type for mount_flags fallback values"
#Patch38: 0038-xlat-use-unsgined-type-for-mount_flags-fallback-valu.patch
## Wire up rseq and kexec_file_load in order to avoid kexec_file_load
## test failure on aarch64. Addresses https://bugzilla.redhat.com/1676045
## ("strace: FTBFS in Fedora rawhide/f30").
# v5.0~62 "Wire up rseq syscall on architectures that use generic unistd.h"
Patch100: 0100-Wire-up-rseq-syscall-on-architectures-that-use-gener.patch
# v5.0~61 "Wire up kexec_file_load syscall on architectures that use generic unistd.h"
Patch101: 0101-Wire-up-kexec_file_load-syscall-on-architectures-tha.patch
## Missing stack traces on attach (https://bugzilla.redhat.com/1788636)
## RHEL 7: https://bugzilla.redhat.com/1790052
## RHEL 8: https://bugzilla.redhat.com/1790053
## RHEL 6 DTS: https://bugzilla.redhat.com/1790058
## RHEL 7 DTS: https://bugzilla.redhat.com/1790057
## RHEL 8 DTS: https://bugzilla.redhat.com/1790054
## v5.4-18-g69b2c33 "unwind-libdw: fix initialization of libdwfl cache"
#Patch39: 0039-unwind-libdw-fix-initialization-of-libdwfl-cache.patch
## v5.4-27-g35e080a "syscall: do not capture stack trace while the tracee executes strace code"
#Patch40: 0040-syscall-do-not-capture-stack-trace-while-the-tracee-.patch
## v5.4-63-g8e515c7 "tests: add strace-k-p test"
#Patch41: 0041-tests-add-strace-k-p-test.patch
## https://bugzilla.redhat.com/1746885
## v5.2-92-gc108f0b "sockaddr: properly decode sockaddr_hci addresses without hci_channel"
#Patch42: 0042-sockaddr-properly-decode-sockaddr_hci-addresses-with.patch
## Some ipc tests from strace internal testsuite occasionally fail
## https://bugzilla.redhat.com/1795251 https://bugzilla.redhat.com/1795261
## https://bugzilla.redhat.com/1794490 https://bugzilla.redhat.com/1795273
## v5.3~102 "tests: fix expected output for some ipc tests"
#Patch43: 0043-tests-fix-expected-output-for-some-ipc-tests.patch
## v5.4~49 "tests: fix -a argument in ipc_msgbuf-Xraw test"
#Patch44: 0044-tests-fix-a-argument-in-ipc_msgbuf-Xraw-test.patch
### Update bpf decoder, as bpf-obj_get_info_by_fd-prog-v.gen.test has started
### to fail after BPF rebase in RHEL 8.2 kernel.
## v5.0~98 "Fix preprocessor indentation", only the bpf_attr.h chunks
#Patch45: 0045-Fix-preprocessor-indentation.patch
## v5.0~24 "bpf: exclude bit fields from the check"
#Patch46: 0046-bpf-exclude-bit-fields-from-the-check.patch
## v5.0~23 "bpf: print struct bpf_prog_info.gpl_compatible"
#Patch47: 0047-bpf-print-struct-bpf_prog_info.gpl_compatible.patch
## v5.0~22 "bpf: add support for btf_* fields in BPF_MAP_CREATE"
#Patch48: 0048-bpf-add-support-for-btf_-fields-in-BPF_MAP_CREATE.patch
## v5.0~21 "bpf: add support for btf_* fields in struct bpf_map_info"
#Patch49: 0049-bpf-add-support-for-btf_-fields-in-struct-bpf_map_in.patch
## v5.0~20 "bpf: add support for *jited_ksyms and *jited_func_lens fields in struct bpf_prog_info"
#Patch50: 0050-bpf-add-support-for-jited_ksyms-and-jited_func_lens-.patch
## v5.0~19 "bpf: add support for new twelve fields in struct bpf_prog_info"
#Patch51: 0051-bpf-add-support-for-new-twelve-fields-in-struct-bpf_.patch
## v5.1~6 "tests: robustify bpf-obj_get_info_by_fd test against future kernels"
#Patch52: 0052-tests-robustify-bpf-obj_get_info_by_fd-test-against-.patch
## Patches 53-86 were on DTS 9 for
## "some devtoolset-9-strace internal tests fail on rhel-alt-7.6"
## https://bugzilla.redhat.com/1758201
## Update io_uring(2) decoder (https://bugzilla.redhat.com/1853011)
## v5.5~65 "io_uring: do not depend on kernel header definitions"
#Patch87: 0087-io_uring-do-not-depend-on-kernel-header-definitions.patch
## v5.5~64 "io_uring: de-indent the switch case statements"
#Patch88: 0088-io_uring-de-indent-the-switch-case-statements.patch
## v5.3~15 "Add support for printing local arrays to print_array"
#Patch89: 0089-Add-support-for-printing-local-arrays-to-print_array.patch
## v5.5~63 "Rework interface for printing local arrays"
#Patch90: 0090-Rework-interface-for-printing-local-arrays.patch
## v5.5~62 "io_uring: decode io_uring_params.resv with IS_ARRAY_ZERO and PRINT_FIELD_ARRAY"
#Patch91: 0091-io_uring-decode-io_uring_params.resv-with-IS_ARRAY_Z.patch
## v5.5~61 "io_uring: print io_sqring_offsets and io_cqring_offsets reserved fields"
#Patch92: 0092-io_uring-print-io_sqring_offsets-and-io_cqring_offse.patch
## v5.5~60 "io_uring: add support for IORING_REGISTER_EVENTFD and IORING_UNREGISTER_EVENTFD"
#Patch93: 0093-io_uring-add-support-for-IORING_REGISTER_EVENTFD-and.patch
## v5.5~59 "io_uring: implement decoding of struct io_uring_params.features"
#Patch94: 0094-io_uring-implement-decoding-of-struct-io_uring_param.patch
## v5.5~58 "xlat: add IORING_SETUP_CQSIZE to uring_setup_flags"
#Patch95: 0095-xlat-add-IORING_SETUP_CQSIZE-to-uring_setup_flags.patch
## v5.5~42 "io_uring: check struct io_* types automatically"
#Patch96: 0096-io_uring-check-struct-io_-types-automatically.patch
## v5.5~41 "io_uring: add support for IORING_REGISTER_FILES_UPDATE"
#Patch97: 0097-io_uring-add-support-for-IORING_REGISTER_FILES_UPDAT.patch
## v5.5~27 "xlat: update uring_setup_features constants"
#Patch98: 0098-xlat-update-uring_setup_features-constants.patch
## v5.5~26 "xlat: add IORING_SETUP_CLAMP to uring_setup_flags"
#Patch99: 0099-xlat-add-IORING_SETUP_CLAMP-to-uring_setup_flags.patch
## v5.5~25 "io_uring: add support of wq_fd field decoding to io_uring_setup"
#Patch100: 0100-io_uring-add-support-of-wq_fd-field-decoding-to-io_u.patch
## v5.6~190 "tests/io_uring_register: properly handle big endian architectures"
#Patch101: 0101-tests-io_uring_register-properly-handle-big-endian-a.patch
## v5.6~157 "io_uring: decode IORING_REGISTER_EVENTFD_ASYNC io_uring_reginster command"
#Patch102: 0102-io_uring-decode-IORING_REGISTER_EVENTFD_ASYNC-io_uri.patch
## v5.6~95 "io_uring: de-indent some code in io_uring_setup decoder"
#Patch103: 0103-io_uring-de-indent-some-code-in-io_uring_setup-decod.patch
## v5.3~29 "defs.h: introduce {opt,dispatch}_{word,klong}size"
#Patch104: 0104-defs.h-introduce-opt-dispatch-_-word-klong-size.patch
## v5.3~9 "Handle xlat verbosity in evdev bitset printing"
#Patch105: 0105-Handle-xlat-verbosity-in-evdev-bitset-printing.patch
## v5.6~94 "io_uring: support IORING_REGISTER_PROBE io_uring_register command"
#Patch106: 0106-io_uring-support-IORING_REGISTER_PROBE-io_uring_regi.patch
## v5.6~93 "io_uring: add support for IORING_{UN,}REGISTER_PERSONALITY commands"
#Patch107: 0107-io_uring-add-support-for-IORING_-UN-REGISTER_PERSONA.patch
## v5.6~17 "tests: fix clang compilation warning"
#Patch108: 0108-tests-fix-clang-compilation-warning.patch
## v5.6~10 "tests: workaround clang compilation warning"
#Patch109: 0109-tests-workaround-clang-compilation-warning.patch
## v5.7~87 "xlat: add IORING_FEAT_FAST_POLL to uring_setup_features"
#Patch110: 0110-xlat-add-IORING_FEAT_FAST_POLL-to-uring_setup_featur.patch
## v5.7~85 "xlat: update uring_ops"
#Patch111: 0111-xlat-update-uring_ops.patch
## v5.7~68 "tests: correct error message in io_uring_register test"
#Patch112: 0112-tests-correct-error-message-in-io_uring_register-tes.patch
## v5.8~58 "io_uring: Remove struct io_cqring_offsets compile time asserts"
#Patch113: 0113-io_uring-Remove-struct-io_cqring_offsets-compile-tim.patch
## v5.8~57 "io_uring: Add io_cqring_offset flags"
#Patch114: 0114-io_uring-Add-io_cqring_offset-flags.patch
## v5.8~47 "xlat: update IORING_* constants"
#Patch115: 0115-xlat-update-IORING_-constants.patch
## v5.5~71 "macros.h: introduce sizeof_field macro"
#Patch116: 0116-macros.h-introduce-sizeof_field-macro.patch
## v5.5~49 "types: new infrastructure for automatic checking of structure types"
#Patch117: 0117-types-new-infrastructure-for-automatic-checking-of-s.patch
## v5.8~59 "types: skip field lines that start with comments"
#Patch118: 0118-types-skip-field-lines-that-start-with-comments.patch
## PID namespace translation support
## https://bugzilla.redhat.com/1035434
## https://bugzilla.redhat.com/1725113 https://bugzilla.redhat.com/1790836
## https://bugzilla.redhat.com/1804334 https://bugzilla.redhat.com/1807458
# v5.8~62 "print_fields.h: add PRINT_FIELD_LEN macro"
#Patch119: 0119-print_fields.h-add-PRINT_FIELD_LEN-macro.patch
## v5.8~61 "Move ilog* functions from util.c to defs.h"
#Patch120: 0120-Move-ilog-functions-from-util.c-to-defs.h.patch
## v5.8~59 "types: skip field lines that start with comments"
#Patch121: 0121-types-skip-field-lines-that-start-with-comments.patch
## v5.8~54 "tests/inject-nf.test: replace getpid with geteuid"
#Patch122: 0122-tests-inject-nf.test-replace-getpid-with-geteuid.patch
## v5.8~18 "fcntl: use print_fields.h macros"
#Patch123: 0123-fcntl-use-print_fields.h-macros.patch
## v5.8~17 "kcmp: fix KCMP_FILE decoding"
#Patch124: 0124-kcmp-fix-KCMP_FILE-decoding.patch
## v5.8~15 "printsiginfo: fix printing of siginfo_t.si_pid and siginfo_t.si_uid"
#Patch125: 0125-printsiginfo-fix-printing-of-siginfo_t.si_pid-and-si.patch
## v5.8~14 "Use PRINT_FIELD_UID instead of printuid where appropriate"
#Patch126: 0126-Use-PRINT_FIELD_UID-instead-of-printuid-where-approp.patch
## v5.8~10 "Consistently print process ids as signed integers"
#Patch127: 0127-Consistently-print-process-ids-as-signed-integers.patch
## v5.8~9 "Remove tcb parameter of read_int_from_file"
#Patch128: 0128-Remove-tcb-parameter-of-read_int_from_file.patch
## v5.8~6 "Add "struct tcb *" parameters to various functions"
#Patch129: 0129-Add-struct-tcb-parameters-to-various-functions.patch
## v5.8~53 "Modify %process class: trace syscalls associated with process lifecycle"
#Patch130: 0130-Modify-process-class-trace-syscalls-associated-with-.patch
## v5.8~5 "Introduce SYS_FUNC(tkill)"
#Patch131: 0131-Introduce-SYS_FUNC-tkill.patch
## v5.8~4 "tests: check decoding of tkill syscall"
#Patch132: 0132-tests-check-decoding-of-tkill-syscall.patch
## v5.8~3 "tests: check decoding of tgkill syscall"
#Patch133: 0133-tests-check-decoding-of-tgkill-syscall.patch
## v5.8-5-gdea0284 "PID namespace translation support"
#Patch134: 0134-PID-namespace-translation-support.patch
## v5.8-6-g173257d "Use printpid in decoders"
#Patch135: 0135-Use-printpid-in-decoders.patch
## v5.8-7-g18c2208 "Use get_proc_pid for /proc paths"
#Patch136: 0136-Use-get_proc_pid-for-proc-paths.patch
## v5.8-8-g7ecee07 "Implement testing framework for pidns"
#Patch137: 0137-Implement-testing-framework-for-pidns.patch
## v5.8-9-gf350ce0 "Add tests for PID namespace translation"
#Patch138: 0138-Add-tests-for-PID-namespace-translation.patch
## v5.12~55 "tests: add fchmod-y test"
#Patch142: 0142-tests-add-fchmod-y-test.patch
## v5.12~54 "tests: introduce create_and_enter_subdir and leave_and_remove_subdir"
#Patch143: 0143-tests-introduce-create_and_enter_subdir-and-leave_an.patch
## v5.8~36 "tests: check decoding of faccessat syscall in -P, -y, and -yy modes"
#Patch144: 0144-tests-check-decoding-of-faccessat-syscall-in-P-y-and.patch
## v5.12~97 "xmalloc: introduce xasprintf"
#Patch145: 0145-xmalloc-introduce-xasprintf.patch
## v5.12~96 "tests: use xasprintf instead of asprintf"
#Patch146: 0146-tests-use-xasprintf-instead-of-asprintf.patch
## v5.12~156 "file_handle: print f_handle as a hexadecimal string"
#Patch147: 0147-file_handle-print-f_handle-as-a-hexadecimal-string.patch
## v5.10~47 "tests: fix execve test with fresh linux kernels"
#Patch148: 0148-tests-fix-execve-test-with-fresh-linux-kernels.patch
## v5.12~49 "Implement --secontext[=full] option to display SELinux contexts"
#Patch149: 0149-Implement-secontext-full-option-to-display-SELinux-c.patch
# v5.13-14-g9623154 "m4/mpers.m4: generate HAVE_*_SELINUX_RUNTIME config defines"
#Patch155: 0155-m4-mpers.m4-generate-HAVE_-_SELINUX_RUNTIME-config-d.patch
## v5.9~28 "Introduce GLIBC_PREREQ_GE and GLIBC_PREREQ_LT macros"
#Patch156: 0156-Introduce-GLIBC_PREREQ_GE-and-GLIBC_PREREQ_LT-macros.patch
## v5.9~27 "tests/ipc_msg.c: disable TEST_MSGCTL_BOGUS_ADDR on glibc >= 2.32"
#Patch157: 0157-tests-ipc_msg.c-disable-TEST_MSGCTL_BOGUS_ADDR-on-gl.patch
## v5.10~46 "tests: disable TEST_MSGCTL_BOGUS_ADDR in ipc_msg test on glibc >= 2.31"
#Patch158: 0158-tests-disable-TEST_MSGCTL_BOGUS_ADDR-in-ipc_msg-test.patch
## v5.10~22 "tests: disable tests for invalid msgctl commands on glibc >= 2.32"
#Patch159: 0159-tests-disable-tests-for-invalid-msgctl-commands-on-g.patch
## v5.9~11 "tests: disable shmctl IPC_STAT test with a bogus address on glibc >= 2.32"
#Patch160: 0160-tests-disable-shmctl-IPC_STAT-test-with-a-bogus-addr.patch
## v5.9~10 "tests: disable tests for invalid shmctl commands on glibc >= 2.32"
#Patch161: 0161-tests-disable-tests-for-invalid-shmctl-commands-on-g.patch
## v5.9~12 "tests: disable tests for invalid semctl commands on glibc >= 2.32"
#Patch162: 0162-tests-disable-tests-for-invalid-semctl-commands-on-g.patch
## v5.13-55-g6b2191f "filter_qualify: free allocated data on the error path exit of parse_poke_token"
#Patch163: 0163-filter_qualify-free-allocated-data-on-the-error-path.patch
## v5.13-56-g80dc60c "macros: expand BIT macros, add MASK macros; add *_SAFE macros"
#Patch164: 0164-macros-expand-BIT-macros-add-MASK-macros-add-_SAFE-m.patch
## v5.13-58-g94ae5c2 "trie: use BIT* and MASK* macros"
#Patch165: 0165-trie-use-BIT-and-MASK-macros.patch
## v5.13-65-g41b753e "tee: rewrite num_params access in tee_fetch_buf_data"
#Patch166: 0166-tee-rewrite-num_params-access-in-tee_fetch_buf_data.patch
## v5.15~1 "print_ifindex: fix IFNAME_QUOTED_SZ definition"
#Patch167: 0167-print_ifindex-fix-IFNAME_QUOTED_SZ-definition.patch
## v5.15~18 "m4: fix st_SELINUX check"
#Patch168: 0168-m4-fix-st_SELINUX-check.patch
## v5.16~31 "Implement displaying of expected context upon mismatch"
#Patch169: 0169-Implement-displaying-of-expected-context-upon-mismat.patch
#Patch170: 0170-tests-linkat-reset-errno-before-SELinux-context-mani.patch
#Patch171: 0171-tests-secontext-add-secontext-field-getters.patch
#Patch172: 0172-tests-linkat-provide-fallback-values-for-secontext-f.patch
#Patch173: 0173-tests-secontext-eliminate-separate-secontext_format-.patch
#Patch174: 0174-tests-linkat-reset-context-to-the-expected-one-if-a-.patch
## https://bugzilla.redhat.com/2103068 covscan fixes
# v5.18-5-g2bf0696 "src/xlat: remove remnants of unnecessary idx usage in xlookup"
Patch175: 0175-src-xlat-remove-remnants-of-unnecessary-idx-usage-in.patch
# v5.18-7-ge604d7b "strauss: tips whitespace and phrasing cleanups"
Patch176: 0176-strauss-tips-whitespace-and-phrasing-cleanups.patch
# v5.18-8-g968789d "strauss: fix off-by-one error in strauss array access"
Patch177: 0177-strauss-fix-off-by-one-error-in-strauss-array-access.patch
# v5.18-9-g6d3e97e "util: add offs sanity check to print_clock_t"
Patch178: 0178-util-add-offs-sanity-check-to-print_clock_t.patch
## https://bugzilla.redhat.com/2087693
# v5.18-13-g960e78f "secontext: print context of Unix socket's sun_path field"
Patch179: 0179-secontext-print-context-of-Unix-socket-s-sun_path-fi.patch
# v5.18-18-g676979f "pathtrace, util: do not print " (deleted)" as part of the path"
Patch180: 0180-pathtrace-util-do-not-print-deleted-as-part-of-the-p.patch
# v5.18-19-g3f0e534 "secontext: fix expected SELinux context check for unlinked FDs"
Patch181: 0181-secontext-fix-expected-SELinux-context-check-for-unl.patch
## https://bugzilla.redhat.com/2103137
# v5.18-21-g5338636 "tests/bpf: fix sloppy low FD number usage"
Patch182: 0182-tests-bpf-fix-sloppy-low-FD-number-usage.patch
### Wire up rseq and kexec_file_load in order to avoid kexec_file_load
### test failure on aarch64. Addresses https://bugzilla.redhat.com/1676045
### ("strace: FTBFS in Fedora rawhide/f30").
## v5.0~62 "Wire up rseq syscall on architectures that use generic unistd.h"
#Patch1000: 1000-Wire-up-rseq-syscall-on-architectures-that-use-gener.patch
## v5.0~61 "Wire up kexec_file_load syscall on architectures that use generic unistd.h"
#Patch1001: 1001-Wire-up-kexec_file_load-syscall-on-architectures-tha.patch
### RHEL7-only: headers on some builders do not provide O_TMPFILE
#Patch200: 0200-strace-provide-O_TMPFILE-fallback-definition.patch
#Patch2000: 2000-strace-provide-O_TMPFILE-fallback-definition.patch
## RHEL-only: aarch64 brew builders are extremely slow on qual_fault.test
Patch201: 0201-limit-qual_fault-scope-on-aarch64.patch
## RHEL8.2-only: disable ksysent test due to missing rebase
Patch202: 0202-disable-ksysent-on-8.2.patch
Patch2001: 2001-limit-qual_fault-scope-on-aarch64.patch
### RHEL8.2-only: disable ksysent test due to missing rebase
#Patch2002: 2002-disable-ksysent-on-8.2.patch
### RHEL-only: avoid ARRAY_SIZE macro re-definition in libiberty.h
## No longer needed, since upstream commit v5.14~14
#Patch2003: 2003-undef-ARRAY_SIZE.patch
### RHEL-only: glibc-2.32.9000-147-ga16d2abd496bd974a882,
### glibc-2.32.9000-149-gbe9b0b9a012780a403a2 and
### glibc-2.32.9000-207-g9ebaabeaac1a96b0d91f have been backported in RHEL.
## No longer needed, since upstream commit v5.15~9
#Patch2004: 2004-glibc-msgctl-semctl-shmctl-backport-workaround.patch
# We no longer need to build a separate strace32 binary, but we don't want
# to break existing strace32 users' workflows.
@ -152,9 +312,16 @@ Patch202: 0202-disable-ksysent-on-8.2.patch
%define _isa_compat %{?__isa_name:(%{__isa_name}-32)}%{!?__isa:%{nil}}
%define evr %{?epoch:%{epoch}:}%{version}-%{release}
Provides: strace32 = %{evr}
Obsoletes: strace32 < %{version} strace32%{_isa_compat} < %{version}
# strace32 was a real package before strace-4.24 in RHEL
Obsoletes: strace32 < 4.24
%endif
# Fallback definitions for make_build/make_install macros
%{?!__make: %global __make %_bindir/make}
%{?!__install: %global __install %_bindir/install}
%{?!make_build: %global make_build %__make %{?_smp_mflags}}
%{?!make_install: %global make_install %__make install DESTDIR="%{?buildroot}" INSTALL="%__install -p"}
%description
The strace program intercepts and records the system calls called and
received by a running process. Strace can print a record of each
@ -168,56 +335,134 @@ received by a process.
%prep
%setup -q
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
%patch6 -p1
%patch7 -p1
%patch8 -p1
%patch9 -p1
%patch10 -p1
%patch11 -p1
%patch12 -p1
%patch13 -p1
%patch14 -p1
%patch15 -p1
%patch16 -p1
%patch17 -p1
%patch18 -p1
%patch19 -p1
%patch20 -p1
%patch21 -p1
%patch22 -p1
%patch23 -p1
%patch24 -p1
%patch25 -p1
%patch26 -p1
%patch27 -p1
%patch28 -p1
%patch29 -p1
%patch30 -p1
%patch31 -p1
%patch32 -p1
%patch33 -p1
%patch34 -p1
%patch35 -p1
%patch36 -p1
%patch37 -p1
%patch38 -p1
#%patch30 -p1
#%patch31 -p1
#%patch32 -p1
#%patch33 -p1
#%patch34 -p1
#%patch35 -p1
#%patch36 -p1
#%patch37 -p1
#%patch38 -p1
#%patch39 -p1
#%patch40 -p1
#%patch41 -p1
#%patch42 -p1
#%patch43 -p1
#%patch44 -p1
#%patch45 -p1
#%patch46 -p1
#%patch47 -p1
#%patch48 -p1
#%patch49 -p1
#%patch50 -p1
#%patch51 -p1
#%patch52 -p1
#%patch87 -p1
#%patch88 -p1
#%patch89 -p1
#%patch90 -p1
#%patch91 -p1
#%patch92 -p1
#%patch93 -p1
#%patch94 -p1
#%patch95 -p1
#%patch96 -p1
#%patch97 -p1
#%patch98 -p1
#%patch99 -p1
#%patch100 -p1
#%patch101 -p1
#%patch102 -p1
#%patch103 -p1
#%patch104 -p1
#%patch105 -p1
#%patch106 -p1
#%patch107 -p1
#%patch108 -p1
#%patch109 -p1
#%patch110 -p1
#%patch111 -p1
#%patch112 -p1
#%patch113 -p1
#%patch114 -p1
#%patch115 -p1
#%patch116 -p1
#%patch117 -p1
#%patch118 -p1
#%patch119 -p1
#%patch120 -p1
#%patch121 -p1
#%patch122 -p1
#%patch123 -p1
#%patch124 -p1
#%patch125 -p1
#%patch126 -p1
#%patch127 -p1
#%patch128 -p1
#%patch129 -p1
#%patch130 -p1
#%patch131 -p1
#%patch132 -p1
#%patch133 -p1
#%patch134 -p1
#%patch135 -p1
#%patch136 -p1
#%patch137 -p1
#%patch138 -p1
#%patch142 -p1
#%patch143 -p1
#%patch144 -p1
#%patch145 -p1
#%patch146 -p1
#%patch147 -p1
#%patch148 -p1
#%patch149 -p1
#%patch155 -p1
#%patch156 -p1
#%patch157 -p1
#%patch158 -p1
#%patch159 -p1
#%patch160 -p1
#%patch161 -p1
#%patch162 -p1
#%patch163 -p1
#%patch164 -p1
#%patch165 -p1
#%patch166 -p1
#%patch167 -p1
#%patch168 -p1
#%patch169 -p1
#%patch170 -p1
#%patch171 -p1
#%patch172 -p1
#%patch173 -p1
#%patch174 -p1
%patch100 -p1
%patch101 -p1
%patch175 -p1
%patch176 -p1
%patch177 -p1
%patch178 -p1
%patch179 -p1
%patch180 -p1
%patch181 -p1
%patch182 -p1
#%patch200 -p1
%patch201 -p1
%patch202 -p1
#%patch1000 -p1
#%patch1001 -p1
#%patch2000 -p1
%patch2001 -p1
#%patch2002 -p1
#%patch2003 -p1
#%patch2004 -p1
chmod a+x tests/*.test
echo -n %version-%release > .tarball-version
echo -n 2019 > .year
echo -n 2019-12-02 > .strace.1.in.date
echo -n 2022 > .year
echo -n 2022-06-22 > doc/.strace.1.in.date
echo -n 2022-06-22 > doc/.strace-log-merge.1.in.date
%build
echo 'BEGIN OF BUILD ENVIRONMENT INFORMATION'
@ -236,20 +481,18 @@ CFLAGS=" $RPM_OPT_FLAGS $LDFLAGS "
[ "x${CFLAGS#* -m64 }" = "x${CFLAGS}" ] || CFLAGS=$(echo "$CFLAGS" | sed 's/ -m64 / /g')
export CFLAGS
CPPFLAGS=" -I%{_includedir} %{optflags} "
CPPFLAGS=" -isystem %{_includedir} %{optflags} "
# Removing explicit -m64 as it breaks mpers
[ "x${CPPFLAGS#* -m64 }" = "x${CPPFLAGS}" ] || CPPFLAGS=$(echo "$CPPFLAGS" | sed 's/ -m64 / /g')
export CPPFLAGS
CFLAGS_FOR_BUILD="$RPM_OPT_FLAGS"; export CFLAGS_FOR_BUILD
# Commit v4.26-50-gb1a2db9 is needed for enforcing libiberty usage with
# --with-libiberty
%configure --enable-mpers=check --with-libdw
make %{?_smp_mflags}
%configure --enable-mpers=check --with-libdw --with-libiberty
%make_build
%install
make DESTDIR=%{buildroot} install
%make_install
%ifarch %{strace32_arches}
ln -s ./strace %{buildroot}%{_bindir}/strace32
@ -266,20 +509,15 @@ wait
%check
# This is needed since patch does not set x bit to the newly created files
# (0022-tests-add-kill_child-test.patch,
# 0024-tests-check-tracing-of-orphaned-process-group.patch,
# 0025-tests-check-tracing-of-looping-threads.patch,
# 0032-tests-check-decoding-of-successful-evdev-ioctl.patch)
chmod u+x tests/*.test tests-m32/*.test tests-mx32/*.test
%{buildroot}%{_bindir}/strace -V
# We have to limit concurrent execution of tests as some time-sensitive tests
# start to fail if the reported time is way too off from the expected one.
make -j2 -k check VERBOSE=1 V=1 TIMEOUT_DURATION=5400
%make_build -k check VERBOSE=1 V=1
echo 'BEGIN OF TEST SUITE INFORMATION'
tail -n 99999 -- tests*/test-suite.log
tail -n 99999 -- tests*/ksysent.log ||:
tail -n 99999 -- tests*/test-suite.log tests*/ksysent.gen.log
find tests* -type f -name '*.log' -print0 |
xargs -r0 grep -H '^KERNEL BUG:' -- ||:
echo 'END OF TEST SUITE INFORMATION'
@ -295,6 +533,74 @@ echo 'END OF TEST SUITE INFORMATION'
%{_mandir}/man1/*
%changelog
* Mon Jul 11 2022 Eugene Syromiatnikov <esyr@redhat.com> - 5.18-2
- Fix the issues reported by covscan (#2103068).
- Fix SELinux context matching for the deleted paths (#2087693).
- Fix sloppy FD usage in the bpf test (#2103137).
* Wed Jun 22 2022 Eugene Syromiatnikov <esyr@redhat.com> - 5.18-1
- Rebase to v5.18; drop upstream patches on top of 5.13 (#2084000).
* Mon Feb 07 2022 Eugene Syromiatnikov <esyr@redhat.com> - 5.13-4
- Update tests-m32 and tests-mx32 with --secontext=mismatch option support
changes (#2046259).
* Wed Jan 19 2022 Eugene Syromiatnikov <esyr@redhat.com> - 5.13-3
- Add --secontext=mismatch option support (#2038810).
* Wed Jan 05 2022 Eugene Syromiatnikov <esyr@redhat.com> - 5.13-2
- Fix incorrect ifname printing buffer size (#2028158).
* Wed Oct 20 2021 Eugene Syromiatnikov <esyr@redhat.com> - 5.13-1
- Rebase to v5.13; drop upstream patches on top of 5.7 (#2015917).
- Address some issues reported by covscan.
* Mon Aug 09 2021 Eugene Syromiatnikov <esyr@redhat.com> - 5.7-3
- Add SELnux context decoding support (#1946500).
* Mon Nov 09 2020 Eugene Syromiatnikov <esyr@redhat.com> - 5.7-2
- Add PID namespace translation support (#1725113).
* Mon Nov 09 2020 Eugene Syromiatnikov <esyr@redhat.com> - 5.7-1
- Rebase to v5.7; drop upstream patches on top of 5.1 (#1873229).
* Mon Aug 24 2020 Eugene Syromiatnikov <esyr@redhat.com> - 5.1-2
- Update io_uring(2) decoder (#1853011).
- Fix "Obsoletes:" tag on s390x (#1852960).
* Thu Jan 30 2020 Eugene Syromiatnikov <esyr@redhat.com> - 5.1-1
- Rebase to strace 5.1 (#1777847).
* Thu Jan 30 2020 Eugene Syromiatnikov <esyr@redhat.com> - 4.24-9
- Fix the "extra tokens at end of #ifdef directive" warning:
579f2702 "bpf: exclude bit fields from the check".
* Mon Jan 27 2020 Eugene Syromiatnikov <esyr@redhat.com> - 4.24-8
- Fix expected alignment for IPC tests (#1795251):
4377e3a1 "tests: fix expected output for some ipc tests", and
a75c7c4b "tests: fix -a argument in ipc_msgbuf-Xraw test".
- Update tests-m32/looping_threads.test and tests-mx32/looping_threads.test
in 0025-tests-check-tracing-of-looping-threads.patch.
- Update the bpf syscall decoder:
d6c71dd0 "Fix preprocessor indentation",
cabd6955 "bpf: print struct bpf_prog_info.gpl_compatible",
14a9b6ca "bpf: add support for btf_* fields in BPF_MAP_CREATE",
27bd13d3 "bpf: add support for btf_* fields in struct bpf_map_info",
d1f90bcd "bpf: add support for *jited_ksyms and *jited_func_lens fields
in struct bpf_prog_info", and
940fe50f "bpf: add support for new twelve fields in struct bpf_prog_info".
c661605b "tests: robustify bpf-obj_get_info_by_fd test against future kernels"
* Thu Jan 23 2020 Eugene Syromiatnikov <esyr@redhat.com> - 4.24-7
- Fix printing stack traces for early syscalls on process attach (#1790053):
69b2c33a "unwind-libdw: fix initialization of libdwfl cache" and
8e515c74 "tests: add strace-k-p test".
- Properly decode struct sockaddr_hci without hci_channel field.
- Update tests-m32/ioctl_evdev.c and tests-mx32/ioctl_evdev.c
in 0002-evdev-fix-decoding-of-EVIOCGBIT-0.patch.
- Update tests-m32/Makefile.in and tests-mx32/Makefile.in
in 0032-tests-check-decoding-of-successful-evdev-ioctl.patch.
* Mon Dec 02 2019 Eugene Syromiatnikov <esyr@redhat.com> - 4.24-6
- Pull upstream fix for ioctl evdev bitset decoding, fix the tests (#1747214).
- Include commit v4.26~65 "s390x: beautify sthyi data tail prints" (#1747514).