Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 The Chromium OS Authors. |
Elliott Hughes | 28e98bc | 2018-06-14 16:59:04 -0700 | [diff] [blame] | 3 | * Copyright (c) 2012-2018 The strace developers. |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 4 | * Written by Mike Frysinger <vapier@gentoo.org>. |
| 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 | #include "defs.h" |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 30 | #include <linux/ioctl.h> |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 31 | #include <linux/loop.h> |
| 32 | |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 33 | typedef struct loop_info struct_loop_info; |
| 34 | |
| 35 | #include DEF_MPERS_TYPE(struct_loop_info) |
| 36 | |
| 37 | #include MPERS_DEFS |
| 38 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 39 | #include "print_fields.h" |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 40 | #include "xlat/loop_cmds.h" |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 41 | #include "xlat/loop_flags_options.h" |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 42 | #include "xlat/loop_crypt_type_options.h" |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 43 | |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 44 | static void |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 45 | decode_loop_info(struct tcb *const tcp, const kernel_ulong_t addr) |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 46 | { |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 47 | struct_loop_info info; |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 48 | |
| 49 | tprints(", "); |
| 50 | if (umove_or_printaddr(tcp, addr, &info)) |
| 51 | return; |
| 52 | |
Dmitry V. Levin | 25129ac | 2016-05-29 22:28:28 +0000 | [diff] [blame] | 53 | tprintf("{lo_number=%d", info.lo_number); |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 54 | |
| 55 | if (!abbrev(tcp)) { |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 56 | PRINT_FIELD_DEV(", ", info, lo_device); |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 57 | tprintf(", lo_inode=%" PRI_klu, (kernel_ulong_t) info.lo_inode); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 58 | PRINT_FIELD_DEV(", ", info, lo_rdevice); |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 59 | } |
| 60 | |
Dmitry V. Levin | 25129ac | 2016-05-29 22:28:28 +0000 | [diff] [blame] | 61 | tprintf(", lo_offset=%#x", info.lo_offset); |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 62 | |
| 63 | if (!abbrev(tcp) || info.lo_encrypt_type != LO_CRYPT_NONE) { |
Dmitry V. Levin | 25129ac | 2016-05-29 22:28:28 +0000 | [diff] [blame] | 64 | tprints(", lo_encrypt_type="); |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 65 | printxval(loop_crypt_type_options, info.lo_encrypt_type, |
| 66 | "LO_CRYPT_???"); |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 67 | /* |
| 68 | * It is converted to unsigned before use in kernel, see |
| 69 | * loop_info64_from_old in drivers/block/loop.c |
| 70 | */ |
| 71 | tprintf(", lo_encrypt_key_size=%" PRIu32, |
| 72 | (uint32_t) info.lo_encrypt_key_size); |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 73 | } |
| 74 | |
Dmitry V. Levin | 25129ac | 2016-05-29 22:28:28 +0000 | [diff] [blame] | 75 | tprints(", lo_flags="); |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 76 | printflags(loop_flags_options, info.lo_flags, "LO_FLAGS_???"); |
| 77 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 78 | PRINT_FIELD_CSTRING(", ", info, lo_name); |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 79 | |
| 80 | if (!abbrev(tcp) || info.lo_encrypt_type != LO_CRYPT_NONE) { |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 81 | const unsigned int lo_encrypt_key_size = |
| 82 | MIN((unsigned) info.lo_encrypt_key_size, LO_KEY_SIZE); |
| 83 | PRINT_FIELD_STRING(", ", info, lo_encrypt_key, |
| 84 | lo_encrypt_key_size, 0); |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | if (!abbrev(tcp)) |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 88 | tprintf(", lo_init=[%#" PRI_klx ", %#" PRI_klx "]" |
| 89 | ", reserved=[%#hhx, %#hhx, %#hhx, %#hhx]}", |
| 90 | (kernel_ulong_t) info.lo_init[0], |
| 91 | (kernel_ulong_t) info.lo_init[1], |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 92 | info.reserved[0], info.reserved[1], |
| 93 | info.reserved[2], info.reserved[3]); |
| 94 | else |
| 95 | tprints(", ...}"); |
| 96 | } |
| 97 | |
| 98 | static void |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 99 | decode_loop_info64(struct tcb *const tcp, const kernel_ulong_t addr) |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 100 | { |
| 101 | struct loop_info64 info64; |
| 102 | |
| 103 | tprints(", "); |
| 104 | if (umove_or_printaddr(tcp, addr, &info64)) |
| 105 | return; |
| 106 | |
| 107 | if (!abbrev(tcp)) { |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 108 | PRINT_FIELD_DEV("{", info64, lo_device); |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 109 | tprintf(", lo_inode=%" PRIu64, (uint64_t) info64.lo_inode); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 110 | PRINT_FIELD_DEV(", ", info64, lo_rdevice); |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 111 | tprintf(", lo_offset=%#" PRIx64 ", lo_sizelimit=%" PRIu64 |
| 112 | ", lo_number=%" PRIu32, |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 113 | (uint64_t) info64.lo_offset, |
| 114 | (uint64_t) info64.lo_sizelimit, |
| 115 | (uint32_t) info64.lo_number); |
| 116 | } else { |
Dmitry V. Levin | 25129ac | 2016-05-29 22:28:28 +0000 | [diff] [blame] | 117 | tprintf("{lo_offset=%#" PRIx64 ", lo_number=%" PRIu32, |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 118 | (uint64_t) info64.lo_offset, |
| 119 | (uint32_t) info64.lo_number); |
| 120 | } |
| 121 | |
| 122 | if (!abbrev(tcp) || info64.lo_encrypt_type != LO_CRYPT_NONE) { |
Dmitry V. Levin | 25129ac | 2016-05-29 22:28:28 +0000 | [diff] [blame] | 123 | tprints(", lo_encrypt_type="); |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 124 | printxval(loop_crypt_type_options, info64.lo_encrypt_type, |
| 125 | "LO_CRYPT_???"); |
Dmitry V. Levin | 25129ac | 2016-05-29 22:28:28 +0000 | [diff] [blame] | 126 | tprintf(", lo_encrypt_key_size=%" PRIu32, |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 127 | info64.lo_encrypt_key_size); |
| 128 | } |
| 129 | |
Dmitry V. Levin | 25129ac | 2016-05-29 22:28:28 +0000 | [diff] [blame] | 130 | tprints(", lo_flags="); |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 131 | printflags(loop_flags_options, info64.lo_flags, "LO_FLAGS_???"); |
| 132 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 133 | PRINT_FIELD_CSTRING(", ", info64, lo_file_name); |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 134 | |
| 135 | if (!abbrev(tcp) || info64.lo_encrypt_type != LO_CRYPT_NONE) { |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 136 | PRINT_FIELD_CSTRING(", ", info64, lo_crypt_name); |
| 137 | const unsigned int lo_encrypt_key_size = |
| 138 | MIN((unsigned) info64.lo_encrypt_key_size, LO_KEY_SIZE); |
| 139 | PRINT_FIELD_STRING(", ", info64, lo_encrypt_key, |
| 140 | lo_encrypt_key_size, 0); |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | if (!abbrev(tcp)) |
Dmitry V. Levin | b7166a6 | 2016-05-29 22:34:30 +0000 | [diff] [blame] | 144 | tprintf(", lo_init=[%#" PRIx64 ", %#" PRIx64 "]}", |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 145 | (uint64_t) info64.lo_init[0], |
| 146 | (uint64_t) info64.lo_init[1]); |
| 147 | else |
| 148 | tprints(", ...}"); |
| 149 | } |
| 150 | |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 151 | MPERS_PRINTER_DECL(int, loop_ioctl, |
| 152 | struct tcb *tcp, const unsigned int code, |
| 153 | const kernel_ulong_t arg) |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 154 | { |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 155 | switch (code) { |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 156 | case LOOP_GET_STATUS: |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 157 | if (entering(tcp)) |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 158 | return 0; |
Elliott Hughes | 28e98bc | 2018-06-14 16:59:04 -0700 | [diff] [blame] | 159 | ATTRIBUTE_FALLTHROUGH; |
Dmitry V. Levin | bece24d | 2016-05-29 22:15:53 +0000 | [diff] [blame] | 160 | case LOOP_SET_STATUS: |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 161 | decode_loop_info(tcp, arg); |
| 162 | break; |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 163 | |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 164 | case LOOP_GET_STATUS64: |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 165 | if (entering(tcp)) |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 166 | return 0; |
Elliott Hughes | 28e98bc | 2018-06-14 16:59:04 -0700 | [diff] [blame] | 167 | ATTRIBUTE_FALLTHROUGH; |
Dmitry V. Levin | bece24d | 2016-05-29 22:15:53 +0000 | [diff] [blame] | 168 | case LOOP_SET_STATUS64: |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 169 | decode_loop_info64(tcp, arg); |
| 170 | break; |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 171 | |
| 172 | case LOOP_CLR_FD: |
| 173 | case LOOP_SET_CAPACITY: |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 174 | /* newer loop-control stuff */ |
| 175 | case LOOP_CTL_GET_FREE: |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 176 | /* Takes no arguments */ |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 177 | break; |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 178 | |
| 179 | case LOOP_SET_FD: |
| 180 | case LOOP_CHANGE_FD: |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 181 | tprints(", "); |
| 182 | printfd(tcp, arg); |
| 183 | break; |
| 184 | |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 185 | /* newer loop-control stuff */ |
| 186 | case LOOP_CTL_ADD: |
| 187 | case LOOP_CTL_REMOVE: |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 188 | tprintf(", %d", (int) arg); |
| 189 | break; |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 190 | |
Dmitry V. Levin | 4b9fa90 | 2016-05-29 22:58:56 +0000 | [diff] [blame] | 191 | case LOOP_SET_DIRECT_IO: |
Elliott Hughes | bbf97dc | 2017-11-15 16:45:52 -0800 | [diff] [blame] | 192 | case LOOP_SET_BLOCK_SIZE: |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 193 | tprintf(", %" PRI_klu, arg); |
Dmitry V. Levin | 4b9fa90 | 2016-05-29 22:58:56 +0000 | [diff] [blame] | 194 | break; |
Dmitry V. Levin | 4b9fa90 | 2016-05-29 22:58:56 +0000 | [diff] [blame] | 195 | |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 196 | default: |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 197 | return RVAL_DECODED; |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 198 | } |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 199 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 200 | return RVAL_IOCTL_DECODED; |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 201 | } |