Loading...
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
4 * Copyright (C) 2015 Richard Weinberger (richard@nod.at)
5 */
6
7#ifndef __UM_UACCESS_H
8#define __UM_UACCESS_H
9
10#include <asm/elf.h>
11
12#define __under_task_size(addr, size) \
13 (((unsigned long) (addr) < TASK_SIZE) && \
14 (((unsigned long) (addr) + (size)) < TASK_SIZE))
15
16#define __access_ok_vsyscall(addr, size) \
17 (((unsigned long) (addr) >= FIXADDR_USER_START) && \
18 ((unsigned long) (addr) + (size) <= FIXADDR_USER_END) && \
19 ((unsigned long) (addr) + (size) >= (unsigned long)(addr)))
20
21#define __addr_range_nowrap(addr, size) \
22 ((unsigned long) (addr) <= ((unsigned long) (addr) + (size)))
23
24extern unsigned long raw_copy_from_user(void *to, const void __user *from, unsigned long n);
25extern unsigned long raw_copy_to_user(void __user *to, const void *from, unsigned long n);
26extern long __strncpy_from_user(char *dst, const char __user *src, long count);
27extern long __strnlen_user(const void __user *str, long len);
28extern unsigned long __clear_user(void __user *mem, unsigned long len);
29static inline int __access_ok(unsigned long addr, unsigned long size);
30
31/* Teach asm-generic/uaccess.h that we have C functions for these. */
32#define __access_ok __access_ok
33#define __clear_user __clear_user
34#define __strnlen_user __strnlen_user
35#define __strncpy_from_user __strncpy_from_user
36#define INLINE_COPY_FROM_USER
37#define INLINE_COPY_TO_USER
38
39#include <asm-generic/uaccess.h>
40
41static inline int __access_ok(unsigned long addr, unsigned long size)
42{
43 return __addr_range_nowrap(addr, size) &&
44 (__under_task_size(addr, size) ||
45 __access_ok_vsyscall(addr, size) ||
46 uaccess_kernel());
47}
48
49#endif
1/*
2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 * Copyright (C) 2015 Richard Weinberger (richard@nod.at)
4 * Licensed under the GPL
5 */
6
7#ifndef __UM_UACCESS_H
8#define __UM_UACCESS_H
9
10#include <asm/thread_info.h>
11#include <asm/elf.h>
12
13#define __under_task_size(addr, size) \
14 (((unsigned long) (addr) < TASK_SIZE) && \
15 (((unsigned long) (addr) + (size)) < TASK_SIZE))
16
17#define __access_ok_vsyscall(addr, size) \
18 (((unsigned long) (addr) >= FIXADDR_USER_START) && \
19 ((unsigned long) (addr) + (size) <= FIXADDR_USER_END) && \
20 ((unsigned long) (addr) + (size) >= (unsigned long)(addr)))
21
22#define __addr_range_nowrap(addr, size) \
23 ((unsigned long) (addr) <= ((unsigned long) (addr) + (size)))
24
25extern long __copy_from_user(void *to, const void __user *from, unsigned long n);
26extern long __copy_to_user(void __user *to, const void *from, unsigned long n);
27extern long __strncpy_from_user(char *dst, const char __user *src, long count);
28extern long __strnlen_user(const void __user *str, long len);
29extern unsigned long __clear_user(void __user *mem, unsigned long len);
30static inline int __access_ok(unsigned long addr, unsigned long size);
31
32/* Teach asm-generic/uaccess.h that we have C functions for these. */
33#define __access_ok __access_ok
34#define __clear_user __clear_user
35#define __copy_to_user __copy_to_user
36#define __copy_from_user __copy_from_user
37#define __strnlen_user __strnlen_user
38#define __strncpy_from_user __strncpy_from_user
39#define __copy_to_user_inatomic __copy_to_user
40#define __copy_from_user_inatomic __copy_from_user
41
42#include <asm-generic/uaccess.h>
43
44static inline int __access_ok(unsigned long addr, unsigned long size)
45{
46 return __addr_range_nowrap(addr, size) &&
47 (__under_task_size(addr, size) ||
48 __access_ok_vsyscall(addr, size) ||
49 segment_eq(get_fs(), KERNEL_DS));
50}
51
52#endif