1 /* 2 * Check decoding of inotify_add_watch and inotify_rm_watch syscalls. 3 * 4 * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr (at) gmail.com> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. The name of the author may not be used to endorse or promote products 16 * derived from this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 #include "tests.h" 31 32 #include <asm/unistd.h> 33 34 #if defined(__NR_inotify_add_watch) && defined(__NR_inotify_rm_watch) 35 36 # include <stdio.h> 37 # include <string.h> 38 # include <unistd.h> 39 40 int 41 main(void) 42 { 43 static const struct { 44 const char *path; 45 const char *str; 46 } bogus_path_str = { 47 ARG_STR("/abc\1/def\2/ghi\3/jkl\4/mno\5/pqr\6/stu\7/vwx\10") }; 48 static const kernel_ulong_t bogus_fd = 49 (kernel_ulong_t) 0xfffffeedfffffaceULL; 50 static const kernel_ulong_t bogus_mask = 51 (kernel_ulong_t) 0xffffda7affffdeadULL; 52 static const char *bogus_mask_str = "IN_ACCESS|IN_ATTRIB|" 53 "IN_CLOSE_WRITE|IN_OPEN|IN_MOVED_TO|IN_DELETE|IN_DELETE_SELF|" 54 "IN_MOVE_SELF|IN_Q_OVERFLOW|IN_IGNORED|IN_ONLYDIR|" 55 "IN_DONT_FOLLOW|IN_EXCL_UNLINK|IN_MASK_ADD|IN_ISDIR|IN_ONESHOT|" 56 "0x18ff1000"; 57 58 long rc; 59 char *bogus_path = tail_memdup(bogus_path_str.path, 60 strlen(bogus_path_str.path) + 1); 61 62 rc = syscall(__NR_inotify_add_watch, 0, NULL, 0); 63 printf("inotify_add_watch(0, NULL, 0) = %s\n", sprintrc(rc)); 64 65 rc = syscall(__NR_inotify_add_watch, bogus_fd, bogus_path + 4096, 0); 66 printf("inotify_add_watch(%d, %p, %u) = %s\n", 67 (int) bogus_fd, bogus_path + 4096, 0, sprintrc(rc)); 68 69 rc = syscall(__NR_inotify_add_watch, bogus_fd, bogus_path, bogus_mask); 70 printf("inotify_add_watch(%d, %s, %s) = %s\n", 71 (int) bogus_fd, bogus_path_str.str, bogus_mask_str, 72 sprintrc(rc)); 73 74 rc = syscall(__NR_inotify_rm_watch, 0, 0); 75 printf("inotify_rm_watch(0, 0) = %s\n", sprintrc(rc)); 76 77 rc = syscall(__NR_inotify_rm_watch, bogus_fd, bogus_fd); 78 printf("inotify_rm_watch(%d, %d) = %s\n", 79 (int) bogus_fd, (int) bogus_fd, sprintrc(rc)); 80 81 puts("+++ exited with 0 +++"); 82 83 return 0; 84 } 85 86 #else 87 88 SKIP_MAIN_UNDEFINED("__NR_inotify_add_watch && __NR_inotify_rm_watch"); 89 90 #endif 91