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 14:07:57 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
linux/compiler.h: Split into compiler.h and compiler_types.h
linux/compiler.h is included indirectly by linux/types.h via
uapi/linux/types.h -> uapi/linux/posix_types.h -> linux/stddef.h
-> uapi/linux/stddef.h and is needed to provide a proper definition of
offsetof.
Unfortunately, compiler.h requires a definition of
smp_read_barrier_depends() for defining lockless_dereference() and soon
for defining READ_ONCE(), which means that all
users of READ_ONCE() will need to include asm/barrier.h to avoid splats
such as:
In file included from include/uapi/linux/stddef.h:1:0,
from include/linux/stddef.h:4,
from arch/h8300/kernel/asm-offsets.c:11:
include/linux/list.h: In function 'list_empty':
>> include/linux/compiler.h:343:2: error: implicit declaration of function 'smp_read_barrier_depends' [-Werror=implicit-function-declaration]
smp_read_barrier_depends(); /* Enforce dependency ordering from x */ \
^
A better alternative is to include asm/barrier.h in linux/compiler.h,
but this requires a type definition for "bool" on some architectures
(e.g. x86), which is defined later by linux/types.h. Type "bool" is also
used directly in linux/compiler.h, so the whole thing is pretty fragile.
This patch splits compiler.h in two: compiler_types.h contains type
annotations, definitions and the compiler-specific parts, whereas
compiler.h #includes compiler-types.h and additionally defines macros
such as {READ,WRITE.ACCESS}_ONCE().
uapi/linux/stddef.h and linux/linkage.h are then moved over to include
linux/compiler_types.h, which fixes the build for h8 and blackfin.
Signed-off-by: Will Deacon <will.deacon@arm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1508840570-22169-2-git-send-email-will.deacon@arm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2017-10-24 10:22:46 +00:00
|
|
|
#ifndef __LINUX_COMPILER_TYPES_H
|
2012-11-20 21:13:10 +00:00
|
|
|
#error "Please don't include <linux/compiler-clang.h> directly, include <linux/compiler.h> instead."
|
|
|
|
#endif
|
|
|
|
|
2019-01-02 20:57:49 +00:00
|
|
|
/* Compiler specific definitions for Clang compiler */
|
|
|
|
|
2023-05-26 10:23:48 +00:00
|
|
|
/*
|
|
|
|
* Clang prior to 17 is being silly and considers many __cleanup() variables
|
|
|
|
* as unused (because they are, their sole purpose is to go out of scope).
|
|
|
|
*
|
|
|
|
* https://reviews.llvm.org/D152180
|
|
|
|
*/
|
|
|
|
#undef __cleanup
|
|
|
|
#define __cleanup(func) __maybe_unused __attribute__((__cleanup__(func)))
|
|
|
|
|
2016-02-08 14:38:32 +00:00
|
|
|
/* same as gcc, this was present in clang-2.6 so we can assume it works
|
|
|
|
* with any version that can compile the kernel
|
|
|
|
*/
|
|
|
|
#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
|
include/linux/compiler-clang.h: handle randomizable anonymous structs
The GCC randomize layout plugin can randomize the member offsets of
sensitive kernel data structures. To use this feature, certain
annotations and members are added to the structures which affect the
member offsets even if this plugin is not used.
All of these structures are completely randomized, except for task_struct
which leaves out some of its members. All the other members are wrapped
within an anonymous struct with the __randomize_layout attribute. This is
done using the randomized_struct_fields_start and
randomized_struct_fields_end defines.
When the plugin is disabled, the behaviour of this attribute can vary
based on the GCC version. For GCC 5.1+, this attribute maps to
__designated_init otherwise it is just an empty define but the anonymous
structure is still present. For other compilers, both
randomized_struct_fields_start and randomized_struct_fields_end default
to empty defines meaning the anonymous structure is not introduced at
all.
So, if a module compiled with Clang, such as a BPF program, needs to
access task_struct fields such as pid and comm, the offsets of these
members as recognized by Clang are different from those recognized by
modules compiled with GCC. If GCC 4.6+ is used to build the kernel,
this can be solved by introducing appropriate defines for Clang so that
the anonymous structure is seen when determining the offsets for the
members.
Link: http://lkml.kernel.org/r/20171109064645.25581-1-sandipan@linux.vnet.ibm.com
Signed-off-by: Sandipan Das <sandipan@linux.vnet.ibm.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Kate Stewart <kstewart@linuxfoundation.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Cc: Alexei Starovoitov <ast@fb.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-11-17 23:27:28 +00:00
|
|
|
|
2018-02-06 23:36:03 +00:00
|
|
|
/* all clang versions usable with the kernel support KASAN ABI version 5 */
|
|
|
|
#define KASAN_ABI_VERSION 5
|
|
|
|
|
2021-07-01 01:56:49 +00:00
|
|
|
/*
|
|
|
|
* Note: Checking __has_feature(*_sanitizer) is only true if the feature is
|
|
|
|
* enabled. Therefore it is not required to additionally check defined(CONFIG_*)
|
|
|
|
* to avoid adding redundant attributes in other configurations.
|
|
|
|
*/
|
|
|
|
|
2018-12-28 08:29:53 +00:00
|
|
|
#if __has_feature(address_sanitizer) || __has_feature(hwaddress_sanitizer)
|
2019-11-20 09:41:43 +00:00
|
|
|
/* Emulate GCC's __SANITIZE_ADDRESS__ flag */
|
2018-02-06 23:36:03 +00:00
|
|
|
#define __SANITIZE_ADDRESS__
|
2018-12-28 08:29:53 +00:00
|
|
|
#define __no_sanitize_address \
|
|
|
|
__attribute__((no_sanitize("address", "hwaddress")))
|
|
|
|
#else
|
|
|
|
#define __no_sanitize_address
|
2018-02-06 23:36:03 +00:00
|
|
|
#endif
|
2018-02-19 10:50:57 +00:00
|
|
|
|
2019-11-14 18:02:54 +00:00
|
|
|
#if __has_feature(thread_sanitizer)
|
|
|
|
/* emulate gcc's __SANITIZE_THREAD__ flag */
|
|
|
|
#define __SANITIZE_THREAD__
|
|
|
|
#define __no_sanitize_thread \
|
|
|
|
__attribute__((no_sanitize("thread")))
|
|
|
|
#else
|
|
|
|
#define __no_sanitize_thread
|
|
|
|
#endif
|
|
|
|
|
linux/compiler-clang.h: define HAVE_BUILTIN_BSWAP*
Separating compiler-clang.h from compiler-gcc.h inadventently dropped the
definitions of the three HAVE_BUILTIN_BSWAP macros, which requires falling
back to the open-coded version and hoping that the compiler detects it.
Since all versions of clang support the __builtin_bswap interfaces, add
back the flags and have the headers pick these up automatically.
This results in a 4% improvement of compilation speed for arm defconfig.
Note: it might also be worth revisiting which architectures set
CONFIG_ARCH_USE_BUILTIN_BSWAP for one compiler or the other, today this is
set on six architectures (arm32, csky, mips, powerpc, s390, x86), while
another ten architectures define custom helpers (alpha, arc, ia64, m68k,
mips, nios2, parisc, sh, sparc, xtensa), and the rest (arm64, h8300,
hexagon, microblaze, nds32, openrisc, riscv) just get the unoptimized
version and rely on the compiler to detect it.
A long time ago, the compiler builtins were architecture specific, but
nowadays, all compilers that are able to build the kernel have correct
implementations of them, though some may not be as optimized as the inline
asm versions.
The patch that dropped the optimization landed in v4.19, so as discussed
it would be fairly safe to backport this revert to stable kernels to the
4.19/5.4/5.10 stable kernels, but there is a remaining risk for
regressions, and it has no known side-effects besides compile speed.
Link: https://lkml.kernel.org/r/20210226161151.2629097-1-arnd@kernel.org
Link: https://lore.kernel.org/lkml/20210225164513.3667778-1-arnd@kernel.org/
Fixes: 815f0ddb346c ("include/linux/compiler*.h: make compiler-*.h mutually exclusive")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Acked-by: Miguel Ojeda <ojeda@kernel.org>
Acked-by: Nick Desaulniers <ndesaulniers@google.com>
Acked-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Nick Hu <nickhu@andestech.com>
Cc: Greentime Hu <green.hu@gmail.com>
Cc: Vincent Chen <deanbo422@gmail.com>
Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Guo Ren <guoren@kernel.org>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: Marco Elver <elver@google.com>
Cc: Arvind Sankar <nivedita@alum.mit.edu>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2021-03-13 05:07:47 +00:00
|
|
|
#if defined(CONFIG_ARCH_USE_BUILTIN_BSWAP)
|
|
|
|
#define __HAVE_BUILTIN_BSWAP32__
|
|
|
|
#define __HAVE_BUILTIN_BSWAP64__
|
|
|
|
#define __HAVE_BUILTIN_BSWAP16__
|
|
|
|
#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */
|
|
|
|
|
2020-06-04 05:58:11 +00:00
|
|
|
#if __has_feature(undefined_behavior_sanitizer)
|
|
|
|
/* GCC does not have __SANITIZE_UNDEFINED__ */
|
|
|
|
#define __no_sanitize_undefined \
|
|
|
|
__attribute__((no_sanitize("undefined")))
|
|
|
|
#else
|
|
|
|
#define __no_sanitize_undefined
|
|
|
|
#endif
|
|
|
|
|
2022-09-15 15:03:41 +00:00
|
|
|
#if __has_feature(memory_sanitizer)
|
|
|
|
#define __SANITIZE_MEMORY__
|
|
|
|
/*
|
|
|
|
* Unlike other sanitizers, KMSAN still inserts code into functions marked with
|
|
|
|
* no_sanitize("kernel-memory"). Using disable_sanitizer_instrumentation
|
|
|
|
* provides the behavior consistent with other __no_sanitize_ attributes,
|
|
|
|
* guaranteeing that __no_sanitize_memory functions remain uninstrumented.
|
|
|
|
*/
|
|
|
|
#define __no_sanitize_memory __disable_sanitizer_instrumentation
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The __no_kmsan_checks attribute ensures that a function does not produce
|
|
|
|
* false positive reports by:
|
|
|
|
* - initializing all local variables and memory stores in this function;
|
|
|
|
* - skipping all shadow checks;
|
|
|
|
* - passing initialized arguments to this function's callees.
|
|
|
|
*/
|
|
|
|
#define __no_kmsan_checks __attribute__((no_sanitize("kernel-memory")))
|
|
|
|
#else
|
|
|
|
#define __no_sanitize_memory
|
|
|
|
#define __no_kmsan_checks
|
|
|
|
#endif
|
|
|
|
|
2021-07-01 01:56:49 +00:00
|
|
|
/*
|
|
|
|
* Support for __has_feature(coverage_sanitizer) was added in Clang 13 together
|
|
|
|
* with no_sanitize("coverage"). Prior versions of Clang support coverage
|
|
|
|
* instrumentation, but cannot be queried for support by the preprocessor.
|
|
|
|
*/
|
|
|
|
#if __has_feature(coverage_sanitizer)
|
|
|
|
#define __no_sanitize_coverage __attribute__((no_sanitize("coverage")))
|
|
|
|
#else
|
|
|
|
#define __no_sanitize_coverage
|
|
|
|
#endif
|
|
|
|
|
2020-04-27 16:00:07 +00:00
|
|
|
#if __has_feature(shadow_call_stack)
|
|
|
|
# define __noscs __attribute__((__no_sanitize__("shadow-call-stack")))
|
|
|
|
#endif
|
add support for Clang CFI
This change adds support for Clang’s forward-edge Control Flow
Integrity (CFI) checking. With CONFIG_CFI_CLANG, the compiler
injects a runtime check before each indirect function call to ensure
the target is a valid function with the correct static type. This
restricts possible call targets and makes it more difficult for
an attacker to exploit bugs that allow the modification of stored
function pointers. For more details, see:
https://clang.llvm.org/docs/ControlFlowIntegrity.html
Clang requires CONFIG_LTO_CLANG to be enabled with CFI to gain
visibility to possible call targets. Kernel modules are supported
with Clang’s cross-DSO CFI mode, which allows checking between
independently compiled components.
With CFI enabled, the compiler injects a __cfi_check() function into
the kernel and each module for validating local call targets. For
cross-module calls that cannot be validated locally, the compiler
calls the global __cfi_slowpath_diag() function, which determines
the target module and calls the correct __cfi_check() function. This
patch includes a slowpath implementation that uses __module_address()
to resolve call targets, and with CONFIG_CFI_CLANG_SHADOW enabled, a
shadow map that speeds up module look-ups by ~3x.
Clang implements indirect call checking using jump tables and
offers two methods of generating them. With canonical jump tables,
the compiler renames each address-taken function to <function>.cfi
and points the original symbol to a jump table entry, which passes
__cfi_check() validation. This isn’t compatible with stand-alone
assembly code, which the compiler doesn’t instrument, and would
result in indirect calls to assembly code to fail. Therefore, we
default to using non-canonical jump tables instead, where the compiler
generates a local jump table entry <function>.cfi_jt for each
address-taken function, and replaces all references to the function
with the address of the jump table entry.
Note that because non-canonical jump table addresses are local
to each component, they break cross-module function address
equality. Specifically, the address of a global function will be
different in each module, as it's replaced with the address of a local
jump table entry. If this address is passed to a different module,
it won’t match the address of the same function taken there. This
may break code that relies on comparing addresses passed from other
components.
CFI checking can be disabled in a function with the __nocfi attribute.
Additionally, CFI can be disabled for an entire compilation unit by
filtering out CC_FLAGS_CFI.
By default, CFI failures result in a kernel panic to stop a potential
exploit. CONFIG_CFI_PERMISSIVE enables a permissive mode, where the
kernel prints out a rate-limited warning instead, and allows execution
to continue. This option is helpful for locating type mismatches, but
should only be enabled during development.
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20210408182843.1754385-2-samitolvanen@google.com
2021-04-08 18:28:26 +00:00
|
|
|
|
2022-09-08 21:54:47 +00:00
|
|
|
#if __has_feature(kcfi)
|
|
|
|
/* Disable CFI checking inside a function. */
|
|
|
|
#define __nocfi __attribute__((__no_sanitize__("kcfi")))
|
2022-04-05 22:16:18 +00:00
|
|
|
#endif
|
|
|
|
|
2022-03-04 22:46:42 +00:00
|
|
|
/*
|
|
|
|
* Turn individual warnings and errors on and off locally, depending
|
|
|
|
* on version.
|
|
|
|
*/
|
|
|
|
#define __diag_clang(version, severity, s) \
|
|
|
|
__diag_clang_ ## version(__diag_clang_ ## severity s)
|
|
|
|
|
|
|
|
/* Severity used in pragma directives */
|
|
|
|
#define __diag_clang_ignore ignored
|
|
|
|
#define __diag_clang_warn warning
|
|
|
|
#define __diag_clang_error error
|
|
|
|
|
|
|
|
#define __diag_str1(s) #s
|
|
|
|
#define __diag_str(s) __diag_str1(s)
|
|
|
|
#define __diag(s) _Pragma(__diag_str(clang diagnostic s))
|
|
|
|
|
|
|
|
#if CONFIG_CLANG_VERSION >= 110000
|
|
|
|
#define __diag_clang_11(s) __diag(s)
|
|
|
|
#else
|
|
|
|
#define __diag_clang_11(s)
|
|
|
|
#endif
|
2022-03-04 22:46:43 +00:00
|
|
|
|
|
|
|
#define __diag_ignore_all(option, comment) \
|
|
|
|
__diag_clang(11, ignore, option)
|