Move inject data of struct inject_opts to inject_data substructure
authorDmitry V. Levin <ldv@altlinux.org>
Mon, 28 Aug 2017 22:37:27 +0000 (22:37 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 28 Aug 2017 22:37:27 +0000 (22:37 +0000)
* 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 <krapivenskiy.va@phystech.edu>
defs.h
filter_qualify.c
syscall.c

diff --git a/defs.h b/defs.h
index 93f09706329cf474fdc8cf12f4a9a68efff22daa..0f276ba294848dcd12dc05b32b87b1e44a8ad416 100644 (file)
--- 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
index b59b19b9f95351fe96331e28a6958b3c5072be8e..d3c036cf4aafeb32d0418c117c1db6e9f7638801 100644 (file)
@@ -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);
index 1d3b12328a405d4eb85651ff87a408b326d6232a..a622f0bf8b2f2d5889e51be1aab9099aab70c753 100644 (file)
--- 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;