Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 1 | /* |
Elliott Hughes | 39bac05 | 2017-05-25 16:56:11 -0700 | [diff] [blame] | 2 | * Copyright (c) 2011 Comtrol Corp. |
Elliott Hughes | b755614 | 2018-02-20 17:03:16 -0800 | [diff] [blame] | 3 | * Copyright (c) 2011-2018 The strace developers. |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions |
| 8 | * are met: |
| 9 | * 1. Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * 2. Redistributions in binary form must reproduce the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer in the |
| 13 | * documentation and/or other materials provided with the distribution. |
| 14 | * 3. The name of the author may not be used to endorse or promote products |
| 15 | * derived from this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | * |
| 28 | */ |
| 29 | |
| 30 | #include "defs.h" |
Elliott Hughes | b755614 | 2018-02-20 17:03:16 -0800 | [diff] [blame] | 31 | #include <limits.h> |
Dmitry V. Levin | 80d5e01 | 2015-07-30 16:23:58 +0000 | [diff] [blame] | 32 | #include <poll.h> |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 33 | |
| 34 | #include "syscall.h" |
Elliott Hughes | b755614 | 2018-02-20 17:03:16 -0800 | [diff] [blame] | 35 | #include "xstring.h" |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 36 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 37 | struct path_set global_path_set; |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 38 | |
| 39 | /* |
| 40 | * Return true if specified path matches one that we're tracing. |
| 41 | */ |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 42 | static bool |
| 43 | pathmatch(const char *path, struct path_set *set) |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 44 | { |
Denys Vlasenko | 7239dbc | 2013-03-05 15:46:34 +0100 | [diff] [blame] | 45 | unsigned i; |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 46 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 47 | for (i = 0; i < set->num_selected; ++i) { |
| 48 | if (strcmp(path, set->paths_selected[i]) == 0) |
| 49 | return true; |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 50 | } |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 51 | return false; |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | /* |
| 55 | * Return true if specified path (in user-space) matches. |
| 56 | */ |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 57 | static bool |
| 58 | upathmatch(struct tcb *const tcp, const kernel_ulong_t upath, |
| 59 | struct path_set *set) |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 60 | { |
Denys Vlasenko | 7b609d5 | 2011-06-22 14:32:43 +0200 | [diff] [blame] | 61 | char path[PATH_MAX + 1]; |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 62 | |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 63 | return umovestr(tcp, upath, sizeof(path), path) > 0 && |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 64 | pathmatch(path, set); |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | /* |
| 68 | * Return true if specified fd maps to a path we're tracing. |
| 69 | */ |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 70 | static bool |
| 71 | fdmatch(struct tcb *tcp, int fd, struct path_set *set) |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 72 | { |
Denys Vlasenko | 61ad0a4 | 2013-03-06 18:24:34 +0100 | [diff] [blame] | 73 | char path[PATH_MAX + 1]; |
| 74 | int n = getfdpath(tcp, fd, path, sizeof(path)); |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 75 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 76 | return n >= 0 && pathmatch(path, set); |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /* |
| 80 | * Add a path to the set we're tracing. |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 81 | * Specifying NULL will delete all paths. |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 82 | */ |
Denys Vlasenko | 7239dbc | 2013-03-05 15:46:34 +0100 | [diff] [blame] | 83 | static void |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 84 | storepath(const char *path, struct path_set *set) |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 85 | { |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 86 | if (pathmatch(path, set)) |
Denys Vlasenko | 7239dbc | 2013-03-05 15:46:34 +0100 | [diff] [blame] | 87 | return; /* already in table */ |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 88 | |
Elliott Hughes | b755614 | 2018-02-20 17:03:16 -0800 | [diff] [blame] | 89 | if (set->num_selected >= set->size) |
| 90 | set->paths_selected = |
| 91 | xgrowarray(set->paths_selected, &set->size, |
| 92 | sizeof(set->paths_selected[0])); |
| 93 | |
| 94 | set->paths_selected[set->num_selected++] = path; |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | /* |
| 98 | * Get path associated with fd. |
| 99 | */ |
Denys Vlasenko | 61ad0a4 | 2013-03-06 18:24:34 +0100 | [diff] [blame] | 100 | int |
| 101 | getfdpath(struct tcb *tcp, int fd, char *buf, unsigned bufsize) |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 102 | { |
Denys Vlasenko | 384b0ad | 2012-03-15 18:11:51 +0100 | [diff] [blame] | 103 | char linkpath[sizeof("/proc/%u/fd/%u") + 2 * sizeof(int)*3]; |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 104 | ssize_t n; |
| 105 | |
| 106 | if (fd < 0) |
Denys Vlasenko | 61ad0a4 | 2013-03-06 18:24:34 +0100 | [diff] [blame] | 107 | return -1; |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 108 | |
Elliott Hughes | b755614 | 2018-02-20 17:03:16 -0800 | [diff] [blame] | 109 | xsprintf(linkpath, "/proc/%u/fd/%u", tcp->pid, fd); |
Denys Vlasenko | 61ad0a4 | 2013-03-06 18:24:34 +0100 | [diff] [blame] | 110 | n = readlink(linkpath, buf, bufsize - 1); |
| 111 | /* |
| 112 | * NB: if buf is too small, readlink doesn't fail, |
| 113 | * it returns truncated result (IOW: n == bufsize - 1). |
| 114 | */ |
| 115 | if (n >= 0) |
| 116 | buf[n] = '\0'; |
| 117 | return n; |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | /* |
| 121 | * Add a path to the set we're tracing. Also add the canonicalized |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 122 | * version of the path. Specifying NULL will delete all paths. |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 123 | */ |
Denys Vlasenko | 7239dbc | 2013-03-05 15:46:34 +0100 | [diff] [blame] | 124 | void |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 125 | pathtrace_select_set(const char *path, struct path_set *set) |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 126 | { |
Denys Vlasenko | 29865e7 | 2012-03-15 18:03:56 +0100 | [diff] [blame] | 127 | char *rpath; |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 128 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 129 | storepath(path, set); |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 130 | |
| 131 | rpath = realpath(path, NULL); |
| 132 | |
| 133 | if (rpath == NULL) |
Denys Vlasenko | 7239dbc | 2013-03-05 15:46:34 +0100 | [diff] [blame] | 134 | return; |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 135 | |
| 136 | /* if realpath and specified path are same, we're done */ |
Denys Vlasenko | 29865e7 | 2012-03-15 18:03:56 +0100 | [diff] [blame] | 137 | if (strcmp(path, rpath) == 0) { |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 138 | free(rpath); |
Denys Vlasenko | 7239dbc | 2013-03-05 15:46:34 +0100 | [diff] [blame] | 139 | return; |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Dmitry V. Levin | 6c8ef05 | 2015-05-25 22:51:19 +0000 | [diff] [blame] | 142 | error_msg("Requested path '%s' resolved into '%s'", path, rpath); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 143 | storepath(rpath, set); |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Elliott Hughes | b755614 | 2018-02-20 17:03:16 -0800 | [diff] [blame] | 146 | static bool |
| 147 | match_xselect_args(struct tcb *tcp, const kernel_ulong_t *args, |
| 148 | struct path_set *set) |
| 149 | { |
| 150 | /* Kernel truncates arg[0] to int, we do the same. */ |
| 151 | int nfds = (int) args[0]; |
| 152 | /* Kernel rejects negative nfds, so we don't parse it either. */ |
| 153 | if (nfds <= 0) |
| 154 | return false; |
| 155 | /* Beware of select(2^31-1, NULL, NULL, NULL) and similar... */ |
| 156 | if (nfds > 1024*1024) |
| 157 | nfds = 1024*1024; |
| 158 | unsigned int fdsize = (((nfds + 7) / 8) + current_wordsize-1) & -current_wordsize; |
| 159 | fd_set *fds = xmalloc(fdsize); |
| 160 | |
| 161 | for (unsigned int i = 1; i <= 3; ++i) { |
| 162 | if (args[i] == 0) |
| 163 | continue; |
| 164 | if (umoven(tcp, args[i], fdsize, fds) < 0) |
| 165 | continue; |
| 166 | for (int j = 0;; ++j) { |
| 167 | j = next_set_bit(fds, j, nfds); |
| 168 | if (j < 0) |
| 169 | break; |
| 170 | if (fdmatch(tcp, j, set)) { |
| 171 | free(fds); |
| 172 | return true; |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | free(fds); |
| 178 | return false; |
| 179 | } |
| 180 | |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 181 | /* |
| 182 | * Return true if syscall accesses a selected path |
| 183 | * (or if no paths have been specified for tracing). |
| 184 | */ |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 185 | bool |
| 186 | pathtrace_match_set(struct tcb *tcp, struct path_set *set) |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 187 | { |
Denys Vlasenko | a9fe13c | 2013-02-22 13:26:10 +0100 | [diff] [blame] | 188 | const struct_sysent *s; |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 189 | |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 190 | s = tcp->s_ent; |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 191 | |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 192 | if (!(s->sys_flags & (TRACE_FILE | TRACE_DESC | TRACE_NETWORK))) |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 193 | return false; |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 194 | |
| 195 | /* |
| 196 | * Check for special cases where we need to do something |
| 197 | * other than test arg[0]. |
| 198 | */ |
| 199 | |
Elvira Khabirova | 483c15f | 2015-07-10 22:24:58 +0300 | [diff] [blame] | 200 | switch (s->sen) { |
| 201 | case SEN_dup2: |
| 202 | case SEN_dup3: |
Dmitry V. Levin | ea19705 | 2015-11-22 18:51:05 +0000 | [diff] [blame] | 203 | case SEN_kexec_file_load: |
Elvira Khabirova | 483c15f | 2015-07-10 22:24:58 +0300 | [diff] [blame] | 204 | case SEN_sendfile: |
| 205 | case SEN_sendfile64: |
| 206 | case SEN_tee: |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 207 | /* fd, fd */ |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 208 | return fdmatch(tcp, tcp->u_arg[0], set) || |
| 209 | fdmatch(tcp, tcp->u_arg[1], set); |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 210 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 211 | case SEN_execveat: |
Elvira Khabirova | 483c15f | 2015-07-10 22:24:58 +0300 | [diff] [blame] | 212 | case SEN_faccessat: |
| 213 | case SEN_fchmodat: |
| 214 | case SEN_fchownat: |
Dmitry V. Levin | c4da489 | 2016-08-23 14:27:49 +0000 | [diff] [blame] | 215 | case SEN_fstatat64: |
Elvira Khabirova | 483c15f | 2015-07-10 22:24:58 +0300 | [diff] [blame] | 216 | case SEN_futimesat: |
| 217 | case SEN_inotify_add_watch: |
| 218 | case SEN_mkdirat: |
| 219 | case SEN_mknodat: |
Dmitry V. Levin | 4b3a170 | 2015-11-22 21:29:32 +0000 | [diff] [blame] | 220 | case SEN_name_to_handle_at: |
Elvira Khabirova | 483c15f | 2015-07-10 22:24:58 +0300 | [diff] [blame] | 221 | case SEN_newfstatat: |
| 222 | case SEN_openat: |
Elvira Khabirova | 483c15f | 2015-07-10 22:24:58 +0300 | [diff] [blame] | 223 | case SEN_readlinkat: |
Elliott Hughes | 39bac05 | 2017-05-25 16:56:11 -0700 | [diff] [blame] | 224 | case SEN_statx: |
Elvira Khabirova | 483c15f | 2015-07-10 22:24:58 +0300 | [diff] [blame] | 225 | case SEN_unlinkat: |
| 226 | case SEN_utimensat: |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 227 | /* fd, path */ |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 228 | return fdmatch(tcp, tcp->u_arg[0], set) || |
| 229 | upathmatch(tcp, tcp->u_arg[1], set); |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 230 | |
Elvira Khabirova | 483c15f | 2015-07-10 22:24:58 +0300 | [diff] [blame] | 231 | case SEN_link: |
| 232 | case SEN_mount: |
| 233 | case SEN_pivotroot: |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 234 | /* path, path */ |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 235 | return upathmatch(tcp, tcp->u_arg[0], set) || |
| 236 | upathmatch(tcp, tcp->u_arg[1], set); |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 237 | |
Elvira Khabirova | 483c15f | 2015-07-10 22:24:58 +0300 | [diff] [blame] | 238 | case SEN_quotactl: |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 239 | case SEN_symlink: |
Dmitry V. Levin | 7943966 | 2012-10-26 23:43:13 +0000 | [diff] [blame] | 240 | /* x, path */ |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 241 | return upathmatch(tcp, tcp->u_arg[1], set); |
Dmitry V. Levin | 7943966 | 2012-10-26 23:43:13 +0000 | [diff] [blame] | 242 | |
Elvira Khabirova | 483c15f | 2015-07-10 22:24:58 +0300 | [diff] [blame] | 243 | case SEN_linkat: |
| 244 | case SEN_renameat2: |
| 245 | case SEN_renameat: |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 246 | /* fd, path, fd, path */ |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 247 | return fdmatch(tcp, tcp->u_arg[0], set) || |
| 248 | fdmatch(tcp, tcp->u_arg[2], set) || |
| 249 | upathmatch(tcp, tcp->u_arg[1], set) || |
| 250 | upathmatch(tcp, tcp->u_arg[3], set); |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 251 | |
Elliott Hughes | b755614 | 2018-02-20 17:03:16 -0800 | [diff] [blame] | 252 | #if HAVE_ARCH_OLD_MMAP |
Elvira Khabirova | 483c15f | 2015-07-10 22:24:58 +0300 | [diff] [blame] | 253 | case SEN_old_mmap: |
Elliott Hughes | b755614 | 2018-02-20 17:03:16 -0800 | [diff] [blame] | 254 | # if HAVE_ARCH_OLD_MMAP_PGOFF |
Elvira Khabirova | 483c15f | 2015-07-10 22:24:58 +0300 | [diff] [blame] | 255 | case SEN_old_mmap_pgoff: |
Elliott Hughes | b755614 | 2018-02-20 17:03:16 -0800 | [diff] [blame] | 256 | # endif |
| 257 | { |
| 258 | kernel_ulong_t *args = |
| 259 | fetch_indirect_syscall_args(tcp, tcp->u_arg[0], 6); |
| 260 | |
| 261 | return args && fdmatch(tcp, args[4], set); |
| 262 | } |
| 263 | #endif /* HAVE_ARCH_OLD_MMAP */ |
| 264 | |
Elvira Khabirova | 483c15f | 2015-07-10 22:24:58 +0300 | [diff] [blame] | 265 | case SEN_mmap: |
| 266 | case SEN_mmap_4koff: |
| 267 | case SEN_mmap_pgoff: |
Dmitry V. Levin | dd1a80c | 2015-12-24 15:40:55 +0000 | [diff] [blame] | 268 | case SEN_ARCH_mmap: |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 269 | /* x, x, x, x, fd */ |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 270 | return fdmatch(tcp, tcp->u_arg[4], set); |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 271 | |
Elvira Khabirova | 483c15f | 2015-07-10 22:24:58 +0300 | [diff] [blame] | 272 | case SEN_symlinkat: |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 273 | /* x, fd, path */ |
| 274 | return fdmatch(tcp, tcp->u_arg[1], set) || |
| 275 | upathmatch(tcp, tcp->u_arg[2], set); |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 276 | |
Dmitry V. Levin | c1f99f5 | 2016-02-13 03:45:32 +0000 | [diff] [blame] | 277 | case SEN_copy_file_range: |
Elvira Khabirova | 483c15f | 2015-07-10 22:24:58 +0300 | [diff] [blame] | 278 | case SEN_splice: |
Dmitry V. Levin | c1f99f5 | 2016-02-13 03:45:32 +0000 | [diff] [blame] | 279 | /* fd, x, fd, x, x, x */ |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 280 | return fdmatch(tcp, tcp->u_arg[0], set) || |
| 281 | fdmatch(tcp, tcp->u_arg[2], set); |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 282 | |
Elvira Khabirova | 483c15f | 2015-07-10 22:24:58 +0300 | [diff] [blame] | 283 | case SEN_epoll_ctl: |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 284 | /* x, x, fd, x */ |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 285 | return fdmatch(tcp, tcp->u_arg[2], set); |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 286 | |
Elvira Khabirova | 483c15f | 2015-07-10 22:24:58 +0300 | [diff] [blame] | 287 | |
| 288 | case SEN_fanotify_mark: |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 289 | { |
| 290 | /* x, x, mask (64 bit), fd, path */ |
| 291 | unsigned long long mask = 0; |
| 292 | int argn = getllval(tcp, &mask, 2); |
| 293 | return fdmatch(tcp, tcp->u_arg[argn], set) || |
| 294 | upathmatch(tcp, tcp->u_arg[argn + 1], set); |
| 295 | } |
Elliott Hughes | b755614 | 2018-02-20 17:03:16 -0800 | [diff] [blame] | 296 | #if HAVE_ARCH_OLD_SELECT |
Elvira Khabirova | 483c15f | 2015-07-10 22:24:58 +0300 | [diff] [blame] | 297 | case SEN_oldselect: |
Elliott Hughes | b755614 | 2018-02-20 17:03:16 -0800 | [diff] [blame] | 298 | { |
| 299 | kernel_ulong_t *args = |
| 300 | fetch_indirect_syscall_args(tcp, tcp->u_arg[0], 5); |
| 301 | |
| 302 | return args && match_xselect_args(tcp, args, set); |
| 303 | } |
| 304 | #endif |
Elvira Khabirova | 483c15f | 2015-07-10 22:24:58 +0300 | [diff] [blame] | 305 | case SEN_pselect6: |
| 306 | case SEN_select: |
Elliott Hughes | b755614 | 2018-02-20 17:03:16 -0800 | [diff] [blame] | 307 | return match_xselect_args(tcp, tcp->u_arg, set); |
Elvira Khabirova | 483c15f | 2015-07-10 22:24:58 +0300 | [diff] [blame] | 308 | case SEN_poll: |
| 309 | case SEN_ppoll: |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 310 | { |
| 311 | struct pollfd fds; |
| 312 | unsigned nfds; |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 313 | kernel_ulong_t start, cur, end; |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 314 | |
| 315 | start = tcp->u_arg[0]; |
| 316 | nfds = tcp->u_arg[1]; |
| 317 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 318 | if (nfds > 1024 * 1024) |
| 319 | nfds = 1024 * 1024; |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 320 | end = start + sizeof(fds) * nfds; |
| 321 | |
| 322 | if (nfds == 0 || end < start) |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 323 | return false; |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 324 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 325 | for (cur = start; cur < end; cur += sizeof(fds)) { |
| 326 | if (umove(tcp, cur, &fds)) |
| 327 | break; |
| 328 | if (fdmatch(tcp, fds.fd, set)) |
| 329 | return true; |
| 330 | } |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 331 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 332 | return false; |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 333 | } |
| 334 | |
Elliott Hughes | b755614 | 2018-02-20 17:03:16 -0800 | [diff] [blame] | 335 | case SEN_accept4: |
| 336 | case SEN_accept: |
Dmitry V. Levin | ddb53dd | 2015-07-25 23:55:51 +0000 | [diff] [blame] | 337 | case SEN_bpf: |
Elvira Khabirova | 483c15f | 2015-07-10 22:24:58 +0300 | [diff] [blame] | 338 | case SEN_epoll_create: |
Dmitry V. Levin | 2716346 | 2015-08-01 23:07:19 +0000 | [diff] [blame] | 339 | case SEN_epoll_create1: |
Elvira Khabirova | 483c15f | 2015-07-10 22:24:58 +0300 | [diff] [blame] | 340 | case SEN_eventfd2: |
| 341 | case SEN_eventfd: |
| 342 | case SEN_fanotify_init: |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 343 | case SEN_inotify_init: |
Elvira Khabirova | 483c15f | 2015-07-10 22:24:58 +0300 | [diff] [blame] | 344 | case SEN_inotify_init1: |
Dmitry V. Levin | 95b84ea | 2015-07-28 23:03:41 +0000 | [diff] [blame] | 345 | case SEN_memfd_create: |
Elliott Hughes | b755614 | 2018-02-20 17:03:16 -0800 | [diff] [blame] | 346 | case SEN_mq_getsetattr: |
| 347 | case SEN_mq_notify: |
| 348 | case SEN_mq_open: |
| 349 | case SEN_mq_timedreceive: |
| 350 | case SEN_mq_timedsend: |
Elvira Khabirova | 483c15f | 2015-07-10 22:24:58 +0300 | [diff] [blame] | 351 | case SEN_perf_event_open: |
| 352 | case SEN_pipe: |
Dmitry V. Levin | f9f04f7 | 2016-02-12 16:15:23 +0000 | [diff] [blame] | 353 | case SEN_pipe2: |
Elvira Khabirova | 483c15f | 2015-07-10 22:24:58 +0300 | [diff] [blame] | 354 | case SEN_printargs: |
Elliott Hughes | b755614 | 2018-02-20 17:03:16 -0800 | [diff] [blame] | 355 | case SEN_signalfd4: |
| 356 | case SEN_signalfd: |
Elvira Khabirova | 483c15f | 2015-07-10 22:24:58 +0300 | [diff] [blame] | 357 | case SEN_socket: |
| 358 | case SEN_socketpair: |
| 359 | case SEN_timerfd_create: |
| 360 | case SEN_timerfd_gettime: |
| 361 | case SEN_timerfd_settime: |
Dmitry V. Levin | 87d64ed | 2015-11-22 19:56:00 +0000 | [diff] [blame] | 362 | case SEN_userfaultfd: |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 363 | /* |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 364 | * These have TRACE_FILE or TRACE_DESCRIPTOR or TRACE_NETWORK set, |
| 365 | * but they don't have any file descriptor or path args to test. |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 366 | */ |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 367 | return false; |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 368 | } |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 369 | |
| 370 | /* |
| 371 | * Our fallback position for calls that haven't already |
| 372 | * been handled is to just check arg[0]. |
| 373 | */ |
| 374 | |
| 375 | if (s->sys_flags & TRACE_FILE) |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 376 | return upathmatch(tcp, tcp->u_arg[0], set); |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 377 | |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 378 | if (s->sys_flags & (TRACE_DESC | TRACE_NETWORK)) |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 379 | return fdmatch(tcp, tcp->u_arg[0], set); |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 380 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 381 | return false; |
Grant Edwards | 8a08277 | 2011-04-07 20:25:40 +0000 | [diff] [blame] | 382 | } |