#define TCB_FILTERED 0x20 /* This system call has been filtered out */
#define TCB_TAMPERED 0x40 /* A syscall has been tampered with */
#define TCB_HIDE_LOG 0x80 /* We should hide everything (until execve) */
-#define TCB_SKIP_DETACH_ON_FIRST_EXEC 0x100 /* -b execve should skip detach on first execve */
-#define TCB_GRABBED 0x200 /* We grab the process and can catch it
+#define TCB_CHECK_EXEC_SYSCALL 0x100 /* Check whether this execve syscall succeeded */
+#define TCB_SKIP_DETACH_ON_FIRST_EXEC 0x200 /* -b execve should skip detach on first execve */
+#define TCB_GRABBED 0x400 /* We grab the process and can catch it
* in the middle of a syscall */
-#define TCB_RECOVERING 0x400 /* We try to recover after detecting incorrect
+#define TCB_RECOVERING 0x800 /* We try to recover after detecting incorrect
* syscall entering/exiting state */
-#define TCB_INJECT_DELAY_EXIT 0x800 /* Current syscall needs to be delayed
+#define TCB_INJECT_DELAY_EXIT 0x1000 /* Current syscall needs to be delayed
on exit */
-#define TCB_DELAYED 0x1000 /* Current syscall has been delayed */
-#define TCB_TAMPERED_NO_FAIL 0x2000 /* We tamper tcb with syscall
+#define TCB_DELAYED 0x2000 /* Current syscall has been delayed */
+#define TCB_TAMPERED_NO_FAIL 0x4000 /* We tamper tcb with syscall
that should not fail. */
/* qualifier flags */
#define inject(tcp) ((tcp)->qual_flg & QUAL_INJECT)
#define filtered(tcp) ((tcp)->flags & TCB_FILTERED)
#define hide_log(tcp) ((tcp)->flags & TCB_HIDE_LOG)
+#define check_exec_syscall(tcp) ((tcp)->flags & TCB_CHECK_EXEC_SYSCALL)
#define syscall_tampered(tcp) ((tcp)->flags & TCB_TAMPERED)
#define recovering(tcp) ((tcp)->flags & TCB_RECOVERING)
#define inject_delay_exit(tcp) ((tcp)->flags & TCB_INJECT_DELAY_EXIT)
return true;
case TE_STOP_BEFORE_EXECVE:
+ /* The syscall succeeded, clear the flag. */
+ current_tcp->flags &= ~TCB_CHECK_EXEC_SYSCALL;
/*
* Check that we are inside syscall now (next event after
* PTRACE_EVENT_EXEC should be for syscall exiting). If it is
* First exec* syscall makes the log visible.
*/
tcp->flags &= ~TCB_HIDE_LOG;
+ /*
+ * Check whether this exec* syscall succeeds.
+ */
+ tcp->flags |= TCB_CHECK_EXEC_SYSCALL;
break;
- default:
- tcp->flags |= TCB_FILTERED;
- return 0;
}
}
- if (!traced(tcp) || (tracing_paths && !pathtrace_match(tcp))) {
+ if (hide_log(tcp) || !traced(tcp) || (tracing_paths && !pathtrace_match(tcp))) {
tcp->flags |= TCB_FILTERED;
return 0;
}
if (filtered(tcp))
return 0;
+ if (check_exec_syscall(tcp)) {
+ /* The check failed, hide the log. */
+ tcp->flags |= TCB_HIDE_LOG;
+ }
+
#if SUPPORTED_PERSONALITIES > 1
update_personality(tcp, tcp->currpers);
#endif
filter-unavailable.test \
filtering_fd-syntax.test \
filtering_syscall-syntax.test \
+ first_exec_failure.test \
get_regs.test \
inject-nf.test \
interactive_block.test \
--- /dev/null
+#!/bin/sh
+#
+# Check error diagnostics when the first exec fails.
+#
+# Copyright (c) 2016-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.
+
+. "${srcdir=.}/init.sh"
+
+$STRACE / 2> "$LOG" &&
+ dump_log_and_fail_with \
+ "$STRACE / failed to handle the error properly"
+
+check_prog head
+check_prog tail
+
+head -n1 < "$LOG" > "$OUT"
+cat > "$EXP" <<__EOF__
+execve\("/", \["/"\], 0x[[:xdigit:]]+ /\* [[:digit:]]+ vars \*/\) += -1 EACCES \(Permission denied\)
+__EOF__
+match_grep "$OUT" "$EXP"
+
+tail -n +2 < "$LOG" > "$OUT"
+cat > "$EXP" <<__EOF__
+$STRACE_EXE: exec: Permission denied
++++ exited with 1 +++
+__EOF__
+match_diff "$OUT" "$EXP"