]> granicus.if.org Git - strace/commitdiff
Prepare for introduction of -e inject= option
authorDmitry V. Levin <ldv@altlinux.org>
Wed, 8 Feb 2017 09:28:07 +0000 (09:28 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 8 Feb 2017 09:28:07 +0000 (09:28 +0000)
As -e fault= injection syntax has been extended to configure various
kinds of injections besides fault injection, the original option name
bacame too narrow.

This change renames internal constants, types, and functions from
"fault" to more generic inject/tamper ones.

* defs.h (fault_opts): Rename to inject_opts.
(FAULT_OPTS_RVAL_DEFAULT): Rename to INJECT_OPTS_RVAL_DEFAULT.
(FAULT_OPTS_RVAL_DISABLE): Rename to INJECT_OPTS_RVAL_DISABLE.
(struct tcb): Rename fault_vec field to inject_vec.
(TCB_FAULT_INJ): Rename to TCB_TAMPERED.
(QUAL_FAULT): Rename to QUAL_INJECT.
(fault_vec): Rename to inject_vec.
All users changed.
* qualify.c (fault_set): Rename to inject_set.
(parse_fault_token): Rename to parse_inject_token.
(parse_fault_expression): Rename to parse_inject_expression.
All callers changed.
* syscall.c (fault_vec): Rename to inject_vec.
(tcb_fault_opts): Rename to tcb_inject_opts.
(inject_syscall_fault_entering): Rename to tamper_with_syscall_entering.
(update_syscall_fault_exiting): Rename to tamper_with_syscall_exiting.
(syscall_fault_injected): Rename to syscall_tampered.
All callers changed.

defs.h
qualify.c
strace.c
syscall.c

diff --git a/defs.h b/defs.h
index 7e5a8bfc18c0b21c93996d098ef8a2d2ac650dbf..59c9e0ec004a3f8bfb8f0b487df68b10a5453c85 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -197,16 +197,16 @@ typedef struct ioctlent {
        unsigned int code;
 } struct_ioctlent;
 
-struct fault_opts {
+struct inject_opts {
        uint16_t first;
        uint16_t step;
        uint16_t signo;
        int rval;
 };
 
-#define MAX_ERRNO_VALUE                4095
-#define FAULT_OPTS_RVAL_DEFAULT        (-(MAX_ERRNO_VALUE + 1))
-#define FAULT_OPTS_RVAL_DISABLE        (FAULT_OPTS_RVAL_DEFAULT - 1)
+#define MAX_ERRNO_VALUE                        4095
+#define INJECT_OPTS_RVAL_DEFAULT       (-(MAX_ERRNO_VALUE + 1))
+#define INJECT_OPTS_RVAL_DISABLE       (INJECT_OPTS_RVAL_DEFAULT - 1)
 
 /* Trace Control Block */
 struct tcb {
@@ -228,7 +228,7 @@ struct tcb {
        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_prev_ent; /* for "resuming interrupted SYSCALL" msg */
-       struct fault_opts *fault_vec[SUPPORTED_PERSONALITIES];
+       struct inject_opts *inject_vec[SUPPORTED_PERSONALITIES];
        struct timeval stime;   /* System time usage as of last process wait */
        struct timeval dtime;   /* Delta for system time usage */
        struct timeval etime;   /* Syscall entry time */
@@ -265,7 +265,7 @@ struct tcb {
 #define TCB_ATTACHED   0x08    /* We attached to it already */
 #define TCB_REPRINT    0x10    /* We should reprint this syscall on exit */
 #define TCB_FILTERED   0x20    /* This system call has been filtered out */
-#define TCB_FAULT_INJ  0x40    /* A syscall fault has been injected */
+#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 */
 
@@ -274,7 +274,7 @@ struct tcb {
 #define QUAL_ABBREV    0x002   /* abbreviate the structures of this syscall */
 #define QUAL_VERBOSE   0x004   /* decode the structures of this syscall */
 #define QUAL_RAW       0x008   /* print all args in hex for this syscall */
-#define QUAL_FAULT     0x010   /* fail this system call on purpose */
+#define QUAL_INJECT    0x010   /* tamper with this system call on purpose */
 #define QUAL_SIGNAL    0x100   /* report events with this signal */
 #define QUAL_READ      0x200   /* dump data read from this file descriptor */
 #define QUAL_WRITE     0x400   /* dump data written to this file descriptor */
@@ -908,7 +908,7 @@ extern unsigned nioctlents;
 
 extern const unsigned int nsyscall_vec[SUPPORTED_PERSONALITIES];
 extern const struct_sysent *const sysent_vec[SUPPORTED_PERSONALITIES];
-extern struct fault_opts *fault_vec[SUPPORTED_PERSONALITIES];
+extern struct inject_opts *inject_vec[SUPPORTED_PERSONALITIES];
 
 #ifdef IN_MPERS_BOOTSTRAP
 /* Transform multi-line MPERS_PRINTER_DECL statements to one-liners.  */
index 454eacded3fc7e20b6f73feb07135efb3ccc5eec..5116c4875d92c3aa1c72140e55a9d771887f44c7 100644 (file)
--- a/qualify.c
+++ b/qualify.c
@@ -42,7 +42,7 @@ struct number_set write_set;
 struct number_set signal_set;
 
 static struct number_set abbrev_set[SUPPORTED_PERSONALITIES];
-static struct number_set fault_set[SUPPORTED_PERSONALITIES];
+static struct number_set inject_set[SUPPORTED_PERSONALITIES];
 static struct number_set raw_set[SUPPORTED_PERSONALITIES];
 static struct number_set trace_set[SUPPORTED_PERSONALITIES];
 static struct number_set verbose_set[SUPPORTED_PERSONALITIES];
@@ -373,7 +373,7 @@ find_errno_by_name(const char *name)
 }
 
 static bool
-parse_fault_token(const char *const token, struct fault_opts *const fopts)
+parse_inject_token(const char *const token, struct inject_opts *const fopts)
 {
        const char *val;
        int intval;
@@ -409,7 +409,7 @@ parse_fault_token(const char *const token, struct fault_opts *const fopts)
                        fopts->step = 0;
                }
        } else if ((val = strip_prefix("error=", token))) {
-               if (fopts->rval != FAULT_OPTS_RVAL_DEFAULT)
+               if (fopts->rval != INJECT_OPTS_RVAL_DEFAULT)
                        return false;
                intval = string_to_uint_upto(val, MAX_ERRNO_VALUE);
                if (intval < 0)
@@ -418,7 +418,7 @@ parse_fault_token(const char *const token, struct fault_opts *const fopts)
                        return false;
                fopts->rval = -intval;
        } else if ((val = strip_prefix("retval=", token))) {
-               if (fopts->rval != FAULT_OPTS_RVAL_DEFAULT)
+               if (fopts->rval != INJECT_OPTS_RVAL_DEFAULT)
                        return false;
                intval = string_to_uint(val);
                if (intval < 0)
@@ -437,8 +437,8 @@ parse_fault_token(const char *const token, struct fault_opts *const fopts)
 }
 
 static char *
-parse_fault_expression(const char *const s, char **buf,
-                      struct fault_opts *const fopts)
+parse_inject_expression(const char *const s, char **buf,
+                       struct inject_opts *const fopts)
 {
        char *saveptr = NULL;
        char *name = NULL;
@@ -449,7 +449,7 @@ parse_fault_expression(const char *const s, char **buf,
             token = strtok_r(NULL, ":", &saveptr)) {
                if (!name)
                        name = token;
-               else if (!parse_fault_token(token, fopts))
+               else if (!parse_inject_token(token, fopts))
                        goto parse_error;
        }
 
@@ -506,14 +506,14 @@ qualify_raw(const char *const str)
 static void
 qualify_fault(const char *const str)
 {
-       struct fault_opts opts = {
+       struct inject_opts opts = {
                .first = 1,
                .step = 1,
-               .rval = FAULT_OPTS_RVAL_DEFAULT,
+               .rval = INJECT_OPTS_RVAL_DEFAULT,
                .signo = 0
        };
        char *buf = NULL;
-       char *name = parse_fault_expression(str, &buf, &opts);
+       char *name = parse_inject_expression(str, &buf, &opts);
        if (!name) {
                error_msg_and_die("invalid %s '%s'", "fault argument", str);
        }
@@ -522,8 +522,8 @@ qualify_fault(const char *const str)
         * If signal is specified but neither retval nor error are specified,
         * disable syscall fault injection.
         */
-       if (opts.signo && opts.rval == FAULT_OPTS_RVAL_DEFAULT) {
-               opts.rval = FAULT_OPTS_RVAL_DISABLE;
+       if (opts.signo && opts.rval == INJECT_OPTS_RVAL_DEFAULT) {
+               opts.rval = INJECT_OPTS_RVAL_DISABLE;
        }
 
        struct number_set tmp_set[SUPPORTED_PERSONALITIES];
@@ -533,8 +533,8 @@ qualify_fault(const char *const str)
        free(buf);
 
        /*
-        * Initialize fault_vec accourding to tmp_set.
-        * Merge tmp_set into fault_set.
+        * Initialize inject_vec accourding to tmp_set.
+        * Merge tmp_set into inject_set.
         */
        unsigned int p;
        for (p = 0; p < SUPPORTED_PERSONALITIES; ++p) {
@@ -542,16 +542,16 @@ qualify_fault(const char *const str)
                        continue;
                }
 
-               if (!fault_vec[p]) {
-                       fault_vec[p] = xcalloc(nsyscall_vec[p],
-                                              sizeof(*fault_vec[p]));
+               if (!inject_vec[p]) {
+                       inject_vec[p] = xcalloc(nsyscall_vec[p],
+                                              sizeof(*inject_vec[p]));
                }
 
                unsigned int i;
                for (i = 0; i < nsyscall_vec[p]; ++i) {
                        if (is_number_in_set(i, &tmp_set[p])) {
-                               add_number_to_set(i, &fault_set[p]);
-                               fault_vec[p][i] = opts;
+                               add_number_to_set(i, &inject_set[p]);
+                               inject_vec[p][i] = opts;
                        }
                }
 
@@ -615,6 +615,6 @@ qual_flags(const unsigned int scno)
                   ? QUAL_VERBOSE : 0)
                | (is_number_in_set(scno, &raw_set[current_personality])
                   ? QUAL_RAW : 0)
-               | (is_number_in_set(scno, &fault_set[current_personality])
-                  ? QUAL_FAULT : 0);
+               | (is_number_in_set(scno, &inject_set[current_personality])
+                  ? QUAL_INJECT : 0);
 }
index da6b165e1c9c8dac47886e8f162098821b92e6c5..7214e6efeba28b9def805f7d6c5d879a1fb78fdb 100644 (file)
--- a/strace.c
+++ b/strace.c
@@ -798,7 +798,7 @@ droptcb(struct tcb *tcp)
 
        int p;
        for (p = 0; p < SUPPORTED_PERSONALITIES; ++p)
-               free(tcp->fault_vec[p]);
+               free(tcp->inject_vec[p]);
 
        free_tcb_priv_data(tcp);
 
index 6546d1a5c08e17cb5bccf1b200d08f6dedfe5326..714fee715b005eea3a065ff9b893659aaf30623a 100644 (file)
--- a/syscall.c
+++ b/syscall.c
@@ -561,28 +561,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 +596,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_DISABLE && !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;
@@ -678,7 +678,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 +706,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,9 +739,9 @@ 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
@@ -771,8 +771,8 @@ trace_syscall_exiting(struct tcb *tcp)
        if (filtered(tcp) || hide_log(tcp))
                goto ret;
 
-       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,7 +804,7 @@ 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;
@@ -841,7 +841,7 @@ 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) {
@@ -909,7 +909,7 @@ trace_syscall_exiting(struct tcb *tcp)
                                        u_error, strerror(u_error));
                        break;
                }
-               if (syscall_fault_injected(tcp))
+               if (syscall_tampered(tcp))
                        tprintf(" (INJECTED)");
                if ((sys_res & RVAL_STR) && tcp->auxstr)
                        tprintf(" (%s)", tcp->auxstr);
@@ -963,7 +963,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 +981,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;