4c9ed3f146
Extend the range of injected return value to the maximum, print warnings if negative injection value can be clipped in compat personality or can inadvertently turn into a fault injection. * defs.h (INJECT_F_ERROR): New macro. * filter_qualify.c (parse_inject_token): Revert type of intval local variable back to int, check INJECT_F_ERROR along with INJECT_F_RETVAL, use strtoull to parse retval argument, print warnings in case of retval clipping and inadvertent fault injection. (qualify_inject_common): Set INJECT_F_ERROR instead of INJECT_F_RETVAL. * syscall.c (tamper_with_syscall_exiting): Check inject_data.flags to determine whether a fault injection or retval injection has to be performed. (syscall_exiting_trace) <case RVAL_DECIMAL>: Explicitly print tcp->u_rval as int if current_klongsize < sizeof(tcp->u_rval). * tests/inject-nf.c (main): Update. * tests/inject-nf.test: Test injection of negative return values. * tests/qual_inject-syntax.test: Remove retval=-1 check as it is now allowed, add checks for invalid retval parameters. Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
87 lines
2.7 KiB
C
87 lines
2.7 KiB
C
/*
|
|
* Check decoding of return values injected into a syscall that "never fails".
|
|
*
|
|
* Copyright (c) 2018 The strace developers.
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
* derived from this software without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
#include "tests.h"
|
|
|
|
#include <assert.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <asm/unistd.h>
|
|
|
|
#include "raw_syscall.h"
|
|
|
|
#ifdef __alpha__
|
|
/* alpha has no getpid */
|
|
# define SC_NR __NR_getpgrp
|
|
# define SC_NAME "getpgrp"
|
|
# define getpid getpgrp
|
|
#else
|
|
# define SC_NR __NR_getpid
|
|
# define SC_NAME "getpid"
|
|
#endif
|
|
|
|
#ifdef raw_syscall_0
|
|
# define INVOKE_SC(err) raw_syscall_0(SC_NR, &err)
|
|
#else
|
|
/* No raw_syscall_0, let's use getpid() and hope for the best. */
|
|
# define INVOKE_SC(err) getpid()
|
|
#endif
|
|
|
|
/*
|
|
* This prototype is intentionally different
|
|
* from the prototype provided by <unistd.h>.
|
|
*/
|
|
extern kernel_ulong_t getpid(void);
|
|
|
|
int
|
|
main(int ac, char **av)
|
|
{
|
|
assert(ac == 1 || ac == 2);
|
|
|
|
kernel_ulong_t expected =
|
|
(ac == 1) ? getpid() : strtoull(av[1], NULL, 0);
|
|
kernel_ulong_t err = 0;
|
|
kernel_ulong_t rc = INVOKE_SC(err);
|
|
|
|
if (err || rc != expected)
|
|
error_msg_and_fail("expected %#llx, got rval=%#llx err=%#llx",
|
|
(unsigned long long) expected,
|
|
(unsigned long long) rc,
|
|
(unsigned long long) err);
|
|
|
|
if (ac == 2) {
|
|
printf("%s() = %lld (INJECTED)\n",
|
|
SC_NAME, sign_extend_unsigned_to_ll(rc));
|
|
|
|
puts("+++ exited with 0 +++");
|
|
}
|
|
|
|
return 0;
|
|
}
|