d2912cb15bdda (Thomas Gleixner 2019-06-04 10:11:33 +0200 1) // SPDX-License-Identifier: GPL-2.0-only
f75b1b1bedfb4 (Richard Weinberger 2013-08-17 18:46:00 +0200 2) /*
f75b1b1bedfb4 (Richard Weinberger 2013-08-17 18:46:00 +0200 3) * Copyright (C) 2013 Richard Weinberger <richrd@nod.at>
f75b1b1bedfb4 (Richard Weinberger 2013-08-17 18:46:00 +0200 4) */
f75b1b1bedfb4 (Richard Weinberger 2013-08-17 18:46:00 +0200 5)
f75b1b1bedfb4 (Richard Weinberger 2013-08-17 18:46:00 +0200 6) #include <linux/uaccess.h>
f75b1b1bedfb4 (Richard Weinberger 2013-08-17 18:46:00 +0200 7) #include <linux/kernel.h>
f75b1b1bedfb4 (Richard Weinberger 2013-08-17 18:46:00 +0200 8) #include <os.h>
f75b1b1bedfb4 (Richard Weinberger 2013-08-17 18:46:00 +0200 9)
fe557319aa06c (Christoph Hellwig 2020-06-17 09:37:53 +0200 10) bool copy_from_kernel_nofault_allowed(const void *src, size_t size)
f75b1b1bedfb4 (Richard Weinberger 2013-08-17 18:46:00 +0200 11) {
f75b1b1bedfb4 (Richard Weinberger 2013-08-17 18:46:00 +0200 12) void *psrc = (void *)rounddown((unsigned long)src, PAGE_SIZE);
f75b1b1bedfb4 (Richard Weinberger 2013-08-17 18:46:00 +0200 13)
f75b1b1bedfb4 (Richard Weinberger 2013-08-17 18:46:00 +0200 14) if ((unsigned long)src < PAGE_SIZE || size <= 0)
eab0c6089b689 (Christoph Hellwig 2020-06-08 21:34:27 -0700 15) return false;
f75b1b1bedfb4 (Richard Weinberger 2013-08-17 18:46:00 +0200 16) if (os_mincore(psrc, size + src - psrc) <= 0)
eab0c6089b689 (Christoph Hellwig 2020-06-08 21:34:27 -0700 17) return false;
eab0c6089b689 (Christoph Hellwig 2020-06-08 21:34:27 -0700 18) return true;
f75b1b1bedfb4 (Richard Weinberger 2013-08-17 18:46:00 +0200 19) }