Dmitry V. Levin
6a2f43ce64
There are no users of SYS_* macros provided by <sys/syscall.h>, and definitions of __NR_* macros could be obtained directly from <asm/unistd.h>. * defs.h: Include <asm/unistd.h> instead of <sys/syscall.h>. * test/seccomp.c: Likewise. * test/threaded_execve.c: Likewise. * test/x32_lseek.c: Likewise. * test/x32_mmap.c: Likewise. * tests/_newselect.c: Likewise. * tests/access.c: Likewise. * tests/acct.c: Likewise. * tests/aio.c: Likewise. * tests/alarm.c: Likewise. * tests/attach-f-p.c: Likewise. * tests/bpf.c: Likewise. * tests/brk.c: Likewise. * tests/chmod.c: Likewise. * tests/chown.c: Likewise. * tests/chown32.c: Likewise. * tests/chroot.c: Likewise. * tests/clock_adjtime.c: Likewise. * tests/clock_nanosleep.c: Likewise. * tests/clock_xettime.c: Likewise. * tests/copy_file_range.c: Likewise. * tests/creat.c: Likewise. * tests/dup2.c: Likewise. * tests/dup3.c: Likewise. * tests/epoll_create.c: Likewise. * tests/epoll_create1.c: Likewise. * tests/epoll_ctl.c: Likewise. * tests/epoll_pwait.c: Likewise. * tests/epoll_wait.c: Likewise. * tests/eventfd.c: Likewise. * tests/execveat.c: Likewise. * tests/faccessat.c: Likewise. * tests/fchdir.c: Likewise. * tests/fchmod.c: Likewise. * tests/fchmodat.c: Likewise. * tests/fchown.c: Likewise. * tests/fchown32.c: Likewise. * tests/fchownat.c: Likewise. * tests/fcntl.c: Likewise. * tests/fcntl64.c: Likewise. * tests/fdatasync.c: Likewise. * tests/flock.c: Likewise. * tests/fstat.c: Likewise. * tests/fstat64.c: Likewise. * tests/fstatat64.c: Likewise. * tests/fstatfs.c: Likewise. * tests/fstatfs64.c: Likewise. * tests/fsync.c: Likewise. * tests/ftruncate.c: Likewise. * tests/ftruncate64.c: Likewise. * tests/futimesat.c: Likewise. * tests/get_mempolicy.c: Likewise. * tests/getcwd.c: Likewise. * tests/getdents.c: Likewise. * tests/getdents64.c: Likewise. * tests/getegid.c: Likewise. * tests/getegid32.c: Likewise. * tests/geteuid.c: Likewise. * tests/geteuid32.c: Likewise. * tests/getgid.c: Likewise. * tests/getgid32.c: Likewise. * tests/getgroups.c: Likewise. * tests/getgroups32.c: Likewise. * tests/getpgrp.c: Likewise. * tests/getrandom.c: Likewise. * tests/getresgid.c: Likewise. * tests/getresgid32.c: Likewise. * tests/getresuid.c: Likewise. * tests/getresuid32.c: Likewise. * tests/getrlimit.c: Likewise. * tests/getrusage.c: Likewise. * tests/getuid.c: Likewise. * tests/getuid32.c: Likewise. * tests/getxxid.c: Likewise. * tests/ioctl_uffdio.c: Likewise. * tests/ioperm.c: Likewise. * tests/iopl.c: Likewise. * tests/ipc.c: Likewise. * tests/kill.c: Likewise. * tests/lchown.c: Likewise. * tests/lchown32.c: Likewise. * tests/libmmsg.c: Likewise. * tests/libsocketcall.c: Likewise. * tests/link.c: Likewise. * tests/linkat.c: Likewise. * tests/llseek.c: Likewise. * tests/lseek.c: Likewise. * tests/lstat.c: Likewise. * tests/lstat64.c: Likewise. * tests/mbind.c: Likewise. * tests/membarrier.c: Likewise. * tests/memfd_create.c: Likewise. * tests/migrate_pages.c: Likewise. * tests/mkdir.c: Likewise. * tests/mkdirat.c: Likewise. * tests/mknod.c: Likewise. * tests/mknodat.c: Likewise. * tests/mlock.c: Likewise. * tests/mlock2.c: Likewise. * tests/move_pages.c: Likewise. * tests/newfstatat.c: Likewise. * tests/nsyscalls.c: Likewise. * tests/old_mmap.c: Likewise. * tests/oldselect.c: Likewise. * tests/open.c: Likewise. * tests/openat.c: Likewise. * tests/pause.c: Likewise. * tests/poll.c: Likewise. * tests/prctl-seccomp-filter-v.c: Likewise. * tests/prctl-seccomp-strict.c: Likewise. * tests/preadv2-pwritev2.c: Likewise. * tests/prlimit64.c: Likewise. * tests/pselect6.c: Likewise. * tests/ptrace.c: Likewise. * tests/readdir.c: Likewise. * tests/readlink.c: Likewise. * tests/readlinkat.c: Likewise. * tests/reboot.c: Likewise. * tests/remap_file_pages.c: Likewise. * tests/rename.c: Likewise. * tests/renameat.c: Likewise. * tests/renameat2.c: Likewise. * tests/rmdir.c: Likewise. * tests/rt_sigpending.c: Likewise. * tests/rt_sigprocmask.c: Likewise. * tests/rt_sigsuspend.c: Likewise. * tests/rt_sigtimedwait.c: Likewise. * tests/rt_tgsigqueueinfo.c: Likewise. * tests/sched_get_priority_mxx.c: Likewise. * tests/sched_rr_get_interval.c: Likewise. * tests/sched_xetaffinity.c: Likewise. * tests/sched_xetattr.c: Likewise. * tests/sched_xetparam.c: Likewise. * tests/sched_xetscheduler.c: Likewise. * tests/sched_yield.c: Likewise. * tests/seccomp-filter-v.c: Likewise. * tests/seccomp-filter.c: Likewise. * tests/seccomp-strict.c: Likewise. * tests/select.c: Likewise. * tests/sendfile.c: Likewise. * tests/sendfile64.c: Likewise. * tests/set_mempolicy.c: Likewise. * tests/setdomainname.c: Likewise. * tests/setfsgid.c: Likewise. * tests/setfsgid32.c: Likewise. * tests/setfsuid.c: Likewise. * tests/setfsuid32.c: Likewise. * tests/setgid.c: Likewise. * tests/setgid32.c: Likewise. * tests/setgroups.c: Likewise. * tests/setgroups32.c: Likewise. * tests/sethostname.c: Likewise. * tests/setregid.c: Likewise. * tests/setregid32.c: Likewise. * tests/setresgid.c: Likewise. * tests/setresgid32.c: Likewise. * tests/setresuid.c: Likewise. * tests/setresuid32.c: Likewise. * tests/setreuid.c: Likewise. * tests/setreuid32.c: Likewise. * tests/setrlimit.c: Likewise. * tests/setuid.c: Likewise. * tests/setuid32.c: Likewise. * tests/signalfd4.c: Likewise. * tests/socketcall.c: Likewise. * tests/splice.c: Likewise. * tests/stat.c: Likewise. * tests/stat64.c: Likewise. * tests/statfs.c: Likewise. * tests/statfs64.c: Likewise. * tests/swap.c: Likewise. * tests/symlink.c: Likewise. * tests/symlinkat.c: Likewise. * tests/sync.c: Likewise. * tests/sync_file_range.c: Likewise. * tests/sync_file_range2.c: Likewise. * tests/syslog.c: Likewise. * tests/tee.c: Likewise. * tests/time.c: Likewise. * tests/timer_create.c: Likewise. * tests/timer_xettime.c: Likewise. * tests/timerfd_xettime.c: Likewise. * tests/times-fail.c: Likewise. * tests/times.c: Likewise. * tests/truncate.c: Likewise. * tests/truncate64.c: Likewise. * tests/ugetrlimit.c: Likewise. * tests/umount.c: Likewise. * tests/umount2.c: Likewise. * tests/uname.c: Likewise. * tests/unix-pair-send-recv.c: Likewise. * tests/unlink.c: Likewise. * tests/unlinkat.c: Likewise. * tests/userfaultfd.c: Likewise. * tests/utimes.c: Likewise. * tests/vhangup.c: Likewise. * tests/vmsplice.c: Likewise. * tests/waitid.c: Likewise. * tests/waitpid.c: Likewise. * tests/xet_robust_list.c: Likewise. * tests/xetpgid.c: Likewise. * tests/xetpriority.c: Likewise. * tests/xettimeofday.c: Likewise.
478 lines
15 KiB
C
478 lines
15 KiB
C
/*
|
|
* Check decoding of ptrace syscall.
|
|
*
|
|
* Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
|
|
* 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 <asm/unistd.h>
|
|
|
|
#ifdef __NR_rt_sigprocmask
|
|
|
|
# include <errno.h>
|
|
# include <signal.h>
|
|
# include <stdio.h>
|
|
# include <string.h>
|
|
# include <sys/wait.h>
|
|
# include <unistd.h>
|
|
# include "ptrace.h"
|
|
# include <linux/audit.h>
|
|
|
|
static long
|
|
do_ptrace(unsigned long request, unsigned long pid,
|
|
unsigned long addr, unsigned long data)
|
|
{
|
|
return syscall(__NR_ptrace, request, pid, addr, data);
|
|
}
|
|
|
|
static void
|
|
test_peeksiginfo(unsigned long pid, const unsigned long bad_request)
|
|
{
|
|
long rc = do_ptrace(PTRACE_PEEKSIGINFO, pid, 0, bad_request);
|
|
printf("ptrace(PTRACE_PEEKSIGINFO, %u, NULL, %#lx)"
|
|
" = %ld %s (%m)\n", (unsigned) pid, bad_request, rc, errno2name());
|
|
|
|
struct {
|
|
unsigned long long off;
|
|
unsigned int flags, nr;
|
|
} *const psi = tail_alloc(sizeof(*psi));
|
|
|
|
psi->off = 0xdeadbeeffacefeed;
|
|
psi->flags = 1;
|
|
psi->nr = 42;
|
|
|
|
rc = do_ptrace(PTRACE_PEEKSIGINFO,
|
|
pid, (unsigned long) psi, bad_request);
|
|
printf("ptrace(PTRACE_PEEKSIGINFO, %u, {off=%llu"
|
|
", flags=PTRACE_PEEKSIGINFO_SHARED, nr=%u}, %#lx)"
|
|
" = %ld %s (%m)\n",
|
|
(unsigned) pid, psi->off, psi->nr, bad_request, rc, errno2name());
|
|
|
|
pid = fork();
|
|
if ((pid_t) pid < 0)
|
|
perror_msg_and_fail("fork");
|
|
|
|
if (!pid) {
|
|
sigset_t mask;
|
|
sigemptyset(&mask);
|
|
sigaddset(&mask, SIGUSR1);
|
|
sigaddset(&mask, SIGUSR2);
|
|
sigaddset(&mask, SIGALRM);
|
|
|
|
if (sigprocmask(SIG_BLOCK, &mask, NULL))
|
|
perror_msg_and_fail("sigprocmask");
|
|
|
|
raise(SIGUSR1);
|
|
raise(SIGUSR2);
|
|
raise(SIGALRM);
|
|
|
|
if (do_ptrace(PTRACE_TRACEME, 0, 0, 0))
|
|
perror_msg_and_fail("child: PTRACE_TRACEME");
|
|
|
|
raise(SIGSTOP);
|
|
_exit(0);
|
|
}
|
|
|
|
const unsigned int nsigs = 4;
|
|
const uid_t uid = geteuid();
|
|
siginfo_t *sigs = tail_alloc(sizeof(*sigs) * nsigs);
|
|
|
|
psi->off = 0;
|
|
psi->flags = 0;
|
|
psi->nr = nsigs;
|
|
|
|
for (;;) {
|
|
int status, tracee, saved;
|
|
|
|
errno = 0;
|
|
tracee = wait(&status);
|
|
if (tracee <= 0) {
|
|
if (errno == EINTR)
|
|
continue;
|
|
saved = errno;
|
|
kill (pid, SIGKILL);
|
|
errno = saved;
|
|
perror_msg_and_fail("wait");
|
|
}
|
|
if (WIFEXITED(status)) {
|
|
if (WEXITSTATUS(status) == 0)
|
|
break;
|
|
error_msg_and_fail("unexpected exit status %u",
|
|
WEXITSTATUS(status));
|
|
}
|
|
if (WIFSIGNALED(status))
|
|
error_msg_and_fail("unexpected signal %u",
|
|
WTERMSIG(status));
|
|
if (!WIFSTOPPED(status) || WSTOPSIG(status) != SIGSTOP) {
|
|
kill(pid, SIGKILL);
|
|
error_msg_and_fail("unexpected wait status %x",
|
|
status);
|
|
}
|
|
|
|
rc = do_ptrace(PTRACE_PEEKSIGINFO, pid,
|
|
(unsigned long) psi, (unsigned long) sigs);
|
|
if (rc < 0) {
|
|
printf("ptrace(PTRACE_PEEKSIGINFO, %u, {off=%llu"
|
|
", flags=0, nr=%u}, %p) = %ld %s (%m)\n",
|
|
(unsigned) pid, psi->off, psi->nr, sigs,
|
|
rc, errno2name());
|
|
} else {
|
|
printf("ptrace(PTRACE_PEEKSIGINFO, %u, {off=%llu"
|
|
", flags=0, nr=%u}"
|
|
", [{si_signo=SIGUSR1, si_code=SI_TKILL"
|
|
", si_pid=%u, si_uid=%u}"
|
|
", {si_signo=SIGUSR2, si_code=SI_TKILL"
|
|
", si_pid=%u, si_uid=%u}"
|
|
", {si_signo=SIGALRM, si_code=SI_TKILL"
|
|
", si_pid=%u, si_uid=%u}"
|
|
"]) = %ld\n",
|
|
(unsigned) pid, psi->off, psi->nr,
|
|
(unsigned) pid, (unsigned) uid,
|
|
(unsigned) pid, (unsigned) uid,
|
|
(unsigned) pid, (unsigned) uid,
|
|
rc);
|
|
}
|
|
|
|
if (do_ptrace(PTRACE_CONT, pid, 0, 0)) {
|
|
saved = errno;
|
|
kill (pid, SIGKILL);
|
|
errno = saved;
|
|
perror_msg_and_fail("ptrace");
|
|
}
|
|
printf("ptrace(PTRACE_CONT, %ld, NULL, SIG_0) = 0\n", pid);
|
|
}
|
|
}
|
|
|
|
int
|
|
main(void)
|
|
{
|
|
const unsigned long bad_request =
|
|
(unsigned long) 0xdeadbeeffffffeed;
|
|
const unsigned long bad_data =
|
|
(unsigned long) 0xdeadcafefffff00d;
|
|
const unsigned long pid =
|
|
(unsigned long) 0xdefaced00000000 | (unsigned) getpid();
|
|
|
|
unsigned int sigset_size;
|
|
|
|
for (sigset_size = 1024 / 8; sigset_size; sigset_size >>= 1) {
|
|
if (!syscall(__NR_rt_sigprocmask,
|
|
SIG_SETMASK, NULL, NULL, sigset_size))
|
|
break;
|
|
}
|
|
if (!sigset_size)
|
|
perror_msg_and_fail("rt_sigprocmask");
|
|
|
|
void *const k_set = tail_alloc(sigset_size);
|
|
siginfo_t *const sip = tail_alloc(sizeof(*sip));
|
|
|
|
long rc = do_ptrace(bad_request, pid, 0, 0);
|
|
printf("ptrace(%#lx /* PTRACE_??? */, %u, NULL, NULL) = %ld %s (%m)\n",
|
|
bad_request, (unsigned) pid, rc, errno2name());
|
|
|
|
rc = do_ptrace(PTRACE_PEEKDATA, pid, bad_request, bad_data);
|
|
# ifdef IA64
|
|
printf("ptrace(PTRACE_PEEKDATA, %u, %#lx)"
|
|
" = %ld %s (%m)\n",
|
|
(unsigned) pid, bad_request, rc, errno2name());
|
|
# else
|
|
printf("ptrace(PTRACE_PEEKDATA, %u, %#lx, %#lx)"
|
|
" = %ld %s (%m)\n",
|
|
(unsigned) pid, bad_request, bad_data, rc, errno2name());
|
|
#endif
|
|
|
|
rc = do_ptrace(PTRACE_PEEKTEXT, pid, bad_request, bad_data);
|
|
# ifdef IA64
|
|
printf("ptrace(PTRACE_PEEKTEXT, %u, %#lx)"
|
|
" = %ld %s (%m)\n",
|
|
(unsigned) pid, bad_request, rc, errno2name());
|
|
# else
|
|
printf("ptrace(PTRACE_PEEKTEXT, %u, %#lx, %#lx)"
|
|
" = %ld %s (%m)\n",
|
|
(unsigned) pid, bad_request, bad_data, rc, errno2name());
|
|
#endif
|
|
|
|
rc = do_ptrace(PTRACE_PEEKUSER, pid, bad_request, bad_data);
|
|
# ifdef IA64
|
|
printf("ptrace(PTRACE_PEEKUSER, %u, %#lx)"
|
|
" = %ld %s (%m)\n",
|
|
(unsigned) pid, bad_request, rc, errno2name());
|
|
# else
|
|
printf("ptrace(PTRACE_PEEKUSER, %u, %#lx, %#lx)"
|
|
" = %ld %s (%m)\n",
|
|
(unsigned) pid, bad_request, bad_data, rc, errno2name());
|
|
#endif
|
|
|
|
rc = do_ptrace(PTRACE_POKEUSER, pid, bad_request, bad_data);
|
|
printf("ptrace(PTRACE_POKEUSER, %u, %#lx, %#lx)"
|
|
" = %ld %s (%m)\n",
|
|
(unsigned) pid, bad_request, bad_data, rc, errno2name());
|
|
|
|
rc = do_ptrace(PTRACE_ATTACH, pid, 0, 0);
|
|
printf("ptrace(PTRACE_ATTACH, %u) = %ld %s (%m)\n",
|
|
(unsigned) pid, rc, errno2name());
|
|
|
|
rc = do_ptrace(PTRACE_INTERRUPT, pid, 0, 0);
|
|
printf("ptrace(PTRACE_INTERRUPT, %u) = %ld %s (%m)\n",
|
|
(unsigned) pid, rc, errno2name());
|
|
|
|
rc = do_ptrace(PTRACE_KILL, pid, 0, 0);
|
|
printf("ptrace(PTRACE_KILL, %u) = %ld %s (%m)\n",
|
|
(unsigned) pid, rc, errno2name());
|
|
|
|
rc = do_ptrace(PTRACE_LISTEN, pid, 0, 0);
|
|
printf("ptrace(PTRACE_LISTEN, %u) = %ld %s (%m)\n",
|
|
(unsigned) pid, rc, errno2name());
|
|
|
|
sigset_t libc_set;
|
|
sigemptyset(&libc_set);
|
|
sigaddset(&libc_set, SIGUSR1);
|
|
memcpy(k_set, &libc_set, sigset_size);
|
|
|
|
rc = do_ptrace(PTRACE_SETSIGMASK,
|
|
pid, sigset_size, (unsigned long) k_set);
|
|
printf("ptrace(PTRACE_SETSIGMASK, %u, %u, [USR1])"
|
|
" = %ld %s (%m)\n",
|
|
(unsigned) pid, sigset_size, rc, errno2name());
|
|
|
|
rc = do_ptrace(PTRACE_GETSIGMASK,
|
|
pid, sigset_size, (unsigned long) k_set);
|
|
printf("ptrace(PTRACE_GETSIGMASK, %u, %u, %p)"
|
|
" = %ld %s (%m)\n",
|
|
(unsigned) pid, sigset_size, k_set, rc, errno2name());
|
|
|
|
rc = do_ptrace(PTRACE_SECCOMP_GET_FILTER, pid, 42, 0);
|
|
printf("ptrace(PTRACE_SECCOMP_GET_FILTER, %u, 42, NULL)"
|
|
" = %ld %s (%m)\n", (unsigned) pid, rc, errno2name());
|
|
|
|
rc = do_ptrace(PTRACE_GETEVENTMSG, pid, bad_request, bad_data);
|
|
printf("ptrace(PTRACE_GETEVENTMSG, %u, %#lx, %#lx)"
|
|
" = %ld %s (%m)\n",
|
|
(unsigned) pid, bad_request, bad_data, rc, errno2name());
|
|
|
|
memset(sip, -1, sizeof(*sip));
|
|
sip->si_signo = SIGIO;
|
|
sip->si_code = 1;
|
|
sip->si_errno = ENOENT;
|
|
sip->si_band = -2;
|
|
|
|
rc = do_ptrace(PTRACE_SETSIGINFO,
|
|
pid, bad_request, (unsigned long) sip);
|
|
printf("ptrace(PTRACE_SETSIGINFO, %u, %#lx, {si_signo=SIGIO"
|
|
", si_code=POLL_IN, si_errno=ENOENT, si_band=-2})"
|
|
" = %ld %s (%m)\n",
|
|
(unsigned) pid, bad_request, rc, errno2name());
|
|
|
|
memset(sip, -1, sizeof(*sip));
|
|
sip->si_signo = SIGTRAP;
|
|
sip->si_code = 1;
|
|
sip->si_errno = ENOENT;
|
|
sip->si_pid = 2;
|
|
sip->si_uid = 3;
|
|
sip->si_ptr = (void *) bad_request;
|
|
|
|
rc = do_ptrace(PTRACE_SETSIGINFO,
|
|
pid, bad_request, (unsigned long) sip);
|
|
printf("ptrace(PTRACE_SETSIGINFO, %u, %#lx, {si_signo=SIGTRAP"
|
|
", si_code=TRAP_BRKPT, si_errno=ENOENT, si_pid=2, si_uid=3"
|
|
", si_value={int=%d, ptr=%p}}) = %ld %s (%m)\n",
|
|
(unsigned) pid, bad_request, sip->si_int, sip->si_ptr, rc, errno2name());
|
|
|
|
memset(sip, -1, sizeof(*sip));
|
|
sip->si_signo = SIGILL;
|
|
sip->si_code = 1;
|
|
sip->si_errno = ENOENT;
|
|
sip->si_addr = (void *) (unsigned long) 0xfacefeeddeadbeef;
|
|
|
|
rc = do_ptrace(PTRACE_SETSIGINFO,
|
|
pid, bad_request, (unsigned long) sip);
|
|
printf("ptrace(PTRACE_SETSIGINFO, %u, %#lx, {si_signo=SIGILL"
|
|
", si_code=ILL_ILLOPC, si_errno=ENOENT, si_addr=%p})"
|
|
" = %ld %s (%m)\n",
|
|
(unsigned) pid, bad_request, sip->si_addr, rc, errno2name());
|
|
|
|
memset(sip, -1, sizeof(*sip));
|
|
sip->si_signo = SIGFPE;
|
|
sip->si_code = 1;
|
|
sip->si_errno = ENOENT;
|
|
sip->si_addr = (void *) (unsigned long) 0xfacefeeddeadbeef;
|
|
|
|
rc = do_ptrace(PTRACE_SETSIGINFO,
|
|
pid, bad_request, (unsigned long) sip);
|
|
printf("ptrace(PTRACE_SETSIGINFO, %u, %#lx, {si_signo=SIGFPE"
|
|
", si_code=FPE_INTDIV, si_errno=ENOENT, si_addr=%p})"
|
|
" = %ld %s (%m)\n",
|
|
(unsigned) pid, bad_request, sip->si_addr, rc, errno2name());
|
|
|
|
memset(sip, -1, sizeof(*sip));
|
|
sip->si_signo = SIGBUS;
|
|
sip->si_code = 1;
|
|
sip->si_errno = -2;
|
|
sip->si_addr = (void *) (unsigned long) 0xfacefeeddeadbeef;
|
|
|
|
rc = do_ptrace(PTRACE_SETSIGINFO,
|
|
pid, bad_request, (unsigned long) sip);
|
|
printf("ptrace(PTRACE_SETSIGINFO, %u, %#lx, {si_signo=SIGBUS"
|
|
", si_code=BUS_ADRALN, si_errno=%d, si_addr=%p})"
|
|
" = %ld %s (%m)\n",
|
|
(unsigned) pid, bad_request, sip->si_errno, sip->si_addr,
|
|
rc, errno2name());
|
|
|
|
memset(sip, -1, sizeof(*sip));
|
|
sip->si_signo = SIGPROF;
|
|
sip->si_code = 0xbadc0ded;
|
|
sip->si_errno = -2;
|
|
sip->si_pid = 0;
|
|
sip->si_uid = 3;
|
|
sip->si_ptr = 0;
|
|
|
|
rc = do_ptrace(PTRACE_SETSIGINFO,
|
|
pid, bad_request, (unsigned long) sip);
|
|
printf("ptrace(PTRACE_SETSIGINFO, %u, %#lx, {si_signo=SIGPROF"
|
|
", si_code=%#x, si_errno=%d, si_pid=0, si_uid=3})"
|
|
" = %ld %s (%m)\n",
|
|
(unsigned) pid, bad_request, sip->si_code, sip->si_errno,
|
|
rc, errno2name());
|
|
|
|
#ifdef HAVE_SIGINFO_T_SI_SYSCALL
|
|
memset(sip, -1, sizeof(*sip));
|
|
sip->si_signo = SIGSYS;
|
|
sip->si_code = 1;
|
|
sip->si_errno = ENOENT;
|
|
sip->si_call_addr = (void *) (unsigned long) 0xfacefeeddeadbeef;
|
|
sip->si_syscall = -1U;
|
|
sip->si_arch = AUDIT_ARCH_X86_64;
|
|
|
|
rc = do_ptrace(PTRACE_SETSIGINFO,
|
|
pid, bad_request, (unsigned long) sip);
|
|
printf("ptrace(PTRACE_SETSIGINFO, %u, %#lx, {si_signo=SIGSYS"
|
|
", si_code=SYS_SECCOMP, si_errno=ENOENT, si_call_addr=%p"
|
|
", si_syscall=__NR_syscall_%u, si_arch=AUDIT_ARCH_X86_64})"
|
|
" = %ld %s (%m)\n",
|
|
(unsigned) pid, bad_request, sip->si_call_addr, sip->si_syscall,
|
|
rc, errno2name());
|
|
#endif
|
|
|
|
#if defined HAVE_SIGINFO_T_SI_TIMERID && defined HAVE_SIGINFO_T_SI_OVERRUN
|
|
memset(sip, -1, sizeof(*sip));
|
|
sip->si_signo = SIGHUP;
|
|
sip->si_code = SI_TIMER;
|
|
sip->si_errno = ENOENT;
|
|
sip->si_timerid = 0xdeadbeef;
|
|
sip->si_overrun = -1;
|
|
sip->si_ptr = (void *) (unsigned long) 0xfacefeeddeadbeef;
|
|
|
|
rc = do_ptrace(PTRACE_SETSIGINFO,
|
|
pid, bad_request, (unsigned long) sip);
|
|
printf("ptrace(PTRACE_SETSIGINFO, %u, %#lx, {si_signo=SIGHUP"
|
|
", si_code=SI_TIMER, si_errno=ENOENT, si_timerid=%#x"
|
|
", si_overrun=%d, si_value={int=%d, ptr=%p}}) = %ld %s (%m)\n",
|
|
(unsigned) pid, bad_request, sip->si_timerid, sip->si_overrun,
|
|
sip->si_int, sip->si_ptr, rc, errno2name());
|
|
#endif
|
|
|
|
rc = do_ptrace(PTRACE_GETSIGINFO,
|
|
pid, bad_request, (unsigned long) sip);
|
|
printf("ptrace(PTRACE_GETSIGINFO, %u, %#lx, %p)"
|
|
" = %ld %s (%m)\n", (unsigned) pid, bad_request, sip, rc, errno2name());
|
|
|
|
rc = do_ptrace(PTRACE_CONT, pid, 0, SIGUSR1);
|
|
printf("ptrace(PTRACE_CONT, %u, NULL, SIGUSR1) = %ld %s (%m)\n",
|
|
(unsigned) pid, rc, errno2name());
|
|
|
|
rc = do_ptrace(PTRACE_DETACH, pid, 0, SIGUSR2);
|
|
printf("ptrace(PTRACE_DETACH, %u, NULL, SIGUSR2) = %ld %s (%m)\n",
|
|
(unsigned) pid, rc, errno2name());
|
|
|
|
rc = do_ptrace(PTRACE_SYSCALL, pid, 0, SIGUSR1);
|
|
printf("ptrace(PTRACE_SYSCALL, %u, NULL, SIGUSR1) = %ld %s (%m)\n",
|
|
(unsigned) pid, rc, errno2name());
|
|
|
|
#ifdef PTRACE_SINGLESTEP
|
|
rc = do_ptrace(PTRACE_SINGLESTEP, pid, 0, SIGUSR2);
|
|
printf("ptrace(PTRACE_SINGLESTEP, %u, NULL, SIGUSR2) = %ld %s (%m)\n",
|
|
(unsigned) pid, rc, errno2name());
|
|
#endif
|
|
|
|
#ifdef PTRACE_SINGLEBLOCK
|
|
rc = do_ptrace(PTRACE_SINGLEBLOCK, pid, 0, SIGUSR1);
|
|
printf("ptrace(PTRACE_SINGLEBLOCK, %u, NULL, SIGUSR1) = %ld %s (%m)\n",
|
|
(unsigned) pid, rc, errno2name());
|
|
#endif
|
|
|
|
#ifdef PTRACE_SYSEMU
|
|
rc = do_ptrace(PTRACE_SYSEMU, pid, 0, SIGUSR2);
|
|
printf("ptrace(PTRACE_SYSEMU, %u, NULL, SIGUSR2) = %ld %s (%m)\n",
|
|
(unsigned) pid, rc, errno2name());
|
|
#endif
|
|
#ifdef PTRACE_SYSEMU_SINGLESTEP
|
|
rc = do_ptrace(PTRACE_SYSEMU_SINGLESTEP, pid, 0, SIGUSR1);
|
|
printf("ptrace(PTRACE_SYSEMU_SINGLESTEP, %u, NULL, SIGUSR1)"
|
|
" = %ld %s (%m)\n", (unsigned) pid, rc, errno2name());
|
|
#endif
|
|
|
|
rc = do_ptrace(PTRACE_SETOPTIONS,
|
|
pid, 0, PTRACE_O_TRACEFORK|PTRACE_O_TRACECLONE);
|
|
printf("ptrace(PTRACE_SETOPTIONS, %u, NULL"
|
|
", PTRACE_O_TRACEFORK|PTRACE_O_TRACECLONE) = %ld %s (%m)\n",
|
|
(unsigned) pid, rc, errno2name());
|
|
|
|
rc = do_ptrace(PTRACE_SEIZE,
|
|
pid, bad_request, PTRACE_O_TRACESYSGOOD);
|
|
printf("ptrace(PTRACE_SEIZE, %u, %#lx"
|
|
", PTRACE_O_TRACESYSGOOD) = %ld %s (%m)\n",
|
|
(unsigned) pid, bad_request, rc, errno2name());
|
|
|
|
rc = do_ptrace(PTRACE_SETREGSET, pid, 1, bad_request);
|
|
printf("ptrace(PTRACE_SETREGSET, %u, NT_PRSTATUS, %#lx)"
|
|
" = %ld %s (%m)\n",
|
|
(unsigned) pid, bad_request, rc, errno2name());
|
|
|
|
rc = do_ptrace(PTRACE_GETREGSET, pid, 3, bad_request);
|
|
printf("ptrace(PTRACE_GETREGSET, %u, NT_PRPSINFO, %#lx)"
|
|
" = %ld %s (%m)\n",
|
|
(unsigned) pid, bad_request, rc, errno2name());
|
|
|
|
test_peeksiginfo(pid, bad_request);
|
|
|
|
rc = do_ptrace(PTRACE_TRACEME, 0, 0, 0);
|
|
if (rc)
|
|
printf("ptrace(PTRACE_TRACEME) = %ld %s (%m)\n",
|
|
rc, errno2name());
|
|
else
|
|
printf("ptrace(PTRACE_TRACEME) = 0\n");
|
|
|
|
puts("+++ exited with 0 +++");
|
|
return 0;
|
|
}
|
|
|
|
|
|
#else
|
|
|
|
SKIP_MAIN_UNDEFINED("__NR_rt_sigprocmask")
|
|
|
|
#endif
|