From: Dmitry V. Levin Date: Mon, 28 Aug 2017 22:37:27 +0000 (+0000) Subject: Move inject data of struct inject_opts to inject_data substructure X-Git-Tag: v4.19~39 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4fa9ea37075e56fa0e980b68e2e8d6922ebe31c3;p=strace Move inject data of struct inject_opts to inject_data substructure * defs.h (inject_data): New structure. (struct inject_opts): Replace "signo" and "rval" fields with "data" field of type "struct inject_data". * filter_qualify.c (parse_inject_token, qualify_inject_common): Update for the new layout of struct inject_opts. * syscall.c (tamper_with_syscall_entering, tamper_with_syscall_exiting): Likewise. Co-authored-by: Victor Krapivensky --- diff --git a/defs.h b/defs.h index 93f09706..0f276ba2 100644 --- a/defs.h +++ b/defs.h @@ -180,11 +180,15 @@ typedef struct ioctlent { unsigned int code; } struct_ioctlent; +struct inject_data { + uint16_t signo; + int rval; +}; + struct inject_opts { uint16_t first; uint16_t step; - uint16_t signo; - int rval; + struct inject_data data; }; #define MAX_ERRNO_VALUE 4095 diff --git a/filter_qualify.c b/filter_qualify.c index b59b19b9..d3c036cf 100644 --- a/filter_qualify.c +++ b/filter_qualify.c @@ -120,28 +120,28 @@ parse_inject_token(const char *const token, struct inject_opts *const fopts, fopts->step = 0; } } else if ((val = STR_STRIP_PREFIX(token, "error=")) != token) { - if (fopts->rval != INJECT_OPTS_RVAL_DEFAULT) + if (fopts->data.rval != INJECT_OPTS_RVAL_DEFAULT) return false; intval = string_to_uint_upto(val, MAX_ERRNO_VALUE); if (intval < 0) intval = find_errno_by_name(val); if (intval < 1) return false; - fopts->rval = -intval; + fopts->data.rval = -intval; } else if (!fault_tokens_only && (val = STR_STRIP_PREFIX(token, "retval=")) != token) { - if (fopts->rval != INJECT_OPTS_RVAL_DEFAULT) + if (fopts->data.rval != INJECT_OPTS_RVAL_DEFAULT) return false; intval = string_to_uint(val); if (intval < 0) return false; - fopts->rval = intval; + fopts->data.rval = intval; } else if (!fault_tokens_only && (val = STR_STRIP_PREFIX(token, "signal=")) != token) { intval = sigstr_to_uint(val); if (intval < 1 || intval > NSIG_BYTES * 8) return false; - fopts->signo = intval; + fopts->data.signo = intval; } else { return false; } @@ -239,8 +239,10 @@ qualify_inject_common(const char *const str, struct inject_opts opts = { .first = 1, .step = 1, - .rval = INJECT_OPTS_RVAL_DEFAULT, - .signo = 0 + .data = { + .rval = INJECT_OPTS_RVAL_DEFAULT, + .signo = 0 + } }; char *buf = NULL; char *name = parse_inject_expression(str, &buf, &opts, fault_tokens_only); @@ -249,10 +251,10 @@ qualify_inject_common(const char *const str, } /* If neither of retval, error, or signal is specified, then ... */ - if (opts.rval == INJECT_OPTS_RVAL_DEFAULT && !opts.signo) { + if (opts.data.rval == INJECT_OPTS_RVAL_DEFAULT && !opts.data.signo) { if (fault_tokens_only) { /* in fault= syntax the default error code is ENOSYS. */ - opts.rval = -ENOSYS; + opts.data.rval = -ENOSYS; } else { /* in inject= syntax this is not allowed. */ error_msg_and_die("invalid %s '%s'", description, str); diff --git a/syscall.c b/syscall.c index 1d3b1232..a622f0bf 100644 --- a/syscall.c +++ b/syscall.c @@ -570,9 +570,9 @@ tamper_with_syscall_entering(struct tcb *tcp, unsigned int *signo) opts->first = opts->step; - if (opts->signo > 0) - *signo = opts->signo; - if (opts->rval != INJECT_OPTS_RVAL_DEFAULT && !arch_set_scno(tcp, -1)) + if (opts->data.signo > 0) + *signo = opts->data.signo; + if (opts->data.rval != INJECT_OPTS_RVAL_DEFAULT && !arch_set_scno(tcp, -1)) tcp->flags |= TCB_TAMPERED; return 0; @@ -586,17 +586,17 @@ tamper_with_syscall_exiting(struct tcb *tcp) if (!opts) return 0; - if (opts->rval >= 0) { + if (opts->data.rval >= 0) { kernel_long_t u_rval = tcp->u_rval; - tcp->u_rval = opts->rval; + tcp->u_rval = opts->data.rval; if (arch_set_success(tcp)) { tcp->u_rval = u_rval; } else { tcp->u_error = 0; } } else { - unsigned long new_error = -opts->rval; + unsigned long new_error = -opts->data.rval; if (new_error != tcp->u_error && new_error <= MAX_ERRNO_VALUE) { unsigned long u_error = tcp->u_error;