From b21d81db04aaecb45bde9b5f0f519d844c745bb9 Mon Sep 17 00:00:00 2001 From: Eugene Syromyatnikov Date: Thu, 1 Feb 2018 12:34:05 +0100 Subject: [PATCH] Change type of injected rval to kernel_long_t * defs.h (struct inject_data): Change type of rval field to kernel_ulong_t. * filter_qualify.c (parse_inject_token): Use string_to_kulong instead of string_to_uint for rval parsing. Warn if retval is clipped in compat personality. --- defs.h | 2 +- filter_qualify.c | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/defs.h b/defs.h index a014ccf9..742db9a9 100644 --- a/defs.h +++ b/defs.h @@ -181,7 +181,7 @@ typedef struct ioctlent { struct inject_data { uint16_t flags; uint16_t signo; - int rval; + kernel_long_t rval; }; struct inject_opts { diff --git a/filter_qualify.c b/filter_qualify.c index 356f4725..554536a2 100644 --- a/filter_qualify.c +++ b/filter_qualify.c @@ -83,7 +83,7 @@ parse_inject_token(const char *const token, struct inject_opts *const fopts, const bool fault_tokens_only) { const char *val; - int intval; + kernel_long_t intval; if ((val = STR_STRIP_PREFIX(token, "when=")) != token) { /* @@ -129,9 +129,23 @@ parse_inject_token(const char *const token, struct inject_opts *const fopts, && (val = STR_STRIP_PREFIX(token, "retval=")) != token) { if (fopts->data.flags & INJECT_F_RETVAL) return false; - intval = string_to_uint(val); + intval = string_to_kulong(val); if (intval < 0) return false; + +#if ANY_WORDSIZE_LESS_THAN_KERNEL_LONG && !HAVE_ARCH_DEDICATED_ERR_REG + if ((int) intval != intval) + error_msg("Injected return value %" PRI_kld " will be" + " clipped to %d in compat personality", + intval, (int) intval); + + if ((int) intval < 0 && (int) intval >= -4095) + error_msg("Inadvertent injection of error %d is" + " possible in compat personality for" + " retval=%" PRI_kld, + -(int) intval, intval); +#endif + fopts->data.rval = intval; fopts->data.flags |= INJECT_F_RETVAL; } else if (!fault_tokens_only -- 2.40.0