Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1 | /* |
Tharun Kumar Merugu | 55be90d | 2018-05-31 11:41:03 +0530 | [diff] [blame] | 2 | * Copyright (c) 2014-2018, The Linux Foundation. All rights reserved. |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 and |
| 6 | * only version 2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | */ |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 14 | #include <linux/compat.h> |
| 15 | #include <linux/fs.h> |
| 16 | #include <linux/uaccess.h> |
| 17 | #include <linux/msm_ion.h> |
| 18 | |
| 19 | #include "adsprpc_compat.h" |
| 20 | #include "adsprpc_shared.h" |
| 21 | |
| 22 | #define COMPAT_FASTRPC_IOCTL_INVOKE \ |
| 23 | _IOWR('R', 1, struct compat_fastrpc_ioctl_invoke) |
| 24 | #define COMPAT_FASTRPC_IOCTL_MMAP \ |
| 25 | _IOWR('R', 2, struct compat_fastrpc_ioctl_mmap) |
| 26 | #define COMPAT_FASTRPC_IOCTL_MUNMAP \ |
| 27 | _IOWR('R', 3, struct compat_fastrpc_ioctl_munmap) |
| 28 | #define COMPAT_FASTRPC_IOCTL_INVOKE_FD \ |
| 29 | _IOWR('R', 4, struct compat_fastrpc_ioctl_invoke_fd) |
| 30 | #define COMPAT_FASTRPC_IOCTL_INIT \ |
| 31 | _IOWR('R', 6, struct compat_fastrpc_ioctl_init) |
| 32 | #define COMPAT_FASTRPC_IOCTL_INVOKE_ATTRS \ |
| 33 | _IOWR('R', 7, struct compat_fastrpc_ioctl_invoke_attrs) |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 34 | #define COMPAT_FASTRPC_IOCTL_GETPERF \ |
| 35 | _IOWR('R', 9, struct compat_fastrpc_ioctl_perf) |
Sathish Ambley | d6300c3 | 2017-01-18 09:50:43 -0800 | [diff] [blame] | 36 | #define COMPAT_FASTRPC_IOCTL_INIT_ATTRS \ |
| 37 | _IOWR('R', 10, struct compat_fastrpc_ioctl_init_attrs) |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 38 | #define COMPAT_FASTRPC_IOCTL_INVOKE_CRC \ |
| 39 | _IOWR('R', 11, struct compat_fastrpc_ioctl_invoke_crc) |
Tharun Kumar Merugu | 5f6ca61c | 2017-08-11 11:43:11 +0530 | [diff] [blame] | 40 | #define COMPAT_FASTRPC_IOCTL_CONTROL \ |
| 41 | _IOWR('R', 12, struct compat_fastrpc_ioctl_control) |
Tharun Kumar Merugu | 55be90d | 2018-05-31 11:41:03 +0530 | [diff] [blame] | 42 | #define COMPAT_FASTRPC_IOCTL_MMAP_64 \ |
| 43 | _IOWR('R', 14, struct compat_fastrpc_ioctl_mmap_64) |
| 44 | #define COMPAT_FASTRPC_IOCTL_MUNMAP_64 \ |
| 45 | _IOWR('R', 15, struct compat_fastrpc_ioctl_munmap_64) |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 46 | |
| 47 | struct compat_remote_buf { |
| 48 | compat_uptr_t pv; /* buffer pointer */ |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 49 | compat_size_t len; /* length of buffer */ |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | union compat_remote_arg { |
| 53 | struct compat_remote_buf buf; |
| 54 | compat_uint_t h; |
| 55 | }; |
| 56 | |
| 57 | struct compat_fastrpc_ioctl_invoke { |
| 58 | compat_uint_t handle; /* remote handle */ |
| 59 | compat_uint_t sc; /* scalars describing the data */ |
| 60 | compat_uptr_t pra; /* remote arguments list */ |
| 61 | }; |
| 62 | |
| 63 | struct compat_fastrpc_ioctl_invoke_fd { |
| 64 | struct compat_fastrpc_ioctl_invoke inv; |
| 65 | compat_uptr_t fds; /* fd list */ |
| 66 | }; |
| 67 | |
| 68 | struct compat_fastrpc_ioctl_invoke_attrs { |
| 69 | struct compat_fastrpc_ioctl_invoke inv; |
| 70 | compat_uptr_t fds; /* fd list */ |
| 71 | compat_uptr_t attrs; /* attribute list */ |
| 72 | }; |
| 73 | |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 74 | struct compat_fastrpc_ioctl_invoke_crc { |
| 75 | struct compat_fastrpc_ioctl_invoke inv; |
| 76 | compat_uptr_t fds; /* fd list */ |
| 77 | compat_uptr_t attrs; /* attribute list */ |
| 78 | compat_uptr_t crc; /* crc list */ |
| 79 | }; |
| 80 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 81 | struct compat_fastrpc_ioctl_mmap { |
| 82 | compat_int_t fd; /* ion fd */ |
| 83 | compat_uint_t flags; /* flags for dsp to map with */ |
Tharun Kumar Merugu | 6c7d37d | 2018-04-18 12:14:22 +0530 | [diff] [blame] | 84 | compat_uptr_t vaddrin; /* optional virtual address */ |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 85 | compat_size_t size; /* size */ |
Tharun Kumar Merugu | 6c7d37d | 2018-04-18 12:14:22 +0530 | [diff] [blame] | 86 | compat_uptr_t vaddrout; /* dsps virtual address */ |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
Tharun Kumar Merugu | 55be90d | 2018-05-31 11:41:03 +0530 | [diff] [blame] | 89 | struct compat_fastrpc_ioctl_mmap_64 { |
| 90 | compat_int_t fd; /* ion fd */ |
| 91 | compat_uint_t flags; /* flags for dsp to map with */ |
| 92 | compat_u64 vaddrin; /* optional virtual address */ |
| 93 | compat_size_t size; /* size */ |
| 94 | compat_u64 vaddrout; /* dsps virtual address */ |
| 95 | }; |
| 96 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 97 | struct compat_fastrpc_ioctl_munmap { |
Tharun Kumar Merugu | 6c7d37d | 2018-04-18 12:14:22 +0530 | [diff] [blame] | 98 | compat_uptr_t vaddrout; /* address to unmap */ |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 99 | compat_size_t size; /* size */ |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 100 | }; |
| 101 | |
Tharun Kumar Merugu | 55be90d | 2018-05-31 11:41:03 +0530 | [diff] [blame] | 102 | struct compat_fastrpc_ioctl_munmap_64 { |
| 103 | compat_u64 vaddrout; /* address to unmap */ |
| 104 | compat_size_t size; /* size */ |
| 105 | }; |
| 106 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 107 | struct compat_fastrpc_ioctl_init { |
| 108 | compat_uint_t flags; /* one of FASTRPC_INIT_* macros */ |
| 109 | compat_uptr_t file; /* pointer to elf file */ |
| 110 | compat_int_t filelen; /* elf file length */ |
| 111 | compat_int_t filefd; /* ION fd for the file */ |
| 112 | compat_uptr_t mem; /* mem for the PD */ |
| 113 | compat_int_t memlen; /* mem length */ |
| 114 | compat_int_t memfd; /* ION fd for the mem */ |
| 115 | }; |
| 116 | |
Sathish Ambley | d6300c3 | 2017-01-18 09:50:43 -0800 | [diff] [blame] | 117 | struct compat_fastrpc_ioctl_init_attrs { |
| 118 | struct compat_fastrpc_ioctl_init init; |
| 119 | compat_int_t attrs; /* attributes to init process */ |
| 120 | compat_int_t siglen; /* test signature file length */ |
| 121 | }; |
| 122 | |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 123 | struct compat_fastrpc_ioctl_perf { /* kernel performance data */ |
| 124 | compat_uptr_t data; |
| 125 | compat_int_t numkeys; |
| 126 | compat_uptr_t keys; |
| 127 | }; |
| 128 | |
Tharun Kumar Merugu | e073de7 | 2018-07-30 23:57:47 +0530 | [diff] [blame] | 129 | #define FASTRPC_CONTROL_LATENCY (1) |
Tharun Kumar Merugu | 5f6ca61c | 2017-08-11 11:43:11 +0530 | [diff] [blame] | 130 | struct compat_fastrpc_ctrl_latency { |
| 131 | compat_uint_t enable; /* latency control enable */ |
| 132 | compat_uint_t level; /* level of control */ |
| 133 | }; |
| 134 | |
Tharun Kumar Merugu | 0c14c0b | 2018-12-18 13:04:52 +0530 | [diff] [blame] | 135 | #define FASTRPC_CONTROL_SMMU (2) |
| 136 | struct compat_fastrpc_ctrl_smmu { |
| 137 | compat_uint_t sharedcb; |
| 138 | }; |
| 139 | |
Tharun Kumar Merugu | e073de7 | 2018-07-30 23:57:47 +0530 | [diff] [blame] | 140 | #define FASTRPC_CONTROL_KALLOC (3) |
| 141 | struct compat_fastrpc_ctrl_kalloc { |
| 142 | compat_uint_t kalloc_support; /* Remote memory allocation from kernel */ |
| 143 | }; |
| 144 | |
Tharun Kumar Merugu | 5f6ca61c | 2017-08-11 11:43:11 +0530 | [diff] [blame] | 145 | struct compat_fastrpc_ioctl_control { |
| 146 | compat_uint_t req; |
| 147 | union { |
| 148 | struct compat_fastrpc_ctrl_latency lp; |
Tharun Kumar Merugu | 0c14c0b | 2018-12-18 13:04:52 +0530 | [diff] [blame] | 149 | struct compat_fastrpc_ctrl_smmu smmu; |
Tharun Kumar Merugu | e073de7 | 2018-07-30 23:57:47 +0530 | [diff] [blame] | 150 | struct compat_fastrpc_ctrl_kalloc kalloc; |
Tharun Kumar Merugu | 5f6ca61c | 2017-08-11 11:43:11 +0530 | [diff] [blame] | 151 | }; |
| 152 | }; |
| 153 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 154 | static int compat_get_fastrpc_ioctl_invoke( |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 155 | struct compat_fastrpc_ioctl_invoke_crc __user *inv32, |
| 156 | struct fastrpc_ioctl_invoke_crc __user **inva, |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 157 | unsigned int cmd) |
| 158 | { |
| 159 | compat_uint_t u, sc; |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 160 | compat_size_t s; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 161 | compat_uptr_t p; |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 162 | struct fastrpc_ioctl_invoke_crc *inv; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 163 | union compat_remote_arg *pra32; |
| 164 | union remote_arg *pra; |
Sathish Ambley | 58dc64d | 2016-11-29 17:11:53 -0800 | [diff] [blame] | 165 | int err, len, j; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 166 | |
| 167 | err = get_user(sc, &inv32->inv.sc); |
| 168 | if (err) |
| 169 | return err; |
| 170 | |
| 171 | len = REMOTE_SCALARS_LENGTH(sc); |
| 172 | VERIFY(err, NULL != (inv = compat_alloc_user_space( |
| 173 | sizeof(*inv) + len * sizeof(*pra)))); |
| 174 | if (err) |
| 175 | return -EFAULT; |
| 176 | |
| 177 | pra = (union remote_arg *)(inv + 1); |
| 178 | err = put_user(pra, &inv->inv.pra); |
| 179 | err |= put_user(sc, &inv->inv.sc); |
| 180 | err |= get_user(u, &inv32->inv.handle); |
| 181 | err |= put_user(u, &inv->inv.handle); |
| 182 | err |= get_user(p, &inv32->inv.pra); |
| 183 | if (err) |
| 184 | return err; |
| 185 | |
| 186 | pra32 = compat_ptr(p); |
| 187 | pra = (union remote_arg *)(inv + 1); |
Sathish Ambley | 58dc64d | 2016-11-29 17:11:53 -0800 | [diff] [blame] | 188 | for (j = 0; j < len; j++) { |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 189 | err |= get_user(p, &pra32[j].buf.pv); |
| 190 | err |= put_user(p, (uintptr_t *)&pra[j].buf.pv); |
| 191 | err |= get_user(s, &pra32[j].buf.len); |
| 192 | err |= put_user(s, &pra[j].buf.len); |
| 193 | } |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 194 | |
| 195 | err |= put_user(NULL, &inv->fds); |
| 196 | if (cmd != COMPAT_FASTRPC_IOCTL_INVOKE) { |
| 197 | err |= get_user(p, &inv32->fds); |
| 198 | err |= put_user(p, (compat_uptr_t *)&inv->fds); |
| 199 | } |
| 200 | err |= put_user(NULL, &inv->attrs); |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 201 | if ((cmd == COMPAT_FASTRPC_IOCTL_INVOKE_ATTRS) || |
| 202 | (cmd == COMPAT_FASTRPC_IOCTL_INVOKE_CRC)) { |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 203 | err |= get_user(p, &inv32->attrs); |
| 204 | err |= put_user(p, (compat_uptr_t *)&inv->attrs); |
| 205 | } |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 206 | err |= put_user(NULL, (compat_uptr_t __user **)&inv->crc); |
| 207 | if (cmd == COMPAT_FASTRPC_IOCTL_INVOKE_CRC) { |
| 208 | err |= get_user(p, &inv32->crc); |
| 209 | err |= put_user(p, (compat_uptr_t __user *)&inv->crc); |
| 210 | } |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 211 | |
| 212 | *inva = inv; |
| 213 | return err; |
| 214 | } |
| 215 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 216 | static int compat_get_fastrpc_ioctl_mmap( |
| 217 | struct compat_fastrpc_ioctl_mmap __user *map32, |
| 218 | struct fastrpc_ioctl_mmap __user *map) |
| 219 | { |
| 220 | compat_uint_t u; |
| 221 | compat_int_t i; |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 222 | compat_size_t s; |
Tharun Kumar Merugu | 6c7d37d | 2018-04-18 12:14:22 +0530 | [diff] [blame] | 223 | compat_uptr_t p; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 224 | int err; |
| 225 | |
| 226 | err = get_user(i, &map32->fd); |
| 227 | err |= put_user(i, &map->fd); |
| 228 | err |= get_user(u, &map32->flags); |
| 229 | err |= put_user(u, &map->flags); |
| 230 | err |= get_user(p, &map32->vaddrin); |
Tharun Kumar Merugu | 6c7d37d | 2018-04-18 12:14:22 +0530 | [diff] [blame] | 231 | err |= put_user(p, (uintptr_t *)&map->vaddrin); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 232 | err |= get_user(s, &map32->size); |
| 233 | err |= put_user(s, &map->size); |
| 234 | |
| 235 | return err; |
| 236 | } |
| 237 | |
Tharun Kumar Merugu | 55be90d | 2018-05-31 11:41:03 +0530 | [diff] [blame] | 238 | static int compat_get_fastrpc_ioctl_mmap_64( |
| 239 | struct compat_fastrpc_ioctl_mmap_64 __user *map32, |
| 240 | struct fastrpc_ioctl_mmap __user *map) |
| 241 | { |
| 242 | compat_uint_t u; |
| 243 | compat_int_t i; |
| 244 | compat_size_t s; |
| 245 | compat_u64 p; |
| 246 | int err; |
| 247 | |
| 248 | err = get_user(i, &map32->fd); |
| 249 | err |= put_user(i, &map->fd); |
| 250 | err |= get_user(u, &map32->flags); |
| 251 | err |= put_user(u, &map->flags); |
| 252 | err |= get_user(p, &map32->vaddrin); |
| 253 | err |= put_user(p, &map->vaddrin); |
| 254 | err |= get_user(s, &map32->size); |
| 255 | err |= put_user(s, &map->size); |
| 256 | |
| 257 | return err; |
| 258 | } |
| 259 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 260 | static int compat_put_fastrpc_ioctl_mmap( |
| 261 | struct compat_fastrpc_ioctl_mmap __user *map32, |
| 262 | struct fastrpc_ioctl_mmap __user *map) |
| 263 | { |
Tharun Kumar Merugu | 6c7d37d | 2018-04-18 12:14:22 +0530 | [diff] [blame] | 264 | compat_uptr_t p; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 265 | int err; |
| 266 | |
| 267 | err = get_user(p, &map->vaddrout); |
| 268 | err |= put_user(p, &map32->vaddrout); |
| 269 | |
| 270 | return err; |
| 271 | } |
| 272 | |
Tharun Kumar Merugu | 55be90d | 2018-05-31 11:41:03 +0530 | [diff] [blame] | 273 | static int compat_put_fastrpc_ioctl_mmap_64( |
| 274 | struct compat_fastrpc_ioctl_mmap_64 __user *map32, |
| 275 | struct fastrpc_ioctl_mmap __user *map) |
| 276 | { |
| 277 | compat_u64 p; |
| 278 | int err; |
| 279 | |
| 280 | err = get_user(p, &map->vaddrout); |
| 281 | err |= put_user(p, &map32->vaddrout); |
| 282 | |
| 283 | return err; |
| 284 | } |
| 285 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 286 | static int compat_get_fastrpc_ioctl_munmap( |
| 287 | struct compat_fastrpc_ioctl_munmap __user *unmap32, |
| 288 | struct fastrpc_ioctl_munmap __user *unmap) |
| 289 | { |
Tharun Kumar Merugu | 6c7d37d | 2018-04-18 12:14:22 +0530 | [diff] [blame] | 290 | compat_uptr_t p; |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 291 | compat_size_t s; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 292 | int err; |
| 293 | |
| 294 | err = get_user(p, &unmap32->vaddrout); |
| 295 | err |= put_user(p, &unmap->vaddrout); |
| 296 | err |= get_user(s, &unmap32->size); |
| 297 | err |= put_user(s, &unmap->size); |
| 298 | |
| 299 | return err; |
| 300 | } |
| 301 | |
Tharun Kumar Merugu | 55be90d | 2018-05-31 11:41:03 +0530 | [diff] [blame] | 302 | static int compat_get_fastrpc_ioctl_munmap_64( |
| 303 | struct compat_fastrpc_ioctl_munmap_64 __user *unmap32, |
| 304 | struct fastrpc_ioctl_munmap __user *unmap) |
| 305 | { |
| 306 | compat_u64 p; |
| 307 | compat_size_t s; |
| 308 | int err; |
| 309 | |
| 310 | err = get_user(p, &unmap32->vaddrout); |
| 311 | err |= put_user(p, &unmap->vaddrout); |
| 312 | err |= get_user(s, &unmap32->size); |
| 313 | err |= put_user(s, &unmap->size); |
| 314 | |
| 315 | return err; |
| 316 | } |
| 317 | |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 318 | static int compat_get_fastrpc_ioctl_perf( |
| 319 | struct compat_fastrpc_ioctl_perf __user *perf32, |
| 320 | struct fastrpc_ioctl_perf __user *perf) |
| 321 | { |
| 322 | compat_uptr_t p; |
| 323 | int err; |
| 324 | |
| 325 | err = get_user(p, &perf32->data); |
| 326 | err |= put_user(p, &perf->data); |
| 327 | err |= get_user(p, &perf32->keys); |
| 328 | err |= put_user(p, &perf->keys); |
| 329 | |
| 330 | return err; |
| 331 | } |
| 332 | |
Tharun Kumar Merugu | 5f6ca61c | 2017-08-11 11:43:11 +0530 | [diff] [blame] | 333 | static int compat_get_fastrpc_ioctl_control( |
| 334 | struct compat_fastrpc_ioctl_control __user *ctrl32, |
| 335 | struct fastrpc_ioctl_control __user *ctrl) |
| 336 | { |
| 337 | compat_uptr_t p; |
| 338 | int err; |
| 339 | |
| 340 | err = get_user(p, &ctrl32->req); |
| 341 | err |= put_user(p, &ctrl->req); |
| 342 | if (p == FASTRPC_CONTROL_LATENCY) { |
| 343 | err |= get_user(p, &ctrl32->lp.enable); |
| 344 | err |= put_user(p, &ctrl->lp.enable); |
| 345 | err |= get_user(p, &ctrl32->lp.level); |
| 346 | err |= put_user(p, &ctrl->lp.level); |
| 347 | } |
| 348 | |
| 349 | return err; |
| 350 | } |
| 351 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 352 | static int compat_get_fastrpc_ioctl_init( |
Sathish Ambley | d6300c3 | 2017-01-18 09:50:43 -0800 | [diff] [blame] | 353 | struct compat_fastrpc_ioctl_init_attrs __user *init32, |
| 354 | struct fastrpc_ioctl_init_attrs __user *init, |
| 355 | unsigned int cmd) |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 356 | { |
| 357 | compat_uint_t u; |
| 358 | compat_uptr_t p; |
| 359 | compat_int_t i; |
| 360 | int err; |
| 361 | |
Sathish Ambley | d6300c3 | 2017-01-18 09:50:43 -0800 | [diff] [blame] | 362 | err = get_user(u, &init32->init.flags); |
| 363 | err |= put_user(u, &init->init.flags); |
| 364 | err |= get_user(p, &init32->init.file); |
| 365 | err |= put_user(p, &init->init.file); |
| 366 | err |= get_user(i, &init32->init.filelen); |
| 367 | err |= put_user(i, &init->init.filelen); |
| 368 | err |= get_user(i, &init32->init.filefd); |
| 369 | err |= put_user(i, &init->init.filefd); |
| 370 | err |= get_user(p, &init32->init.mem); |
| 371 | err |= put_user(p, &init->init.mem); |
| 372 | err |= get_user(i, &init32->init.memlen); |
| 373 | err |= put_user(i, &init->init.memlen); |
| 374 | err |= get_user(i, &init32->init.memfd); |
| 375 | err |= put_user(i, &init->init.memfd); |
| 376 | |
| 377 | err |= put_user(0, &init->attrs); |
| 378 | if (cmd == COMPAT_FASTRPC_IOCTL_INIT_ATTRS) { |
| 379 | err |= get_user(i, &init32->attrs); |
| 380 | err |= put_user(i, (compat_uptr_t *)&init->attrs); |
| 381 | } |
| 382 | |
| 383 | err |= put_user(0, &init->siglen); |
| 384 | if (cmd == COMPAT_FASTRPC_IOCTL_INIT_ATTRS) { |
| 385 | err |= get_user(i, &init32->siglen); |
| 386 | err |= put_user(i, (compat_uptr_t *)&init->siglen); |
| 387 | } |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 388 | |
| 389 | return err; |
| 390 | } |
| 391 | |
| 392 | long compat_fastrpc_device_ioctl(struct file *filp, unsigned int cmd, |
| 393 | unsigned long arg) |
| 394 | { |
| 395 | int err = 0; |
| 396 | |
| 397 | if (!filp->f_op || !filp->f_op->unlocked_ioctl) |
| 398 | return -ENOTTY; |
| 399 | |
| 400 | switch (cmd) { |
| 401 | case COMPAT_FASTRPC_IOCTL_INVOKE: |
| 402 | case COMPAT_FASTRPC_IOCTL_INVOKE_FD: |
| 403 | case COMPAT_FASTRPC_IOCTL_INVOKE_ATTRS: |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 404 | case COMPAT_FASTRPC_IOCTL_INVOKE_CRC: |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 405 | { |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 406 | struct compat_fastrpc_ioctl_invoke_crc __user *inv32; |
| 407 | struct fastrpc_ioctl_invoke_crc __user *inv; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 408 | |
| 409 | inv32 = compat_ptr(arg); |
| 410 | VERIFY(err, 0 == compat_get_fastrpc_ioctl_invoke(inv32, |
| 411 | &inv, cmd)); |
| 412 | if (err) |
| 413 | return err; |
Sathish Ambley | 58dc64d | 2016-11-29 17:11:53 -0800 | [diff] [blame] | 414 | return filp->f_op->unlocked_ioctl(filp, |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 415 | FASTRPC_IOCTL_INVOKE_CRC, (unsigned long)inv); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 416 | } |
| 417 | case COMPAT_FASTRPC_IOCTL_MMAP: |
| 418 | { |
| 419 | struct compat_fastrpc_ioctl_mmap __user *map32; |
| 420 | struct fastrpc_ioctl_mmap __user *map; |
| 421 | long ret; |
| 422 | |
| 423 | map32 = compat_ptr(arg); |
| 424 | VERIFY(err, NULL != (map = compat_alloc_user_space( |
| 425 | sizeof(*map)))); |
| 426 | if (err) |
| 427 | return -EFAULT; |
| 428 | VERIFY(err, 0 == compat_get_fastrpc_ioctl_mmap(map32, map)); |
| 429 | if (err) |
| 430 | return err; |
| 431 | ret = filp->f_op->unlocked_ioctl(filp, FASTRPC_IOCTL_MMAP, |
| 432 | (unsigned long)map); |
| 433 | if (ret) |
| 434 | return ret; |
| 435 | VERIFY(err, 0 == compat_put_fastrpc_ioctl_mmap(map32, map)); |
| 436 | return err; |
| 437 | } |
Tharun Kumar Merugu | 55be90d | 2018-05-31 11:41:03 +0530 | [diff] [blame] | 438 | case COMPAT_FASTRPC_IOCTL_MMAP_64: |
| 439 | { |
| 440 | struct compat_fastrpc_ioctl_mmap_64 __user *map32; |
| 441 | struct fastrpc_ioctl_mmap __user *map; |
| 442 | long ret; |
| 443 | |
| 444 | map32 = compat_ptr(arg); |
| 445 | VERIFY(err, NULL != (map = compat_alloc_user_space( |
| 446 | sizeof(*map)))); |
| 447 | if (err) |
| 448 | return -EFAULT; |
| 449 | VERIFY(err, 0 == compat_get_fastrpc_ioctl_mmap_64(map32, map)); |
| 450 | if (err) |
| 451 | return err; |
| 452 | ret = filp->f_op->unlocked_ioctl(filp, FASTRPC_IOCTL_MMAP_64, |
| 453 | (unsigned long)map); |
| 454 | if (ret) |
| 455 | return ret; |
| 456 | VERIFY(err, 0 == compat_put_fastrpc_ioctl_mmap_64(map32, map)); |
| 457 | return err; |
| 458 | } |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 459 | case COMPAT_FASTRPC_IOCTL_MUNMAP: |
| 460 | { |
| 461 | struct compat_fastrpc_ioctl_munmap __user *unmap32; |
| 462 | struct fastrpc_ioctl_munmap __user *unmap; |
| 463 | |
| 464 | unmap32 = compat_ptr(arg); |
| 465 | VERIFY(err, NULL != (unmap = compat_alloc_user_space( |
| 466 | sizeof(*unmap)))); |
| 467 | if (err) |
| 468 | return -EFAULT; |
| 469 | VERIFY(err, 0 == compat_get_fastrpc_ioctl_munmap(unmap32, |
| 470 | unmap)); |
| 471 | if (err) |
| 472 | return err; |
| 473 | return filp->f_op->unlocked_ioctl(filp, FASTRPC_IOCTL_MUNMAP, |
| 474 | (unsigned long)unmap); |
| 475 | } |
Tharun Kumar Merugu | 55be90d | 2018-05-31 11:41:03 +0530 | [diff] [blame] | 476 | case COMPAT_FASTRPC_IOCTL_MUNMAP_64: |
| 477 | { |
| 478 | struct compat_fastrpc_ioctl_munmap_64 __user *unmap32; |
| 479 | struct fastrpc_ioctl_munmap __user *unmap; |
| 480 | |
| 481 | unmap32 = compat_ptr(arg); |
| 482 | VERIFY(err, NULL != (unmap = compat_alloc_user_space( |
| 483 | sizeof(*unmap)))); |
| 484 | if (err) |
| 485 | return -EFAULT; |
| 486 | VERIFY(err, 0 == compat_get_fastrpc_ioctl_munmap_64(unmap32, |
| 487 | unmap)); |
| 488 | if (err) |
| 489 | return err; |
| 490 | return filp->f_op->unlocked_ioctl(filp, FASTRPC_IOCTL_MUNMAP_64, |
| 491 | (unsigned long)unmap); |
| 492 | } |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 493 | case COMPAT_FASTRPC_IOCTL_INIT: |
Sathish Ambley | d6300c3 | 2017-01-18 09:50:43 -0800 | [diff] [blame] | 494 | /* fall through */ |
| 495 | case COMPAT_FASTRPC_IOCTL_INIT_ATTRS: |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 496 | { |
Sathish Ambley | d6300c3 | 2017-01-18 09:50:43 -0800 | [diff] [blame] | 497 | struct compat_fastrpc_ioctl_init_attrs __user *init32; |
| 498 | struct fastrpc_ioctl_init_attrs __user *init; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 499 | |
| 500 | init32 = compat_ptr(arg); |
| 501 | VERIFY(err, NULL != (init = compat_alloc_user_space( |
| 502 | sizeof(*init)))); |
| 503 | if (err) |
| 504 | return -EFAULT; |
| 505 | VERIFY(err, 0 == compat_get_fastrpc_ioctl_init(init32, |
Sathish Ambley | d6300c3 | 2017-01-18 09:50:43 -0800 | [diff] [blame] | 506 | init, cmd)); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 507 | if (err) |
| 508 | return err; |
Sathish Ambley | d6300c3 | 2017-01-18 09:50:43 -0800 | [diff] [blame] | 509 | return filp->f_op->unlocked_ioctl(filp, |
| 510 | FASTRPC_IOCTL_INIT_ATTRS, (unsigned long)init); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 511 | } |
| 512 | case FASTRPC_IOCTL_GETINFO: |
| 513 | { |
| 514 | compat_uptr_t __user *info32; |
| 515 | uint32_t __user *info; |
| 516 | compat_uint_t u; |
| 517 | long ret; |
| 518 | |
| 519 | info32 = compat_ptr(arg); |
| 520 | VERIFY(err, NULL != (info = compat_alloc_user_space( |
| 521 | sizeof(*info)))); |
| 522 | if (err) |
| 523 | return -EFAULT; |
Sathish Ambley | 36849af | 2017-02-02 09:35:55 -0800 | [diff] [blame] | 524 | err = get_user(u, info32); |
| 525 | err |= put_user(u, info); |
| 526 | if (err) |
| 527 | return err; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 528 | ret = filp->f_op->unlocked_ioctl(filp, FASTRPC_IOCTL_GETINFO, |
| 529 | (unsigned long)info); |
| 530 | if (ret) |
| 531 | return ret; |
| 532 | err = get_user(u, info); |
| 533 | err |= put_user(u, info32); |
| 534 | return err; |
| 535 | } |
| 536 | case FASTRPC_IOCTL_SETMODE: |
| 537 | return filp->f_op->unlocked_ioctl(filp, cmd, |
| 538 | (unsigned long)compat_ptr(arg)); |
Tharun Kumar Merugu | 5f6ca61c | 2017-08-11 11:43:11 +0530 | [diff] [blame] | 539 | case COMPAT_FASTRPC_IOCTL_CONTROL: |
| 540 | { |
| 541 | struct compat_fastrpc_ioctl_control __user *ctrl32; |
| 542 | struct fastrpc_ioctl_control __user *ctrl; |
Tharun Kumar Merugu | e073de7 | 2018-07-30 23:57:47 +0530 | [diff] [blame] | 543 | compat_uptr_t p; |
Tharun Kumar Merugu | 5f6ca61c | 2017-08-11 11:43:11 +0530 | [diff] [blame] | 544 | |
| 545 | ctrl32 = compat_ptr(arg); |
| 546 | VERIFY(err, NULL != (ctrl = compat_alloc_user_space( |
| 547 | sizeof(*ctrl)))); |
| 548 | if (err) |
| 549 | return -EFAULT; |
| 550 | VERIFY(err, 0 == compat_get_fastrpc_ioctl_control(ctrl32, |
| 551 | ctrl)); |
| 552 | if (err) |
| 553 | return err; |
| 554 | err = filp->f_op->unlocked_ioctl(filp, FASTRPC_IOCTL_CONTROL, |
| 555 | (unsigned long)ctrl); |
Tharun Kumar Merugu | e073de7 | 2018-07-30 23:57:47 +0530 | [diff] [blame] | 556 | if (err) |
| 557 | return err; |
| 558 | err = get_user(p, &ctrl32->req); |
| 559 | if (err) |
| 560 | return err; |
| 561 | if (p == FASTRPC_CONTROL_KALLOC) { |
| 562 | err = get_user(p, &ctrl->kalloc.kalloc_support); |
| 563 | err |= put_user(p, &ctrl32->kalloc.kalloc_support); |
| 564 | } |
Tharun Kumar Merugu | 5f6ca61c | 2017-08-11 11:43:11 +0530 | [diff] [blame] | 565 | return err; |
| 566 | } |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 567 | case COMPAT_FASTRPC_IOCTL_GETPERF: |
| 568 | { |
| 569 | struct compat_fastrpc_ioctl_perf __user *perf32; |
| 570 | struct fastrpc_ioctl_perf *perf; |
| 571 | compat_uint_t u; |
| 572 | long ret; |
| 573 | |
| 574 | perf32 = compat_ptr(arg); |
| 575 | VERIFY(err, NULL != (perf = compat_alloc_user_space( |
| 576 | sizeof(*perf)))); |
| 577 | if (err) |
| 578 | return -EFAULT; |
| 579 | VERIFY(err, 0 == compat_get_fastrpc_ioctl_perf(perf32, |
| 580 | perf)); |
| 581 | if (err) |
| 582 | return err; |
| 583 | ret = filp->f_op->unlocked_ioctl(filp, FASTRPC_IOCTL_GETPERF, |
| 584 | (unsigned long)perf); |
| 585 | if (ret) |
| 586 | return ret; |
| 587 | err = get_user(u, &perf->numkeys); |
| 588 | err |= put_user(u, &perf32->numkeys); |
| 589 | return err; |
| 590 | } |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 591 | default: |
| 592 | return -ENOIOCTLCMD; |
| 593 | } |
| 594 | } |