License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 21:07:57 +07:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2005-10-29 14:51:31 +07:00
|
|
|
#ifndef _ARCH_POWERPC_UACCESS_H
|
|
|
|
#define _ARCH_POWERPC_UACCESS_H
|
|
|
|
|
2016-10-13 12:42:53 +07:00
|
|
|
#include <asm/ppc_asm.h>
|
2005-10-29 14:51:31 +07:00
|
|
|
#include <asm/processor.h>
|
2006-05-03 20:02:04 +07:00
|
|
|
#include <asm/page.h>
|
2016-12-26 12:50:06 +07:00
|
|
|
#include <asm/extable.h>
|
2019-04-18 13:51:20 +07:00
|
|
|
#include <asm/kup.h>
|
2005-10-29 14:51:31 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The fs value determines whether argument validity checking should be
|
|
|
|
* performed or not. If get_fs() == USER_DS, checking is performed, with
|
|
|
|
* get_fs() == KERNEL_DS, checking is bypassed.
|
|
|
|
*
|
|
|
|
* For historical reasons, these macros are grossly misnamed.
|
|
|
|
*
|
|
|
|
* The fs/ds values are now the highest legal address in the "segment".
|
|
|
|
* This simplifies the checking in the routines below.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MAKE_MM_SEG(s) ((mm_segment_t) { (s) })
|
|
|
|
|
2005-10-31 14:39:20 +07:00
|
|
|
#define KERNEL_DS MAKE_MM_SEG(~0UL)
|
2005-10-29 14:51:31 +07:00
|
|
|
#ifdef __powerpc64__
|
2005-10-31 14:39:20 +07:00
|
|
|
/* We use TASK_SIZE_USER64 as TASK_SIZE is not constant */
|
|
|
|
#define USER_DS MAKE_MM_SEG(TASK_SIZE_USER64 - 1)
|
2005-10-29 14:51:31 +07:00
|
|
|
#else
|
|
|
|
#define USER_DS MAKE_MM_SEG(TASK_SIZE - 1)
|
|
|
|
#endif
|
|
|
|
|
2018-05-14 20:03:15 +07:00
|
|
|
#define get_fs() (current->thread.addr_limit)
|
powerpc: Check address limit on user-mode return (TIF_FSCHECK)
set_fs() sets the addr_limit, which is used in access_ok() to
determine if an address is a user or kernel address.
Some code paths use set_fs() to temporarily elevate the addr_limit so
that kernel code can read/write kernel memory as if it were user
memory. That is fine as long as the code can't ever return to
userspace with the addr_limit still elevated.
If that did happen, then userspace can read/write kernel memory as if
it were user memory, eg. just with write(2). In case it's not clear,
that is very bad. It has also happened in the past due to bugs.
Commit 5ea0727b163c ("x86/syscalls: Check address limit on user-mode
return") added a mechanism to check the addr_limit value before
returning to userspace. Any call to set_fs() sets a thread flag,
TIF_FSCHECK, and if we see that on the return to userspace we go out
of line to check that the addr_limit value is not elevated.
For further info see the above commit, as well as:
https://lwn.net/Articles/722267/
https://bugs.chromium.org/p/project-zero/issues/detail?id=990
Verified to work on 64-bit Book3S using a POC that objdumps the system
call handler, and a modified lkdtm_CORRUPT_USER_DS() that doesn't kill
the caller.
Before:
$ sudo ./test-tif-fscheck
...
0000000000000000 <.data>:
0: e1 f7 8a 79 rldicl. r10,r12,30,63
4: 80 03 82 40 bne 0x384
8: 00 40 8a 71 andi. r10,r12,16384
c: 78 0b 2a 7c mr r10,r1
10: 10 fd 21 38 addi r1,r1,-752
14: 08 00 c2 41 beq- 0x1c
18: 58 09 2d e8 ld r1,2392(r13)
1c: 00 00 41 f9 std r10,0(r1)
20: 70 01 61 f9 std r11,368(r1)
24: 78 01 81 f9 std r12,376(r1)
28: 70 00 01 f8 std r0,112(r1)
2c: 78 00 41 f9 std r10,120(r1)
30: 20 00 82 41 beq 0x50
34: a6 42 4c 7d mftb r10
After:
$ sudo ./test-tif-fscheck
Killed
And in dmesg:
Invalid address limit on user-mode return
WARNING: CPU: 1 PID: 3689 at ../include/linux/syscalls.h:260 do_notify_resume+0x140/0x170
...
NIP [c00000000001ee50] do_notify_resume+0x140/0x170
LR [c00000000001ee4c] do_notify_resume+0x13c/0x170
Call Trace:
do_notify_resume+0x13c/0x170 (unreliable)
ret_from_except_lite+0x70/0x74
Performance overhead is essentially zero in the usual case, because
the bit is checked as part of the existing _TIF_USER_WORK_MASK check.
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2018-05-14 20:03:16 +07:00
|
|
|
|
|
|
|
static inline void set_fs(mm_segment_t fs)
|
|
|
|
{
|
|
|
|
current->thread.addr_limit = fs;
|
|
|
|
/* On user-mode return check addr_limit (fs) is correct */
|
|
|
|
set_thread_flag(TIF_FSCHECK);
|
|
|
|
}
|
2005-10-29 14:51:31 +07:00
|
|
|
|
|
|
|
#define segment_eq(a, b) ((a).seg == (b).seg)
|
|
|
|
|
2012-05-28 10:03:47 +07:00
|
|
|
#define user_addr_max() (get_fs().seg)
|
|
|
|
|
2005-10-29 14:51:31 +07:00
|
|
|
#ifdef __powerpc64__
|
|
|
|
/*
|
2005-10-31 14:39:20 +07:00
|
|
|
* This check is sufficient because there is a large enough
|
|
|
|
* gap between user addresses and the kernel addresses
|
2005-10-29 14:51:31 +07:00
|
|
|
*/
|
|
|
|
#define __access_ok(addr, size, segment) \
|
2005-10-31 14:39:20 +07:00
|
|
|
(((addr) <= (segment).seg) && ((size) <= (segment).seg))
|
2005-10-29 14:51:31 +07:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2018-03-03 02:50:51 +07:00
|
|
|
static inline int __access_ok(unsigned long addr, unsigned long size,
|
|
|
|
mm_segment_t seg)
|
|
|
|
{
|
|
|
|
if (addr > seg.seg)
|
|
|
|
return 0;
|
|
|
|
return (size == 0 || size - 1 <= seg.seg - addr);
|
|
|
|
}
|
2005-10-29 14:51:31 +07:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
Remove 'type' argument from access_ok() function
Nobody has actually used the type (VERIFY_READ vs VERIFY_WRITE) argument
of the user address range verification function since we got rid of the
old racy i386-only code to walk page tables by hand.
It existed because the original 80386 would not honor the write protect
bit when in kernel mode, so you had to do COW by hand before doing any
user access. But we haven't supported that in a long time, and these
days the 'type' argument is a purely historical artifact.
A discussion about extending 'user_access_begin()' to do the range
checking resulted this patch, because there is no way we're going to
move the old VERIFY_xyz interface to that model. And it's best done at
the end of the merge window when I've done most of my merges, so let's
just get this done once and for all.
This patch was mostly done with a sed-script, with manual fix-ups for
the cases that weren't of the trivial 'access_ok(VERIFY_xyz' form.
There were a couple of notable cases:
- csky still had the old "verify_area()" name as an alias.
- the iter_iov code had magical hardcoded knowledge of the actual
values of VERIFY_{READ,WRITE} (not that they mattered, since nothing
really used it)
- microblaze used the type argument for a debug printout
but other than those oddities this should be a total no-op patch.
I tried to fix up all architectures, did fairly extensive grepping for
access_ok() uses, and the changes are trivial, but I may have missed
something. Any missed conversion should be trivially fixable, though.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-01-04 09:57:57 +07:00
|
|
|
#define access_ok(addr, size) \
|
2019-01-05 00:58:25 +07:00
|
|
|
(__chk_user_ptr(addr), \
|
2005-10-29 14:51:31 +07:00
|
|
|
__access_ok((__force unsigned long)(addr), (size), get_fs()))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These are the main single-value transfer routines. They automatically
|
|
|
|
* use the right size if we just have the right pointer type.
|
|
|
|
*
|
|
|
|
* This gets kind of ugly. We want to return _two_ values in "get_user()"
|
|
|
|
* and yet we don't want to do any pointers, because that is too much
|
|
|
|
* of a performance impact. Thus we have a few rather ugly macros here,
|
|
|
|
* and hide all the ugliness from the user.
|
|
|
|
*
|
|
|
|
* The "__xxx" versions of the user access functions are versions that
|
|
|
|
* do not verify the address space, that must have been done previously
|
|
|
|
* with a separate "access_ok()" call (this is used when we do multiple
|
|
|
|
* accesses to the same area of user memory).
|
|
|
|
*
|
|
|
|
* As we use the same address space for kernel and user data on the
|
|
|
|
* PowerPC, we can just do these as direct assignments. (Of course, the
|
|
|
|
* exception handling means that it's no longer "just"...)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#define get_user(x, ptr) \
|
|
|
|
__get_user_check((x), (ptr), sizeof(*(ptr)))
|
|
|
|
#define put_user(x, ptr) \
|
|
|
|
__put_user_check((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
|
|
|
|
|
|
|
|
#define __get_user(x, ptr) \
|
|
|
|
__get_user_nocheck((x), (ptr), sizeof(*(ptr)))
|
|
|
|
#define __put_user(x, ptr) \
|
|
|
|
__put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
|
2007-04-11 13:13:19 +07:00
|
|
|
|
|
|
|
#define __get_user_inatomic(x, ptr) \
|
|
|
|
__get_user_nosleep((x), (ptr), sizeof(*(ptr)))
|
|
|
|
#define __put_user_inatomic(x, ptr) \
|
|
|
|
__put_user_nosleep((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
|
|
|
|
|
2005-10-29 14:51:31 +07:00
|
|
|
extern long __put_user_bad(void);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We don't tell gcc that we are accessing memory, but this is OK
|
|
|
|
* because we do not write to any memory gcc knows about, so there
|
|
|
|
* are no aliasing issues.
|
|
|
|
*/
|
|
|
|
#define __put_user_asm(x, addr, err, op) \
|
|
|
|
__asm__ __volatile__( \
|
|
|
|
"1: " op " %1,0(%2) # put_user\n" \
|
|
|
|
"2:\n" \
|
|
|
|
".section .fixup,\"ax\"\n" \
|
|
|
|
"3: li %0,%3\n" \
|
|
|
|
" b 2b\n" \
|
|
|
|
".previous\n" \
|
2016-10-13 12:42:53 +07:00
|
|
|
EX_TABLE(1b, 3b) \
|
2005-10-29 14:51:31 +07:00
|
|
|
: "=r" (err) \
|
2008-07-17 14:17:52 +07:00
|
|
|
: "r" (x), "b" (addr), "i" (-EFAULT), "0" (err))
|
2005-10-29 14:51:31 +07:00
|
|
|
|
2005-10-31 14:39:20 +07:00
|
|
|
#ifdef __powerpc64__
|
|
|
|
#define __put_user_asm2(x, ptr, retval) \
|
|
|
|
__put_user_asm(x, ptr, retval, "std")
|
|
|
|
#else /* __powerpc64__ */
|
2005-10-29 14:51:31 +07:00
|
|
|
#define __put_user_asm2(x, addr, err) \
|
|
|
|
__asm__ __volatile__( \
|
|
|
|
"1: stw %1,0(%2)\n" \
|
|
|
|
"2: stw %1+1,4(%2)\n" \
|
|
|
|
"3:\n" \
|
|
|
|
".section .fixup,\"ax\"\n" \
|
|
|
|
"4: li %0,%3\n" \
|
|
|
|
" b 3b\n" \
|
|
|
|
".previous\n" \
|
2016-10-13 12:42:53 +07:00
|
|
|
EX_TABLE(1b, 4b) \
|
|
|
|
EX_TABLE(2b, 4b) \
|
2005-10-29 14:51:31 +07:00
|
|
|
: "=r" (err) \
|
2008-07-17 14:17:52 +07:00
|
|
|
: "r" (x), "b" (addr), "i" (-EFAULT), "0" (err))
|
2005-10-29 14:51:31 +07:00
|
|
|
#endif /* __powerpc64__ */
|
|
|
|
|
|
|
|
#define __put_user_size(x, ptr, size, retval) \
|
|
|
|
do { \
|
|
|
|
retval = 0; \
|
2019-04-18 13:51:20 +07:00
|
|
|
allow_write_to_user(ptr, size); \
|
2005-10-29 14:51:31 +07:00
|
|
|
switch (size) { \
|
|
|
|
case 1: __put_user_asm(x, ptr, retval, "stb"); break; \
|
|
|
|
case 2: __put_user_asm(x, ptr, retval, "sth"); break; \
|
|
|
|
case 4: __put_user_asm(x, ptr, retval, "stw"); break; \
|
|
|
|
case 8: __put_user_asm2(x, ptr, retval); break; \
|
|
|
|
default: __put_user_bad(); \
|
|
|
|
} \
|
2019-04-18 13:51:20 +07:00
|
|
|
prevent_write_to_user(ptr, size); \
|
2005-10-29 14:51:31 +07:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define __put_user_nocheck(x, ptr, size) \
|
|
|
|
({ \
|
|
|
|
long __pu_err; \
|
2006-05-03 20:02:04 +07:00
|
|
|
__typeof__(*(ptr)) __user *__pu_addr = (ptr); \
|
|
|
|
if (!is_kernel_addr((unsigned long)__pu_addr)) \
|
2013-05-26 21:31:38 +07:00
|
|
|
might_fault(); \
|
2005-10-29 14:51:31 +07:00
|
|
|
__chk_user_ptr(ptr); \
|
2006-05-03 20:02:04 +07:00
|
|
|
__put_user_size((x), __pu_addr, (size), __pu_err); \
|
2005-10-29 14:51:31 +07:00
|
|
|
__pu_err; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define __put_user_check(x, ptr, size) \
|
|
|
|
({ \
|
|
|
|
long __pu_err = -EFAULT; \
|
|
|
|
__typeof__(*(ptr)) __user *__pu_addr = (ptr); \
|
2013-05-26 21:31:38 +07:00
|
|
|
might_fault(); \
|
Remove 'type' argument from access_ok() function
Nobody has actually used the type (VERIFY_READ vs VERIFY_WRITE) argument
of the user address range verification function since we got rid of the
old racy i386-only code to walk page tables by hand.
It existed because the original 80386 would not honor the write protect
bit when in kernel mode, so you had to do COW by hand before doing any
user access. But we haven't supported that in a long time, and these
days the 'type' argument is a purely historical artifact.
A discussion about extending 'user_access_begin()' to do the range
checking resulted this patch, because there is no way we're going to
move the old VERIFY_xyz interface to that model. And it's best done at
the end of the merge window when I've done most of my merges, so let's
just get this done once and for all.
This patch was mostly done with a sed-script, with manual fix-ups for
the cases that weren't of the trivial 'access_ok(VERIFY_xyz' form.
There were a couple of notable cases:
- csky still had the old "verify_area()" name as an alias.
- the iter_iov code had magical hardcoded knowledge of the actual
values of VERIFY_{READ,WRITE} (not that they mattered, since nothing
really used it)
- microblaze used the type argument for a debug printout
but other than those oddities this should be a total no-op patch.
I tried to fix up all architectures, did fairly extensive grepping for
access_ok() uses, and the changes are trivial, but I may have missed
something. Any missed conversion should be trivially fixable, though.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-01-04 09:57:57 +07:00
|
|
|
if (access_ok(__pu_addr, size)) \
|
2005-10-29 14:51:31 +07:00
|
|
|
__put_user_size((x), __pu_addr, (size), __pu_err); \
|
|
|
|
__pu_err; \
|
|
|
|
})
|
|
|
|
|
2007-04-11 13:13:19 +07:00
|
|
|
#define __put_user_nosleep(x, ptr, size) \
|
|
|
|
({ \
|
|
|
|
long __pu_err; \
|
|
|
|
__typeof__(*(ptr)) __user *__pu_addr = (ptr); \
|
|
|
|
__chk_user_ptr(ptr); \
|
|
|
|
__put_user_size((x), __pu_addr, (size), __pu_err); \
|
|
|
|
__pu_err; \
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2005-10-29 14:51:31 +07:00
|
|
|
extern long __get_user_bad(void);
|
|
|
|
|
2017-09-15 12:25:48 +07:00
|
|
|
/*
|
|
|
|
* This does an atomic 128 byte aligned load from userspace.
|
|
|
|
* Upto caller to do enable_kernel_vmx() before calling!
|
|
|
|
*/
|
|
|
|
#define __get_user_atomic_128_aligned(kaddr, uaddr, err) \
|
|
|
|
__asm__ __volatile__( \
|
|
|
|
"1: lvx 0,0,%1 # get user\n" \
|
|
|
|
" stvx 0,0,%2 # put kernel\n" \
|
|
|
|
"2:\n" \
|
|
|
|
".section .fixup,\"ax\"\n" \
|
|
|
|
"3: li %0,%3\n" \
|
|
|
|
" b 2b\n" \
|
|
|
|
".previous\n" \
|
|
|
|
EX_TABLE(1b, 3b) \
|
|
|
|
: "=r" (err) \
|
|
|
|
: "b" (uaddr), "b" (kaddr), "i" (-EFAULT), "0" (err))
|
|
|
|
|
2005-10-29 14:51:31 +07:00
|
|
|
#define __get_user_asm(x, addr, err, op) \
|
|
|
|
__asm__ __volatile__( \
|
2005-10-31 14:39:20 +07:00
|
|
|
"1: "op" %1,0(%2) # get_user\n" \
|
2005-10-29 14:51:31 +07:00
|
|
|
"2:\n" \
|
|
|
|
".section .fixup,\"ax\"\n" \
|
|
|
|
"3: li %0,%3\n" \
|
|
|
|
" li %1,0\n" \
|
|
|
|
" b 2b\n" \
|
|
|
|
".previous\n" \
|
2016-10-13 12:42:53 +07:00
|
|
|
EX_TABLE(1b, 3b) \
|
2005-10-29 14:51:31 +07:00
|
|
|
: "=r" (err), "=r" (x) \
|
2008-07-17 14:17:52 +07:00
|
|
|
: "b" (addr), "i" (-EFAULT), "0" (err))
|
2005-10-29 14:51:31 +07:00
|
|
|
|
2005-10-31 14:39:20 +07:00
|
|
|
#ifdef __powerpc64__
|
|
|
|
#define __get_user_asm2(x, addr, err) \
|
|
|
|
__get_user_asm(x, addr, err, "ld")
|
|
|
|
#else /* __powerpc64__ */
|
|
|
|
#define __get_user_asm2(x, addr, err) \
|
2005-10-29 14:51:31 +07:00
|
|
|
__asm__ __volatile__( \
|
|
|
|
"1: lwz %1,0(%2)\n" \
|
|
|
|
"2: lwz %1+1,4(%2)\n" \
|
|
|
|
"3:\n" \
|
|
|
|
".section .fixup,\"ax\"\n" \
|
|
|
|
"4: li %0,%3\n" \
|
|
|
|
" li %1,0\n" \
|
|
|
|
" li %1+1,0\n" \
|
|
|
|
" b 3b\n" \
|
|
|
|
".previous\n" \
|
2016-10-13 12:42:53 +07:00
|
|
|
EX_TABLE(1b, 4b) \
|
|
|
|
EX_TABLE(2b, 4b) \
|
2005-10-29 14:51:31 +07:00
|
|
|
: "=r" (err), "=&r" (x) \
|
2008-07-17 14:17:52 +07:00
|
|
|
: "b" (addr), "i" (-EFAULT), "0" (err))
|
2005-10-29 14:51:31 +07:00
|
|
|
#endif /* __powerpc64__ */
|
|
|
|
|
|
|
|
#define __get_user_size(x, ptr, size, retval) \
|
|
|
|
do { \
|
|
|
|
retval = 0; \
|
|
|
|
__chk_user_ptr(ptr); \
|
2005-10-31 14:39:20 +07:00
|
|
|
if (size > sizeof(x)) \
|
|
|
|
(x) = __get_user_bad(); \
|
2019-04-18 13:51:20 +07:00
|
|
|
allow_read_from_user(ptr, size); \
|
2005-10-29 14:51:31 +07:00
|
|
|
switch (size) { \
|
|
|
|
case 1: __get_user_asm(x, ptr, retval, "lbz"); break; \
|
|
|
|
case 2: __get_user_asm(x, ptr, retval, "lhz"); break; \
|
|
|
|
case 4: __get_user_asm(x, ptr, retval, "lwz"); break; \
|
|
|
|
case 8: __get_user_asm2(x, ptr, retval); break; \
|
|
|
|
default: (x) = __get_user_bad(); \
|
|
|
|
} \
|
2019-04-18 13:51:20 +07:00
|
|
|
prevent_read_from_user(ptr, size); \
|
2005-10-29 14:51:31 +07:00
|
|
|
} while (0)
|
|
|
|
|
2018-07-10 13:20:56 +07:00
|
|
|
/*
|
|
|
|
* This is a type: either unsigned long, if the argument fits into
|
|
|
|
* that type, or otherwise unsigned long long.
|
|
|
|
*/
|
|
|
|
#define __long_type(x) \
|
|
|
|
__typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
|
|
|
|
|
2005-10-29 14:51:31 +07:00
|
|
|
#define __get_user_nocheck(x, ptr, size) \
|
|
|
|
({ \
|
|
|
|
long __gu_err; \
|
2018-07-10 13:20:56 +07:00
|
|
|
__long_type(*(ptr)) __gu_val; \
|
2018-09-14 11:06:48 +07:00
|
|
|
__typeof__(*(ptr)) __user *__gu_addr = (ptr); \
|
2005-10-29 14:51:31 +07:00
|
|
|
__chk_user_ptr(ptr); \
|
2006-05-03 20:02:04 +07:00
|
|
|
if (!is_kernel_addr((unsigned long)__gu_addr)) \
|
2013-05-26 21:31:38 +07:00
|
|
|
might_fault(); \
|
2018-04-24 11:15:58 +07:00
|
|
|
barrier_nospec(); \
|
2006-05-03 20:02:04 +07:00
|
|
|
__get_user_size(__gu_val, __gu_addr, (size), __gu_err); \
|
2005-10-29 14:51:31 +07:00
|
|
|
(x) = (__typeof__(*(ptr)))__gu_val; \
|
|
|
|
__gu_err; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define __get_user_check(x, ptr, size) \
|
|
|
|
({ \
|
|
|
|
long __gu_err = -EFAULT; \
|
2018-07-10 13:20:56 +07:00
|
|
|
__long_type(*(ptr)) __gu_val = 0; \
|
2018-09-14 11:06:48 +07:00
|
|
|
__typeof__(*(ptr)) __user *__gu_addr = (ptr); \
|
2013-05-26 21:31:38 +07:00
|
|
|
might_fault(); \
|
Remove 'type' argument from access_ok() function
Nobody has actually used the type (VERIFY_READ vs VERIFY_WRITE) argument
of the user address range verification function since we got rid of the
old racy i386-only code to walk page tables by hand.
It existed because the original 80386 would not honor the write protect
bit when in kernel mode, so you had to do COW by hand before doing any
user access. But we haven't supported that in a long time, and these
days the 'type' argument is a purely historical artifact.
A discussion about extending 'user_access_begin()' to do the range
checking resulted this patch, because there is no way we're going to
move the old VERIFY_xyz interface to that model. And it's best done at
the end of the merge window when I've done most of my merges, so let's
just get this done once and for all.
This patch was mostly done with a sed-script, with manual fix-ups for
the cases that weren't of the trivial 'access_ok(VERIFY_xyz' form.
There were a couple of notable cases:
- csky still had the old "verify_area()" name as an alias.
- the iter_iov code had magical hardcoded knowledge of the actual
values of VERIFY_{READ,WRITE} (not that they mattered, since nothing
really used it)
- microblaze used the type argument for a debug printout
but other than those oddities this should be a total no-op patch.
I tried to fix up all architectures, did fairly extensive grepping for
access_ok() uses, and the changes are trivial, but I may have missed
something. Any missed conversion should be trivially fixable, though.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-01-04 09:57:57 +07:00
|
|
|
if (access_ok(__gu_addr, (size))) { \
|
2018-04-24 11:15:58 +07:00
|
|
|
barrier_nospec(); \
|
2005-10-29 14:51:31 +07:00
|
|
|
__get_user_size(__gu_val, __gu_addr, (size), __gu_err); \
|
2018-04-24 11:15:58 +07:00
|
|
|
} \
|
2014-12-14 23:52:51 +07:00
|
|
|
(x) = (__force __typeof__(*(ptr)))__gu_val; \
|
2005-10-29 14:51:31 +07:00
|
|
|
__gu_err; \
|
|
|
|
})
|
|
|
|
|
2007-04-11 13:13:19 +07:00
|
|
|
#define __get_user_nosleep(x, ptr, size) \
|
|
|
|
({ \
|
|
|
|
long __gu_err; \
|
2018-07-10 13:20:56 +07:00
|
|
|
__long_type(*(ptr)) __gu_val; \
|
2018-09-14 11:06:48 +07:00
|
|
|
__typeof__(*(ptr)) __user *__gu_addr = (ptr); \
|
2007-04-11 13:13:19 +07:00
|
|
|
__chk_user_ptr(ptr); \
|
2018-04-24 11:15:58 +07:00
|
|
|
barrier_nospec(); \
|
2007-04-11 13:13:19 +07:00
|
|
|
__get_user_size(__gu_val, __gu_addr, (size), __gu_err); \
|
2014-12-14 23:52:51 +07:00
|
|
|
(x) = (__force __typeof__(*(ptr)))__gu_val; \
|
2007-04-11 13:13:19 +07:00
|
|
|
__gu_err; \
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2005-10-29 14:51:31 +07:00
|
|
|
/* more complex routines */
|
|
|
|
|
|
|
|
extern unsigned long __copy_tofrom_user(void __user *to,
|
|
|
|
const void __user *from, unsigned long size);
|
|
|
|
|
2017-06-26 08:30:57 +07:00
|
|
|
#ifdef __powerpc64__
|
2017-03-22 03:35:08 +07:00
|
|
|
static inline unsigned long
|
|
|
|
raw_copy_in_user(void __user *to, const void __user *from, unsigned long n)
|
|
|
|
{
|
2019-04-18 13:51:20 +07:00
|
|
|
unsigned long ret;
|
|
|
|
|
2019-03-06 08:10:38 +07:00
|
|
|
barrier_nospec();
|
2019-04-18 13:51:20 +07:00
|
|
|
allow_user_access(to, from, n);
|
|
|
|
ret = __copy_tofrom_user(to, from, n);
|
|
|
|
prevent_user_access(to, from, n);
|
|
|
|
return ret;
|
2017-03-22 03:35:08 +07:00
|
|
|
}
|
2005-11-01 11:53:19 +07:00
|
|
|
#endif /* __powerpc64__ */
|
|
|
|
|
2017-03-22 03:35:08 +07:00
|
|
|
static inline unsigned long raw_copy_from_user(void *to,
|
2005-10-31 14:39:20 +07:00
|
|
|
const void __user *from, unsigned long n)
|
2005-10-29 14:51:31 +07:00
|
|
|
{
|
2019-04-18 13:51:20 +07:00
|
|
|
unsigned long ret;
|
2005-10-29 14:51:31 +07:00
|
|
|
if (__builtin_constant_p(n) && (n <= 8)) {
|
2019-04-18 13:51:20 +07:00
|
|
|
ret = 1;
|
2005-10-29 14:51:31 +07:00
|
|
|
|
|
|
|
switch (n) {
|
|
|
|
case 1:
|
2018-04-24 11:15:58 +07:00
|
|
|
barrier_nospec();
|
2005-10-29 14:51:31 +07:00
|
|
|
__get_user_size(*(u8 *)to, from, 1, ret);
|
|
|
|
break;
|
|
|
|
case 2:
|
2018-04-24 11:15:58 +07:00
|
|
|
barrier_nospec();
|
2005-10-29 14:51:31 +07:00
|
|
|
__get_user_size(*(u16 *)to, from, 2, ret);
|
|
|
|
break;
|
|
|
|
case 4:
|
2018-04-24 11:15:58 +07:00
|
|
|
barrier_nospec();
|
2005-10-29 14:51:31 +07:00
|
|
|
__get_user_size(*(u32 *)to, from, 4, ret);
|
|
|
|
break;
|
|
|
|
case 8:
|
2018-04-24 11:15:58 +07:00
|
|
|
barrier_nospec();
|
2005-10-29 14:51:31 +07:00
|
|
|
__get_user_size(*(u64 *)to, from, 8, ret);
|
|
|
|
break;
|
|
|
|
}
|
2005-11-01 11:53:19 +07:00
|
|
|
if (ret == 0)
|
|
|
|
return 0;
|
2005-10-29 14:51:31 +07:00
|
|
|
}
|
2016-06-24 05:10:01 +07:00
|
|
|
|
2018-04-24 11:15:58 +07:00
|
|
|
barrier_nospec();
|
2019-04-18 13:51:20 +07:00
|
|
|
allow_read_from_user(from, n);
|
|
|
|
ret = __copy_tofrom_user((__force void __user *)to, from, n);
|
|
|
|
prevent_read_from_user(from, n);
|
|
|
|
return ret;
|
2005-10-29 14:51:31 +07:00
|
|
|
}
|
|
|
|
|
2017-03-22 03:35:08 +07:00
|
|
|
static inline unsigned long raw_copy_to_user(void __user *to,
|
2005-10-31 14:39:20 +07:00
|
|
|
const void *from, unsigned long n)
|
2005-10-29 14:51:31 +07:00
|
|
|
{
|
2019-04-18 13:51:20 +07:00
|
|
|
unsigned long ret;
|
2005-10-29 14:51:31 +07:00
|
|
|
if (__builtin_constant_p(n) && (n <= 8)) {
|
2019-04-18 13:51:20 +07:00
|
|
|
ret = 1;
|
2005-10-29 14:51:31 +07:00
|
|
|
|
|
|
|
switch (n) {
|
|
|
|
case 1:
|
|
|
|
__put_user_size(*(u8 *)from, (u8 __user *)to, 1, ret);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
__put_user_size(*(u16 *)from, (u16 __user *)to, 2, ret);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
__put_user_size(*(u32 *)from, (u32 __user *)to, 4, ret);
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
__put_user_size(*(u64 *)from, (u64 __user *)to, 8, ret);
|
|
|
|
break;
|
|
|
|
}
|
2005-11-01 11:53:19 +07:00
|
|
|
if (ret == 0)
|
|
|
|
return 0;
|
2005-10-29 14:51:31 +07:00
|
|
|
}
|
2016-09-01 06:04:21 +07:00
|
|
|
|
2019-04-18 13:51:20 +07:00
|
|
|
allow_write_to_user(to, n);
|
|
|
|
ret = __copy_tofrom_user(to, (__force const void __user *)from, n);
|
|
|
|
prevent_write_to_user(to, n);
|
|
|
|
return ret;
|
2005-10-29 14:51:31 +07:00
|
|
|
}
|
|
|
|
|
2019-08-20 15:13:52 +07:00
|
|
|
static __always_inline unsigned long __must_check
|
|
|
|
copy_to_user_mcsafe(void __user *to, const void *from, unsigned long n)
|
|
|
|
{
|
|
|
|
if (likely(check_copy_size(from, n, true))) {
|
|
|
|
if (access_ok(to, n)) {
|
|
|
|
allow_write_to_user(to, n);
|
|
|
|
n = memcpy_mcsafe((void *)to, from, n);
|
|
|
|
prevent_write_to_user(to, n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2005-10-29 14:51:31 +07:00
|
|
|
extern unsigned long __clear_user(void __user *addr, unsigned long size);
|
|
|
|
|
|
|
|
static inline unsigned long clear_user(void __user *addr, unsigned long size)
|
|
|
|
{
|
2019-04-18 13:51:20 +07:00
|
|
|
unsigned long ret = size;
|
2013-05-26 21:31:38 +07:00
|
|
|
might_fault();
|
2019-04-18 13:51:20 +07:00
|
|
|
if (likely(access_ok(addr, size))) {
|
|
|
|
allow_write_to_user(addr, size);
|
|
|
|
ret = __clear_user(addr, size);
|
|
|
|
prevent_write_to_user(addr, size);
|
|
|
|
}
|
|
|
|
return ret;
|
2005-10-29 14:51:31 +07:00
|
|
|
}
|
|
|
|
|
2012-05-28 10:03:47 +07:00
|
|
|
extern long strncpy_from_user(char *dst, const char __user *src, long count);
|
|
|
|
extern __must_check long strnlen_user(const char __user *str, long n);
|
2005-10-29 14:51:31 +07:00
|
|
|
|
2017-10-19 14:13:55 +07:00
|
|
|
extern long __copy_from_user_flushcache(void *dst, const void __user *src,
|
|
|
|
unsigned size);
|
|
|
|
extern void memcpy_page_flushcache(char *to, struct page *page, size_t offset,
|
|
|
|
size_t len);
|
|
|
|
|
2005-10-29 14:51:31 +07:00
|
|
|
#endif /* _ARCH_POWERPC_UACCESS_H */
|