From 2720a618320b1ae697e2f7deec4c2da14ac55b58 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Sat, 9 Jan 2016 00:06:06 +0000 Subject: [PATCH] alpha: enhance decoding of getxpid, getxuid, and getxgid syscalls Print the second return value of getxpid, getxuid, and getxgid syscalls that return a pair of values using the same mechanism as pipe syscall. * alpha.c: New file. * Makefile.am (strace_SOURCES): Add it. * linux/alpha/syscallent.h [20]: Change SEN(getpid) to SEN(getxpid). [24]: Change SEN(getuid) to SEN(getxuid). [47]: Change SEN(getgid) to SEN(getxgid). * NEWS: Mention this enhancement. * tests/uid.awk: Update for getxgid output change. * tests/uid.test: Cleanup. * tests/getxxid.c: New file. * tests/getxxid.test: New test. * tests/Makefile.am (check_PROGRAMS): Add getxxid. (TESTS): Add getxxid.test. * tests/.gitignore: Add getxxid. --- Makefile.am | 1 + NEWS | 1 + alpha.c | 63 ++++++++++++++++++++++++++++++++++++++++ linux/alpha/syscallent.h | 6 ++-- tests/.gitignore | 1 + tests/Makefile.am | 2 ++ tests/getxxid.c | 61 ++++++++++++++++++++++++++++++++++++++ tests/getxxid.test | 13 +++++++++ tests/uid.awk | 9 ++++-- tests/uid.test | 15 ++++------ 10 files changed, 157 insertions(+), 15 deletions(-) create mode 100644 alpha.c create mode 100644 tests/getxxid.c create mode 100755 tests/getxxid.test diff --git a/Makefile.am b/Makefile.am index d43608d9..b107235f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -64,6 +64,7 @@ strace_SOURCES = \ access.c \ affinity.c \ aio.c \ + alpha.c \ bjm.c \ block.c \ bpf.c \ diff --git a/NEWS b/NEWS index 731b4d47..eefd0662 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,7 @@ Noteworthy changes in release ?.?? (????-??-??) * Improvements * Enhanced decoding of personality, sched_getaffinity, and sched_setaffinity syscalls. + * Enhanced decoding of getxpid, getxuid, and getxgid syscalls on alpha. * Bug fixes * Fixed build on arc, metag, nios2, or1k, and tile architectures. diff --git a/alpha.c b/alpha.c new file mode 100644 index 00000000..e343b7eb --- /dev/null +++ b/alpha.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2016 Dmitry V. Levin + * 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 "defs.h" + +#ifdef ALPHA + +static int +decode_getxxid(struct tcb *tcp, const char *what) +{ + if (entering(tcp)) + return 0; + + long rval = getrval2(tcp); + if (rval == -1) + return 0; + static const char const fmt[] = "%s %ld"; + static char outstr[sizeof(fmt) + 3 * sizeof(rval)]; + snprintf(outstr, sizeof(outstr), fmt, what, rval); + tcp->auxstr = outstr; + return RVAL_STR; +} + +SYS_FUNC(getxpid) +{ + return decode_getxxid(tcp, "ppid"); +} + +SYS_FUNC(getxuid) +{ + return decode_getxxid(tcp, "euid"); +} + +SYS_FUNC(getxgid) +{ + return decode_getxxid(tcp, "egid"); +} + +#endif /* ALPHA */ diff --git a/linux/alpha/syscallent.h b/linux/alpha/syscallent.h index 026c1cf7..c622e618 100644 --- a/linux/alpha/syscallent.h +++ b/linux/alpha/syscallent.h @@ -46,11 +46,11 @@ [ 17] = { 1, TM|SI, SEN(brk), "brk" }, [ 18] = { 5, 0, SEN(printargs), "osf_getfsstat" }, /*not implemented */ [ 19] = { 3, TD, SEN(lseek), "lseek" }, -[ 20] = { 0, NF, SEN(getpid), "getxpid" }, +[ 20] = { 0, NF, SEN(getxpid), "getxpid" }, [ 21] = { 4, 0, SEN(printargs), "osf_mount" }, [ 22] = { 2, TF, SEN(umount2), "umount" }, [ 23] = { 1, 0, SEN(setuid), "setuid" }, -[ 24] = { 0, NF, SEN(getuid), "getxuid" }, +[ 24] = { 0, NF, SEN(getxuid), "getxuid" }, [ 25] = { 5, 0, SEN(printargs), "exec_with_loader" }, /*not implemented */ [ 26] = { 4, 0, SEN(ptrace), "ptrace" }, [ 27] = { 5, 0, SEN(printargs), "osf_nrecvmsg" }, /*not implemented */ @@ -73,7 +73,7 @@ [ 44] = { 5, 0, SEN(printargs), "osf_profil" }, /*not implemented */ [ 45] = { 3, TD|TF, SEN(open), "open" }, [ 46] = { 5, 0, SEN(printargs), "osf_old_sigaction" }, /*not implemented */ -[ 47] = { 1, NF, SEN(getgid), "getxgid" }, +[ 47] = { 1, NF, SEN(getxgid), "getxgid" }, [ 48] = { 2, TS, SEN(sigprocmask), "osf_sigprocmask" }, [ 49] = { 5, 0, SEN(printargs), "osf_getlogin" }, /*not implemented */ [ 50] = { 5, 0, SEN(printargs), "osf_setlogin" }, /*not implemented */ diff --git a/tests/.gitignore b/tests/.gitignore index cfe1e9fb..6188bddd 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -30,6 +30,7 @@ ftruncate64 getdents getdents64 getrandom +getxxid inet-accept-connect-send-recv inet-cmsg ioctl diff --git a/tests/Makefile.am b/tests/Makefile.am index 33f76cbc..ab46af16 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -76,6 +76,7 @@ check_PROGRAMS = \ getdents \ getdents64 \ getrandom \ + getxxid \ inet-accept-connect-send-recv \ inet-cmsg \ ioctl \ @@ -213,6 +214,7 @@ TESTS = \ getdents.test \ getdents64.test \ getrandom.test \ + getxxid.test \ inet-cmsg.test \ ioctl.test \ ip_mreq.test \ diff --git a/tests/getxxid.c b/tests/getxxid.c new file mode 100644 index 00000000..1f2076c2 --- /dev/null +++ b/tests/getxxid.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2016 Dmitry V. Levin + * 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 + +#if defined __NR_getxpid && defined __NR_getxuid && defined __NR_getxgid + +# include +# include + +int +main(void) +{ + long id; + pid_t ppid; + + id = syscall(__NR_getxpid); + ppid = getppid(); + printf("getxpid() = %ld (ppid %ld)\n", id, (long) ppid); + printf("getxpid() = %ld (ppid %ld)\n", id, (long) ppid); + + id = syscall(__NR_getxuid); + printf("getxuid() = %ld (euid %ld)\n", id, id); + + id = syscall(__NR_getxgid); + printf("getxgid() = %ld (egid %ld)\n", id, id); + + puts("+++ exited with 0 +++"); + return 0; +} + +#else + +SKIP_MAIN_UNDEFINED("__NR_getxpid && __NR_getxuid && __NR_getxgid") + +#endif diff --git a/tests/getxxid.test b/tests/getxxid.test new file mode 100755 index 00000000..d6a206a2 --- /dev/null +++ b/tests/getxxid.test @@ -0,0 +1,13 @@ +#!/bin/sh + +# Check getxpid, getxuid, and getxgid syscalls decoding. + +. "${srcdir=.}/init.sh" + +run_prog > /dev/null +OUT="$LOG.out" +run_strace -a10 -egetxpid,getxuid,getxgid $args > "$OUT" +match_diff "$LOG" "$OUT" +rm -f "$OUT" + +exit 0 diff --git a/tests/uid.awk b/tests/uid.awk index a56c5be8..a5fdf1aa 100644 --- a/tests/uid.awk +++ b/tests/uid.awk @@ -27,7 +27,9 @@ BEGIN { r_uint = "(0|[1-9][0-9]*)" - regexp = "^getx?uid" suffix "\\(\\)[[:space:]]+= " r_uint "$" + r_getuid = "getuid" suffix "\\(\\)[[:space:]]+= " r_uint + r_getxuid = "getxuid" suffix "\\(\\)[[:space:]]+= " r_uint " \\(euid " r_uint "\\)" + regexp = "^(" r_getuid "|" r_getxuid ")$" expected = "getuid" fail = 0 } @@ -40,7 +42,10 @@ regexp == "" { { if (match($0, regexp, a)) { if (expected == "getuid") { - uid = a[1] + if ("" != a[2]) + uid = a[2] + else + uid = a[3] expected = "setuid" regexp = "^setuid" suffix "\\(" uid "\\)[[:space:]]+= 0$" } else if (expected == "setuid") { diff --git a/tests/uid.test b/tests/uid.test index e214272d..9c5a97f8 100755 --- a/tests/uid.test +++ b/tests/uid.test @@ -9,17 +9,12 @@ w="${uid_t_size-}" run_prog ./uid$s$w -syscalls= -for n in "getuid$s" "getxuid$s"; do - if $STRACE -e "$n" -h > /dev/null; then - syscalls="$n" - break - fi -done -test -n "$syscalls" || - fail_ "neither getuid$s nor getxuid$s is supported on this architecture" +case "$STRACE_ARCH" in + alpha) getuid=getxuid ;; + *) getuid=getuid ;; +esac -syscalls="$syscalls,setuid$s,getresuid$s,setreuid$s,setresuid$s,fchown$s,getgroups$s" +syscalls="$getuid$s,setuid$s,getresuid$s,setreuid$s,setresuid$s,fchown$s,getgroups$s" run_strace -e trace="$syscalls" $args AWK=gawk