* Check decoding of ptrace syscall.
*
* Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
+ * Copyright (c) 2016-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.
+ * SPDX-License-Identifier: GPL-2.0-or-later
*/
#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>
+#include <errno.h>
+#include "ptrace.h"
+#include <inttypes.h>
+#include <signal.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <linux/audit.h>
static const char *errstr;
printf("ptrace(PTRACE_PEEKSIGINFO, %u, NULL, %#lx) = %s\n",
(unsigned) pid, bad_request, errstr);
- struct {
+ struct psi {
unsigned long long off;
unsigned int flags, nr;
- } *const psi = tail_alloc(sizeof(*psi));
+ };
+ TAIL_ALLOC_OBJECT_CONST_PTR(struct psi, psi);
psi->off = 0xdeadbeeffacefeedULL;
psi->flags = 1;
if (errno == EINTR)
continue;
saved = errno;
- kill (pid, SIGKILL);
+ kill(pid, SIGKILL);
errno = saved;
perror_msg_and_fail("wait");
}
if (do_ptrace(PTRACE_CONT, pid, 0, 0)) {
saved = errno;
- kill (pid, SIGKILL);
+ kill(pid, SIGKILL);
errno = saved;
perror_msg_and_fail("ptrace");
}
- printf("ptrace(PTRACE_CONT, %ld, NULL, SIG_0) = 0\n", pid);
+ printf("ptrace(PTRACE_CONT, %ld, NULL, 0) = 0\n", pid);
}
}
const unsigned long pid =
(unsigned long) 0xdefaced00000000ULL | (unsigned) getpid();
- unsigned int sigset_size;
+ TAIL_ALLOC_OBJECT_CONST_PTR(uint64_t, filter_off);
- 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");
+ const unsigned int sigset_size = get_sigset_size();
void *const k_set = tail_alloc(sigset_size);
- siginfo_t *const sip = tail_alloc(sizeof(*sip));
+ TAIL_ALLOC_OBJECT_CONST_PTR(siginfo_t, sip);
do_ptrace(bad_request, pid, 0, 0);
printf("ptrace(%#lx /* PTRACE_??? */, %u, NULL, NULL) = %s\n",
bad_request, (unsigned) pid, errstr);
do_ptrace(PTRACE_PEEKDATA, pid, bad_request, bad_data);
-# ifdef IA64
+#ifdef IA64
printf("ptrace(PTRACE_PEEKDATA, %u, %#lx) = %s\n",
(unsigned) pid, bad_request, errstr);
-# else
+#else
printf("ptrace(PTRACE_PEEKDATA, %u, %#lx, %#lx) = %s\n",
(unsigned) pid, bad_request, bad_data, errstr);
#endif
do_ptrace(PTRACE_PEEKTEXT, pid, bad_request, bad_data);
-# ifdef IA64
+#ifdef IA64
printf("ptrace(PTRACE_PEEKTEXT, %u, %#lx) = %s\n",
(unsigned) pid, bad_request, errstr);
-# else
+#else
printf("ptrace(PTRACE_PEEKTEXT, %u, %#lx, %#lx) = %s\n",
(unsigned) pid, bad_request, bad_data, errstr);
#endif
do_ptrace(PTRACE_PEEKUSER, pid, bad_request, bad_data);
-# ifdef IA64
+#ifdef IA64
printf("ptrace(PTRACE_PEEKUSER, %u, %#lx) = %s\n",
(unsigned) pid, bad_request, errstr);
-# else
+#else
printf("ptrace(PTRACE_PEEKUSER, %u, %#lx, %#lx) = %s\n",
(unsigned) pid, bad_request, bad_data, errstr);
#endif
printf("ptrace(PTRACE_SECCOMP_GET_FILTER, %u, 42, NULL) = %s\n",
(unsigned) pid, errstr);
+ do_ptrace(PTRACE_SECCOMP_GET_METADATA, pid, bad_data, 0);
+ printf("ptrace(PTRACE_SECCOMP_GET_METADATA, %u, %lu, NULL) = %s\n",
+ (unsigned) pid, bad_data, errstr);
+
+ do_ptrace(PTRACE_SECCOMP_GET_METADATA, pid, 7,
+ (unsigned long) filter_off);
+ printf("ptrace(PTRACE_SECCOMP_GET_METADATA, %u, 7, %p) = %s\n",
+ (unsigned) pid, filter_off, errstr);
+
+ *filter_off = 0xfacefeeddeadc0deULL;
+ do_ptrace(PTRACE_SECCOMP_GET_METADATA, pid, bad_data,
+ (unsigned long) filter_off);
+ printf("ptrace(PTRACE_SECCOMP_GET_METADATA, %u, %lu, "
+ "{filter_off=%" PRIu64 "}) = %s\n",
+ (unsigned) pid, bad_data, *filter_off, errstr);
+
do_ptrace(PTRACE_GETEVENTMSG, pid, bad_request, bad_data);
printf("ptrace(PTRACE_GETEVENTMSG, %u, %#lx, %#lx) = %s\n",
(unsigned) pid, bad_request, bad_data, errstr);
" = %s\n",
(unsigned) pid, bad_request, sip->si_call_addr, sip->si_syscall,
errstr);
+
+ sip->si_errno = 3141592653U;
+ sip->si_call_addr = NULL;
+ sip->si_syscall = __NR_read;
+ sip->si_arch = 0xda7a1057;
+
+ 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=%d, si_call_addr=NULL"
+ ", si_syscall=__NR_read, si_arch=%#x /* AUDIT_ARCH_??? */})"
+ " = %s\n",
+ (unsigned) pid, bad_request, sip->si_errno, sip->si_arch,
+ errstr);
#endif
#if defined HAVE_SIGINFO_T_SI_TIMERID && defined HAVE_SIGINFO_T_SI_OVERRUN
puts("+++ exited with 0 +++");
return 0;
}
-
-
-#else
-
-SKIP_MAIN_UNDEFINED("__NR_rt_sigprocmask")
-
-#endif