Dmitry V. Levin | 38a34c9 | 2015-12-17 17:56:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl> |
| 3 | * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl> |
| 4 | * Copyright (c) 1993-1996 Rick Sladkey <jrs@world.std.com> |
| 5 | * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl> |
| 6 | * Copyright (c) 2003-2015 Dmitry V. Levin <ldv@altlinux.org> |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Redistribution and use in source and binary forms, with or without |
| 10 | * modification, are permitted provided that the following conditions |
| 11 | * are met: |
| 12 | * 1. Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * 2. Redistributions in binary form must reproduce the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer in the |
| 16 | * documentation and/or other materials provided with the distribution. |
| 17 | * 3. The name of the author may not be used to endorse or promote products |
| 18 | * derived from this software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 23 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 24 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 29 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | */ |
| 31 | |
Dmitry V. Levin | 80f7db1 | 2014-12-13 21:49:01 +0000 | [diff] [blame] | 32 | #ifdef STRACE_UID_SIZE |
| 33 | # if STRACE_UID_SIZE != 16 |
| 34 | # error invalid STRACE_UID_SIZE |
| 35 | # endif |
| 36 | |
| 37 | # define SIZEIFY(x) SIZEIFY_(x,STRACE_UID_SIZE) |
| 38 | # define SIZEIFY_(x,size) SIZEIFY__(x,size) |
| 39 | # define SIZEIFY__(x,size) x ## size |
| 40 | |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 41 | # define printuid SIZEIFY(printuid) |
Dmitry V. Levin | 80f7db1 | 2014-12-13 21:49:01 +0000 | [diff] [blame] | 42 | # define sys_chown SIZEIFY(sys_chown) |
| 43 | # define sys_fchown SIZEIFY(sys_fchown) |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 44 | # define sys_getgroups SIZEIFY(sys_getgroups) |
| 45 | # define sys_getresuid SIZEIFY(sys_getresuid) |
| 46 | # define sys_getuid SIZEIFY(sys_getuid) |
| 47 | # define sys_setfsuid SIZEIFY(sys_setfsuid) |
| 48 | # define sys_setgroups SIZEIFY(sys_setgroups) |
| 49 | # define sys_setresuid SIZEIFY(sys_setresuid) |
| 50 | # define sys_setreuid SIZEIFY(sys_setreuid) |
| 51 | # define sys_setuid SIZEIFY(sys_setuid) |
Dmitry V. Levin | 80f7db1 | 2014-12-13 21:49:01 +0000 | [diff] [blame] | 52 | #endif /* STRACE_UID_SIZE */ |
| 53 | |
Dmitry V. Levin | e93ef1e | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 54 | #include "defs.h" |
| 55 | |
Dmitry V. Levin | 80f7db1 | 2014-12-13 21:49:01 +0000 | [diff] [blame] | 56 | #ifdef STRACE_UID_SIZE |
| 57 | # if !NEED_UID16_PARSERS |
| 58 | # undef STRACE_UID_SIZE |
| 59 | # endif |
| 60 | #else |
| 61 | # define STRACE_UID_SIZE 32 |
| 62 | #endif |
| 63 | |
| 64 | #ifdef STRACE_UID_SIZE |
| 65 | |
| 66 | # undef uid_t |
| 67 | # define uid_t uid_t_(STRACE_UID_SIZE) |
| 68 | # define uid_t_(size) uid_t__(size) |
| 69 | # define uid_t__(size) uint ## size ## _t |
Dmitry V. Levin | e93ef1e | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 70 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 71 | SYS_FUNC(getuid) |
Dmitry V. Levin | e93ef1e | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 72 | { |
Dmitry V. Levin | abfa939 | 2015-12-27 00:18:03 +0000 | [diff] [blame] | 73 | return RVAL_UDECIMAL | RVAL_DECODED; |
Dmitry V. Levin | e93ef1e | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 76 | SYS_FUNC(setfsuid) |
Dmitry V. Levin | e93ef1e | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 77 | { |
| 78 | if (entering(tcp)) |
| 79 | tprintf("%u", (uid_t) tcp->u_arg[0]); |
Dmitry V. Levin | abfa939 | 2015-12-27 00:18:03 +0000 | [diff] [blame] | 80 | |
| 81 | return RVAL_UDECIMAL | RVAL_DECODED; |
Dmitry V. Levin | e93ef1e | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 84 | SYS_FUNC(setuid) |
Dmitry V. Levin | e93ef1e | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 85 | { |
Dmitry V. Levin | 1427862 | 2015-07-16 00:01:25 +0000 | [diff] [blame] | 86 | printuid("", tcp->u_arg[0]); |
| 87 | |
| 88 | return RVAL_DECODED; |
Dmitry V. Levin | e93ef1e | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Dmitry V. Levin | 80f7db1 | 2014-12-13 21:49:01 +0000 | [diff] [blame] | 91 | static void |
| 92 | get_print_uid(struct tcb *tcp, const char *prefix, const long addr) |
| 93 | { |
| 94 | uid_t uid; |
| 95 | |
Dmitry V. Levin | 288a870 | 2015-07-15 23:37:31 +0000 | [diff] [blame] | 96 | tprints(prefix); |
| 97 | if (!umove_or_printaddr(tcp, addr, &uid)) |
| 98 | tprintf("[%u]", uid); |
Dmitry V. Levin | 80f7db1 | 2014-12-13 21:49:01 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 101 | SYS_FUNC(getresuid) |
Dmitry V. Levin | e93ef1e | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 102 | { |
Dmitry V. Levin | 288a870 | 2015-07-15 23:37:31 +0000 | [diff] [blame] | 103 | if (entering(tcp)) |
| 104 | return 0; |
| 105 | |
| 106 | get_print_uid(tcp, "", tcp->u_arg[0]); |
| 107 | get_print_uid(tcp, ", ", tcp->u_arg[1]); |
| 108 | get_print_uid(tcp, ", ", tcp->u_arg[2]); |
| 109 | |
Dmitry V. Levin | e93ef1e | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 110 | return 0; |
| 111 | } |
| 112 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 113 | SYS_FUNC(setreuid) |
Dmitry V. Levin | e93ef1e | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 114 | { |
Dmitry V. Levin | 1427862 | 2015-07-16 00:01:25 +0000 | [diff] [blame] | 115 | printuid("", tcp->u_arg[0]); |
| 116 | printuid(", ", tcp->u_arg[1]); |
| 117 | |
| 118 | return RVAL_DECODED; |
Dmitry V. Levin | e93ef1e | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 119 | } |
| 120 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 121 | SYS_FUNC(setresuid) |
Dmitry V. Levin | e93ef1e | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 122 | { |
Dmitry V. Levin | 1427862 | 2015-07-16 00:01:25 +0000 | [diff] [blame] | 123 | printuid("", tcp->u_arg[0]); |
| 124 | printuid(", ", tcp->u_arg[1]); |
| 125 | printuid(", ", tcp->u_arg[2]); |
| 126 | |
| 127 | return RVAL_DECODED; |
Dmitry V. Levin | e93ef1e | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 128 | } |
Dmitry V. Levin | 25ebe46 | 2014-12-13 16:02:22 +0000 | [diff] [blame] | 129 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 130 | SYS_FUNC(chown) |
Dmitry V. Levin | 2f7d020 | 2014-12-13 16:20:44 +0000 | [diff] [blame] | 131 | { |
Dmitry V. Levin | 1427862 | 2015-07-16 00:01:25 +0000 | [diff] [blame] | 132 | printpath(tcp, tcp->u_arg[0]); |
| 133 | printuid(", ", tcp->u_arg[1]); |
| 134 | printuid(", ", tcp->u_arg[2]); |
| 135 | |
| 136 | return RVAL_DECODED; |
Dmitry V. Levin | 2f7d020 | 2014-12-13 16:20:44 +0000 | [diff] [blame] | 137 | } |
| 138 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 139 | SYS_FUNC(fchown) |
Dmitry V. Levin | 2f7d020 | 2014-12-13 16:20:44 +0000 | [diff] [blame] | 140 | { |
Dmitry V. Levin | 1427862 | 2015-07-16 00:01:25 +0000 | [diff] [blame] | 141 | printfd(tcp, tcp->u_arg[0]); |
| 142 | printuid(", ", tcp->u_arg[1]); |
| 143 | printuid(", ", tcp->u_arg[2]); |
| 144 | |
| 145 | return RVAL_DECODED; |
Dmitry V. Levin | 2f7d020 | 2014-12-13 16:20:44 +0000 | [diff] [blame] | 146 | } |
| 147 | |
Dmitry V. Levin | 25ebe46 | 2014-12-13 16:02:22 +0000 | [diff] [blame] | 148 | void |
| 149 | printuid(const char *text, const unsigned int uid) |
| 150 | { |
Dmitry V. Levin | a99bcbf | 2016-04-14 23:53:08 +0000 | [diff] [blame] | 151 | if ((uid_t) -1U == (uid_t) uid) |
Dmitry V. Levin | 25ebe46 | 2014-12-13 16:02:22 +0000 | [diff] [blame] | 152 | tprintf("%s-1", text); |
| 153 | else |
Dmitry V. Levin | a99bcbf | 2016-04-14 23:53:08 +0000 | [diff] [blame] | 154 | tprintf("%s%u", text, (uid_t) uid); |
Dmitry V. Levin | 25ebe46 | 2014-12-13 16:02:22 +0000 | [diff] [blame] | 155 | } |
Dmitry V. Levin | 80f7db1 | 2014-12-13 21:49:01 +0000 | [diff] [blame] | 156 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 157 | SYS_FUNC(setgroups) |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 158 | { |
Dmitry V. Levin | 1427862 | 2015-07-16 00:01:25 +0000 | [diff] [blame] | 159 | unsigned long cur, abbrev_end; |
| 160 | uid_t gid; |
| 161 | int failed = 0; |
| 162 | const unsigned long len = tcp->u_arg[0]; |
| 163 | const unsigned long start = tcp->u_arg[1]; |
| 164 | const unsigned long size = len * sizeof(gid); |
| 165 | const unsigned long end = start + size; |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 166 | |
Dmitry V. Levin | 1427862 | 2015-07-16 00:01:25 +0000 | [diff] [blame] | 167 | tprintf("%lu, ", len); |
| 168 | if (len == 0) { |
| 169 | tprints("[]"); |
| 170 | return RVAL_DECODED; |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 171 | } |
Dmitry V. Levin | 1427862 | 2015-07-16 00:01:25 +0000 | [diff] [blame] | 172 | if (!start || !verbose(tcp) || |
| 173 | size / sizeof(gid) != len || end < start) { |
| 174 | printaddr(start); |
| 175 | return RVAL_DECODED; |
| 176 | } |
| 177 | if (abbrev(tcp)) { |
| 178 | abbrev_end = start + max_strlen * sizeof(gid); |
| 179 | if (abbrev_end < start) |
| 180 | abbrev_end = end; |
| 181 | } else { |
| 182 | abbrev_end = end; |
| 183 | } |
| 184 | tprints("["); |
| 185 | for (cur = start; cur < end; cur += sizeof(gid)) { |
| 186 | if (cur > start) |
| 187 | tprints(", "); |
| 188 | if (cur >= abbrev_end) { |
| 189 | tprints("..."); |
| 190 | break; |
| 191 | } |
| 192 | if (umoven(tcp, cur, sizeof(gid), &gid) < 0) { |
| 193 | tprints("?"); |
| 194 | failed = 1; |
| 195 | break; |
| 196 | } |
| 197 | tprintf("%u", (unsigned int) gid); |
| 198 | } |
| 199 | tprints("]"); |
| 200 | if (failed) { |
| 201 | tprints(" "); |
| 202 | printaddr(start); |
| 203 | } |
| 204 | |
| 205 | return RVAL_DECODED; |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 208 | SYS_FUNC(getgroups) |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 209 | { |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 210 | if (entering(tcp)) { |
Dmitry V. Levin | 288a870 | 2015-07-15 23:37:31 +0000 | [diff] [blame] | 211 | tprintf("%lu, ", tcp->u_arg[0]); |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 212 | } else { |
Dmitry V. Levin | 288a870 | 2015-07-15 23:37:31 +0000 | [diff] [blame] | 213 | unsigned long cur, abbrev_end; |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 214 | uid_t gid; |
| 215 | int failed = 0; |
Dmitry V. Levin | 288a870 | 2015-07-15 23:37:31 +0000 | [diff] [blame] | 216 | const unsigned long len = tcp->u_rval; |
| 217 | const unsigned long size = len * sizeof(gid); |
| 218 | const unsigned long start = tcp->u_arg[1]; |
| 219 | const unsigned long end = start + size; |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 220 | |
Dmitry V. Levin | 288a870 | 2015-07-15 23:37:31 +0000 | [diff] [blame] | 221 | if (!start) { |
| 222 | printaddr(start); |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 223 | return 0; |
| 224 | } |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 225 | if (len == 0) { |
| 226 | tprints("[]"); |
| 227 | return 0; |
| 228 | } |
Dmitry V. Levin | 288a870 | 2015-07-15 23:37:31 +0000 | [diff] [blame] | 229 | if (!verbose(tcp) || syserror(tcp) || |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 230 | size / sizeof(gid) != len || end < start) { |
Dmitry V. Levin | 288a870 | 2015-07-15 23:37:31 +0000 | [diff] [blame] | 231 | printaddr(start); |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 232 | return 0; |
| 233 | } |
| 234 | if (abbrev(tcp)) { |
| 235 | abbrev_end = start + max_strlen * sizeof(gid); |
| 236 | if (abbrev_end < start) |
| 237 | abbrev_end = end; |
| 238 | } else { |
| 239 | abbrev_end = end; |
| 240 | } |
| 241 | tprints("["); |
| 242 | for (cur = start; cur < end; cur += sizeof(gid)) { |
| 243 | if (cur > start) |
| 244 | tprints(", "); |
| 245 | if (cur >= abbrev_end) { |
| 246 | tprints("..."); |
| 247 | break; |
| 248 | } |
Denys Vlasenko | 7e69ed9 | 2015-03-21 19:50:53 +0100 | [diff] [blame] | 249 | if (umoven(tcp, cur, sizeof(gid), &gid) < 0) { |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 250 | tprints("?"); |
| 251 | failed = 1; |
| 252 | break; |
| 253 | } |
| 254 | tprintf("%u", (unsigned int) gid); |
| 255 | } |
| 256 | tprints("]"); |
Dmitry V. Levin | 288a870 | 2015-07-15 23:37:31 +0000 | [diff] [blame] | 257 | if (failed) { |
| 258 | tprints(" "); |
| 259 | printaddr(start); |
| 260 | } |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 261 | } |
| 262 | return 0; |
| 263 | } |
| 264 | |
Dmitry V. Levin | 80f7db1 | 2014-12-13 21:49:01 +0000 | [diff] [blame] | 265 | #endif /* STRACE_UID_SIZE */ |