]> granicus.if.org Git - strace/blobdiff - syscall.c
Fix the length argument passed from print_iovec to decode_netlink
[strace] / syscall.c
index 6546d1a5c08e17cb5bccf1b200d08f6dedfe5326..3e91880c956fa1924689dec90b562fc61e2802bd 100644 (file)
--- a/syscall.c
+++ b/syscall.c
@@ -76,6 +76,7 @@
 #define TP TRACE_PROCESS
 #define TS TRACE_SIGNAL
 #define TM TRACE_MEMORY
+#define TSF TRACE_STATFS
 #define NF SYSCALL_NEVER_FAILS
 #define MA MAX_ARGS
 #define SI STACKTRACE_INVALIDATE_CACHE
@@ -111,6 +112,7 @@ static const struct_sysent sysent2[] = {
 #undef TP
 #undef TS
 #undef TM
+#undef TSF
 #undef NF
 #undef MA
 #undef SI
@@ -553,6 +555,7 @@ clear_regs(void)
        get_regs_error = -1;
 }
 
+static void get_regs(pid_t pid);
 static int get_syscall_args(struct tcb *);
 static int get_syscall_result(struct tcb *);
 static int arch_get_scno(struct tcb *tcp);
@@ -561,28 +564,28 @@ static void get_error(struct tcb *, const bool);
 static int arch_set_error(struct tcb *);
 static int arch_set_success(struct tcb *);
 
-struct fault_opts *fault_vec[SUPPORTED_PERSONALITIES];
+struct inject_opts *inject_vec[SUPPORTED_PERSONALITIES];
 
-static struct fault_opts *
-tcb_fault_opts(struct tcb *tcp)
+static struct inject_opts *
+tcb_inject_opts(struct tcb *tcp)
 {
-       return (scno_in_range(tcp->scno) && tcp->fault_vec[current_personality])
-              ? &tcp->fault_vec[current_personality][tcp->scno] : NULL;
+       return (scno_in_range(tcp->scno) && tcp->inject_vec[current_personality])
+              ? &tcp->inject_vec[current_personality][tcp->scno] : NULL;
 }
 
 
 static long
-inject_syscall_fault_entering(struct tcb *tcp, unsigned int *signo)
+tamper_with_syscall_entering(struct tcb *tcp, unsigned int *signo)
 {
-       if (!tcp->fault_vec[current_personality]) {
-               tcp->fault_vec[current_personality] =
-                       xcalloc(nsyscalls, sizeof(**fault_vec));
-               memcpy(tcp->fault_vec[current_personality],
-                      fault_vec[current_personality],
-                      nsyscalls * sizeof(**fault_vec));
+       if (!tcp->inject_vec[current_personality]) {
+               tcp->inject_vec[current_personality] =
+                       xcalloc(nsyscalls, sizeof(**inject_vec));
+               memcpy(tcp->inject_vec[current_personality],
+                      inject_vec[current_personality],
+                      nsyscalls * sizeof(**inject_vec));
        }
 
-       struct fault_opts *opts = tcb_fault_opts(tcp);
+       struct inject_opts *opts = tcb_inject_opts(tcp);
 
        if (!opts || opts->first == 0)
                return 0;
@@ -596,16 +599,16 @@ inject_syscall_fault_entering(struct tcb *tcp, unsigned int *signo)
 
        if (opts->signo > 0)
                *signo = opts->signo;
-       if (opts->rval != FAULT_OPTS_RVAL_DISABLE && !arch_set_scno(tcp, -1))
-               tcp->flags |= TCB_FAULT_INJ;
+       if (opts->rval != INJECT_OPTS_RVAL_DEFAULT && !arch_set_scno(tcp, -1))
+               tcp->flags |= TCB_TAMPERED;
 
        return 0;
 }
 
 static long
-update_syscall_fault_exiting(struct tcb *tcp)
+tamper_with_syscall_exiting(struct tcb *tcp)
 {
-       struct fault_opts *opts = tcb_fault_opts(tcp);
+       struct inject_opts *opts = tcb_inject_opts(tcp);
 
        if (!opts)
                return 0;
@@ -638,11 +641,11 @@ update_syscall_fault_exiting(struct tcb *tcp)
 static int
 trace_syscall_entering(struct tcb *tcp, unsigned int *sig)
 {
-       int res, scno_good;
-
-       scno_good = res = get_scno(tcp);
+       int res = get_scno(tcp);
        if (res == 0)
                return res;
+
+       int scno_good = res;
        if (res == 1)
                res = get_syscall_args(tcp);
 
@@ -678,7 +681,7 @@ trace_syscall_entering(struct tcb *tcp, unsigned int *sig)
 
        /* Restrain from fault injection while the trace executes strace code. */
        if (hide_log(tcp)) {
-               tcp->qual_flg &= ~QUAL_FAULT;
+               tcp->qual_flg &= ~QUAL_INJECT;
        }
 
        switch (tcp->s_ent->sen) {
@@ -706,8 +709,8 @@ trace_syscall_entering(struct tcb *tcp, unsigned int *sig)
                goto ret;
        }
 
-       if (tcp->qual_flg & QUAL_FAULT)
-               inject_syscall_fault_entering(tcp, sig);
+       if (tcp->qual_flg & QUAL_INJECT)
+               tamper_with_syscall_entering(tcp, sig);
 
        if (cflag == CFLAG_ONLY_STATS) {
                res = 0;
@@ -739,22 +742,18 @@ trace_syscall_entering(struct tcb *tcp, unsigned int *sig)
 }
 
 static bool
-syscall_fault_injected(struct tcb *tcp)
+syscall_tampered(struct tcb *tcp)
 {
-       return tcp->flags & TCB_FAULT_INJ;
+       return tcp->flags & TCB_TAMPERED;
 }
 
 static int
 trace_syscall_exiting(struct tcb *tcp)
 {
-       int sys_res;
        struct timeval tv;
-       int res;
-       unsigned long u_error;
-       const char *u_error_str;
 
        /* Measure the exit time as early as possible to avoid errors. */
-       if (Tflag || cflag)
+       if ((Tflag || cflag) && !(filtered(tcp) || hide_log(tcp)))
                gettimeofday(&tv, NULL);
 
 #ifdef USE_LIBUNWIND
@@ -764,15 +763,17 @@ trace_syscall_exiting(struct tcb *tcp)
        }
 #endif
 
+       if (filtered(tcp) || hide_log(tcp))
+               goto ret;
+
+       get_regs(tcp->pid);
 #if SUPPORTED_PERSONALITIES > 1
        update_personality(tcp, tcp->currpers);
 #endif
-       res = (get_regs_error ? -1 : get_syscall_result(tcp));
-       if (filtered(tcp) || hide_log(tcp))
-               goto ret;
+       int res = (get_regs_error ? -1 : get_syscall_result(tcp));
 
-       if (syserror(tcp) && syscall_fault_injected(tcp))
-               update_syscall_fault_exiting(tcp);
+       if (syserror(tcp) && syscall_tampered(tcp))
+               tamper_with_syscall_exiting(tcp);
 
        if (cflag) {
                count_syscall(tcp, &tv);
@@ -804,14 +805,14 @@ trace_syscall_exiting(struct tcb *tcp)
                tabto();
                tprints("= ? <unavailable>\n");
                line_ended();
-               tcp->flags &= ~(TCB_INSYSCALL | TCB_FAULT_INJ);
+               tcp->flags &= ~(TCB_INSYSCALL | TCB_TAMPERED);
                tcp->sys_func_rval = 0;
                free_tcb_priv_data(tcp);
                return res;
        }
        tcp->s_prev_ent = tcp->s_ent;
 
-       sys_res = 0;
+       int sys_res = 0;
        if (tcp->qual_flg & QUAL_RAW) {
                /* sys_res = printargs(tcp); - but it's nop on sysexit */
        } else {
@@ -833,7 +834,7 @@ trace_syscall_exiting(struct tcb *tcp)
 
        tprints(") ");
        tabto();
-       u_error = tcp->u_error;
+       unsigned long u_error = tcp->u_error;
 
        if (tcp->qual_flg & QUAL_RAW) {
                if (u_error) {
@@ -841,10 +842,12 @@ trace_syscall_exiting(struct tcb *tcp)
                } else {
                        tprintf("= %#" PRI_klx, tcp->u_rval);
                }
-               if (syscall_fault_injected(tcp))
+               if (syscall_tampered(tcp))
                        tprints(" (INJECTED)");
        }
        else if (!(sys_res & RVAL_NONE) && u_error) {
+               const char *u_error_str;
+
                switch (u_error) {
                /* Blocked signals do not interrupt any syscalls.
                 * In this case syscalls don't return ERESTARTfoo codes.
@@ -909,8 +912,8 @@ trace_syscall_exiting(struct tcb *tcp)
                                        u_error, strerror(u_error));
                        break;
                }
-               if (syscall_fault_injected(tcp))
-                       tprintf(" (INJECTED)");
+               if (syscall_tampered(tcp))
+                       tprints(" (INJECTED)");
                if ((sys_res & RVAL_STR) && tcp->auxstr)
                        tprintf(" (%s)", tcp->auxstr);
        }
@@ -963,7 +966,7 @@ trace_syscall_exiting(struct tcb *tcp)
                }
                if ((sys_res & RVAL_STR) && tcp->auxstr)
                        tprintf(" (%s)", tcp->auxstr);
-               if (syscall_fault_injected(tcp))
+               if (syscall_tampered(tcp))
                        tprints(" (INJECTED)");
        }
        if (Tflag) {
@@ -981,7 +984,7 @@ trace_syscall_exiting(struct tcb *tcp)
 #endif
 
  ret:
-       tcp->flags &= ~(TCB_INSYSCALL | TCB_FAULT_INJ);
+       tcp->flags &= ~(TCB_INSYSCALL | TCB_TAMPERED);
        tcp->sys_func_rval = 0;
        free_tcb_priv_data(tcp);
        return 0;
@@ -1061,6 +1064,7 @@ print_pc(struct tcb *tcp)
 #else
 # error Neither ARCH_PC_REG nor ARCH_PC_PEEK_ADDR is defined
 #endif
+       get_regs(tcp->pid);
        if (get_regs_error || ARCH_GET_PC)
                tprints(current_wordsize == 4 ? "[????????] "
                                              : "[????????????????] ");
@@ -1146,12 +1150,15 @@ ptrace_setregs(pid_t pid)
 
 #endif /* ARCH_REGS_FOR_GETREGSET || ARCH_REGS_FOR_GETREGS */
 
-void
+static void
 get_regs(pid_t pid)
 {
 #undef USE_GET_SYSCALL_RESULT_REGS
 #ifdef ptrace_getregset_or_getregs
 
+       if (get_regs_error != -1)
+               return;
+
 # ifdef HAVE_GETREGS_OLD
        /*
         * Try PTRACE_GETREGSET/PTRACE_GETREGS first,
@@ -1218,6 +1225,8 @@ free_sysent_buf(void *ptr)
 int
 get_scno(struct tcb *tcp)
 {
+       get_regs(tcp->pid);
+
        if (get_regs_error)
                return -1;