David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2013 Richard Weinberger <richrd@nod.at> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <linux/uaccess.h> |
| 7 | #include <linux/kernel.h> |
| 8 | #include <os.h> |
| 9 | |
| 10 | long probe_kernel_read(void *dst, const void *src, size_t size) |
| 11 | { |
| 12 | void *psrc = (void *)rounddown((unsigned long)src, PAGE_SIZE); |
| 13 | |
| 14 | if ((unsigned long)src < PAGE_SIZE || size <= 0) |
| 15 | return -EFAULT; |
| 16 | |
| 17 | if (os_mincore(psrc, size + src - psrc) <= 0) |
| 18 | return -EFAULT; |
| 19 | |
| 20 | return __probe_kernel_read(dst, src, size); |
| 21 | } |