summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Kconfig.debug53
-rw-r--r--lib/Kconfig.kasan9
-rw-r--r--lib/Kconfig.ubsan128
-rw-r--r--lib/Makefile4
-rw-r--r--lib/asn1_decoder.c4
-rw-r--r--lib/assoc_array.c2
-rw-r--r--lib/bootconfig.c4
-rw-r--r--lib/cmdline.c27
-rw-r--r--lib/cmdline_kunit.c100
-rw-r--r--lib/cpumask.c18
-rw-r--r--lib/crypto/blake2s-selftest.c2
-rw-r--r--lib/crypto/blake2s.c2
-rw-r--r--lib/crypto/curve25519.c2
-rw-r--r--lib/crypto/sha256.c214
-rw-r--r--lib/digsig.c2
-rw-r--r--lib/dim/net_dim.c2
-rw-r--r--lib/dim/rdma_dim.c4
-rw-r--r--lib/dump_stack.c2
-rw-r--r--lib/dynamic_debug.c9
-rw-r--r--lib/errname.c1
-rw-r--r--lib/error-inject.c2
-rw-r--r--lib/errseq.c1
-rw-r--r--lib/find_bit.c3
-rw-r--r--lib/fonts/font_10x18.c1
-rw-r--r--lib/fonts/font_6x10.c1
-rw-r--r--lib/fonts/font_6x11.c1
-rw-r--r--lib/fonts/font_6x8.c1
-rw-r--r--lib/fonts/font_7x14.c1
-rw-r--r--lib/fonts/font_8x16.c1
-rw-r--r--lib/fonts/font_8x8.c1
-rw-r--r--lib/fonts/font_acorn_8x8.c1
-rw-r--r--lib/fonts/font_mini_4x6.c1
-rw-r--r--lib/fonts/font_pearl_8x8.c1
-rw-r--r--lib/fonts/font_sun12x22.c1
-rw-r--r--lib/fonts/font_sun8x16.c1
-rw-r--r--lib/fonts/font_ter16x32.c1
-rw-r--r--lib/glob.c2
-rw-r--r--lib/kstrtox.c1
-rw-r--r--lib/kunit/test.c59
-rw-r--r--lib/locking-selftest.c98
-rw-r--r--lib/lz4/lz4_decompress.c6
-rw-r--r--lib/lz4/lz4defs.h1
-rw-r--r--lib/lzo/lzo1x_compress.c2
-rw-r--r--lib/math/div64.c4
-rw-r--r--lib/math/int_pow.c2
-rw-r--r--lib/math/int_sqrt.c3
-rw-r--r--lib/math/reciprocal_div.c9
-rw-r--r--lib/mpi/ec.c3
-rw-r--r--lib/nlattr.c44
-rw-r--r--lib/sha1.c2
-rw-r--r--lib/siphash.c36
-rw-r--r--lib/smp_processor_id.c5
-rw-r--r--lib/stackdepot.c11
-rw-r--r--lib/string.c4
-rw-r--r--lib/strncpy_from_user.c19
-rw-r--r--lib/syscall.c11
-rw-r--r--lib/test_firmware.c9
-rw-r--r--lib/test_free_pages.c5
-rw-r--r--lib/test_kasan_module.c29
-rw-r--r--lib/test_kmod.c26
-rw-r--r--lib/test_lockup.c16
-rw-r--r--lib/test_ubsan.c74
-rw-r--r--lib/ts_fsm.c2
-rw-r--r--lib/ubsan.c2
-rw-r--r--lib/vsprintf.c15
-rw-r--r--lib/xz/xz_dec_lzma2.c4
-rw-r--r--lib/xz/xz_dec_stream.c16
-rw-r--r--lib/zlib_dfltcc/dfltcc_inflate.c3
-rw-r--r--lib/zlib_inflate/inflate.c24
-rw-r--r--lib/zstd/bitstream.h11
-rw-r--r--lib/zstd/compress.c2
-rw-r--r--lib/zstd/decompress.c12
-rw-r--r--lib/zstd/huf_compress.c5
73 files changed, 814 insertions, 371 deletions
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index c789b39ed527..7d7097c5dc58 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -274,6 +274,15 @@ config DEBUG_INFO_BTF
Turning this on expects presence of pahole tool, which will convert
DWARF type info into equivalent deduplicated BTF type info.
+config PAHOLE_HAS_SPLIT_BTF
+ def_bool $(success, test `$(PAHOLE) --version | sed -E 's/v([0-9]+)\.([0-9]+)/\1\2/'` -ge "119")
+
+config DEBUG_INFO_BTF_MODULES
+ def_bool y
+ depends on DEBUG_INFO_BTF && MODULES && PAHOLE_HAS_SPLIT_BTF
+ help
+ Generate compact split BTF type information for kernel modules.
+
config GDB_SCRIPTS
bool "Provide GDB scripts for kernel debugging"
help
@@ -849,9 +858,31 @@ config DEBUG_PER_CPU_MAPS
Say N if unsure.
+config DEBUG_KMAP_LOCAL
+ bool "Debug kmap_local temporary mappings"
+ depends on DEBUG_KERNEL && KMAP_LOCAL
+ help
+ This option enables additional error checking for the kmap_local
+ infrastructure. Disable for production use.
+
+config ARCH_SUPPORTS_KMAP_LOCAL_FORCE_MAP
+ bool
+
+config DEBUG_KMAP_LOCAL_FORCE_MAP
+ bool "Enforce kmap_local temporary mappings"
+ depends on DEBUG_KERNEL && ARCH_SUPPORTS_KMAP_LOCAL_FORCE_MAP
+ select KMAP_LOCAL
+ select DEBUG_KMAP_LOCAL
+ help
+ This option enforces temporary mappings through the kmap_local
+ mechanism for non-highmem pages and on non-highmem systems.
+ Disable this for production systems!
+
config DEBUG_HIGHMEM
bool "Highmem debugging"
depends on DEBUG_KERNEL && HIGHMEM
+ select DEBUG_KMAP_LOCAL_FORCE_MAP if ARCH_SUPPORTS_KMAP_LOCAL_FORCE_MAP
+ select DEBUG_KMAP_LOCAL
help
This option enables additional error checking for high memory
systems. Disable for production systems.
@@ -2226,6 +2257,17 @@ config BITFIELD_KUNIT
If unsure, say N.
+config RESOURCE_KUNIT_TEST
+ tristate "KUnit test for resource API"
+ depends on KUNIT
+ help
+ This builds the resource API unit test.
+ Tests the logic of API provided by resource.c and ioport.h.
+ For more information on KUnit and unit tests in general please refer
+ to the KUnit documentation in Documentation/dev-tools/kunit/.
+
+ If unsure, say N.
+
config SYSCTL_KUNIT_TEST
tristate "KUnit test for sysctl" if !KUNIT_ALL_TESTS
depends on KUNIT
@@ -2269,6 +2311,17 @@ config LINEAR_RANGES_TEST
If unsure, say N.
+config CMDLINE_KUNIT_TEST
+ tristate "KUnit test for cmdline API"
+ depends on KUNIT
+ help
+ This builds the cmdline API unit test.
+ Tests the logic of API provided by cmdline.c.
+ For more information on KUnit and unit tests in general please refer
+ to the KUnit documentation in Documentation/dev-tools/kunit/.
+
+ If unsure, say N.
+
config BITS_TEST
tristate "KUnit test for bits.h"
depends on KUNIT
diff --git a/lib/Kconfig.kasan b/lib/Kconfig.kasan
index 542a9c18398e..8fb097057fec 100644
--- a/lib/Kconfig.kasan
+++ b/lib/Kconfig.kasan
@@ -136,15 +136,6 @@ config KASAN_STACK
default 1 if KASAN_STACK_ENABLE || CC_IS_GCC
default 0
-config KASAN_S390_4_LEVEL_PAGING
- bool "KASan: use 4-level paging"
- depends on S390
- help
- Compiling the kernel with KASan disables automatic 3-level vs
- 4-level paging selection. 3-level paging is used by default (up
- to 3TB of RAM with KASan enabled). This options allows to force
- 4-level paging instead.
-
config KASAN_SW_TAGS_IDENTIFY
bool "Enable memory corruption identification"
depends on KASAN_SW_TAGS
diff --git a/lib/Kconfig.ubsan b/lib/Kconfig.ubsan
index 58f8d03d037b..8b635fd75fe4 100644
--- a/lib/Kconfig.ubsan
+++ b/lib/Kconfig.ubsan
@@ -14,6 +14,7 @@ if UBSAN
config UBSAN_TRAP
bool "On Sanitizer warnings, abort the running kernel code"
+ depends on !COMPILE_TEST
depends on $(cc-option, -fsanitize-undefined-trap-on-error)
help
Building kernels with Sanitizer features enabled tends to grow
@@ -36,10 +37,17 @@ config UBSAN_KCOV_BROKEN
See https://bugs.llvm.org/show_bug.cgi?id=45831 for the status
in newer releases.
+config CC_HAS_UBSAN_BOUNDS
+ def_bool $(cc-option,-fsanitize=bounds)
+
+config CC_HAS_UBSAN_ARRAY_BOUNDS
+ def_bool $(cc-option,-fsanitize=array-bounds)
+
config UBSAN_BOUNDS
bool "Perform array index bounds checking"
default UBSAN
depends on !UBSAN_KCOV_BROKEN
+ depends on CC_HAS_UBSAN_ARRAY_BOUNDS || CC_HAS_UBSAN_BOUNDS
help
This option enables detection of directly indexed out of bounds
array accesses, where the array size is known at compile time.
@@ -47,36 +55,121 @@ config UBSAN_BOUNDS
to the {str,mem}*cpy() family of functions (that is addressed
by CONFIG_FORTIFY_SOURCE).
+config UBSAN_ONLY_BOUNDS
+ def_bool CC_HAS_UBSAN_BOUNDS && !CC_HAS_UBSAN_ARRAY_BOUNDS
+ depends on UBSAN_BOUNDS
+ help
+ This is a weird case: Clang's -fsanitize=bounds includes
+ -fsanitize=local-bounds, but it's trapping-only, so for
+ Clang, we must use -fsanitize=array-bounds when we want
+ traditional array bounds checking enabled. For GCC, we
+ want -fsanitize=bounds.
+
+config UBSAN_ARRAY_BOUNDS
+ def_bool CC_HAS_UBSAN_ARRAY_BOUNDS
+ depends on UBSAN_BOUNDS
+
config UBSAN_LOCAL_BOUNDS
bool "Perform array local bounds checking"
depends on UBSAN_TRAP
- depends on CC_IS_CLANG
depends on !UBSAN_KCOV_BROKEN
+ depends on $(cc-option,-fsanitize=local-bounds)
help
This option enables -fsanitize=local-bounds which traps when an
- exception/error is detected. Therefore, it should be enabled only
- if trapping is expected.
+ exception/error is detected. Therefore, it may only be enabled
+ with CONFIG_UBSAN_TRAP.
+
Enabling this option detects errors due to accesses through a
pointer that is derived from an object of a statically-known size,
where an added offset (which may not be known statically) is
out-of-bounds.
-config UBSAN_MISC
- bool "Enable all other Undefined Behavior sanity checks"
+config UBSAN_SHIFT
+ bool "Perform checking for bit-shift overflows"
+ default UBSAN
+ depends on $(cc-option,-fsanitize=shift)
+ help
+ This option enables -fsanitize=shift which checks for bit-shift
+ operations that overflow to the left or go switch to negative
+ for signed types.
+
+config UBSAN_DIV_ZERO
+ bool "Perform checking for integer divide-by-zero"
+ depends on $(cc-option,-fsanitize=integer-divide-by-zero)
+ help
+ This option enables -fsanitize=integer-divide-by-zero which checks
+ for integer division by zero. This is effectively redundant with the
+ kernel's existing exception handling, though it can provide greater
+ debugging information under CONFIG_UBSAN_REPORT_FULL.
+
+config UBSAN_UNREACHABLE
+ bool "Perform checking for unreachable code"
+ # objtool already handles unreachable checking and gets angry about
+ # seeing UBSan instrumentation located in unreachable places.
+ depends on !STACK_VALIDATION
+ depends on $(cc-option,-fsanitize=unreachable)
+ help
+ This option enables -fsanitize=unreachable which checks for control
+ flow reaching an expected-to-be-unreachable position.
+
+config UBSAN_SIGNED_OVERFLOW
+ bool "Perform checking for signed arithmetic overflow"
+ default UBSAN
+ depends on $(cc-option,-fsanitize=signed-integer-overflow)
+ help
+ This option enables -fsanitize=signed-integer-overflow which checks
+ for overflow of any arithmetic operations with signed integers.
+
+config UBSAN_UNSIGNED_OVERFLOW
+ bool "Perform checking for unsigned arithmetic overflow"
+ depends on $(cc-option,-fsanitize=unsigned-integer-overflow)
+ help
+ This option enables -fsanitize=unsigned-integer-overflow which checks
+ for overflow of any arithmetic operations with unsigned integers. This
+ currently causes x86 to fail to boot.
+
+config UBSAN_OBJECT_SIZE
+ bool "Perform checking for accesses beyond the end of objects"
+ default UBSAN
+ # gcc hugely expands stack usage with -fsanitize=object-size
+ # https://lore.kernel.org/lkml/CAHk-=wjPasyJrDuwDnpHJS2TuQfExwe=px-SzLeN8GFMAQJPmQ@mail.gmail.com/
+ depends on !CC_IS_GCC
+ depends on $(cc-option,-fsanitize=object-size)
+ help
+ This option enables -fsanitize=object-size which checks for accesses
+ beyond the end of objects where the optimizer can determine both the
+ object being operated on and its size, usually seen with bad downcasts,
+ or access to struct members from NULL pointers.
+
+config UBSAN_BOOL
+ bool "Perform checking for non-boolean values used as boolean"
+ default UBSAN
+ depends on $(cc-option,-fsanitize=bool)
+ help
+ This option enables -fsanitize=bool which checks for boolean values being
+ loaded that are neither 0 nor 1.
+
+config UBSAN_ENUM
+ bool "Perform checking for out of bounds enum values"
default UBSAN
+ depends on $(cc-option,-fsanitize=enum)
help
- This option enables all sanity checks that don't have their
- own Kconfig options. Disable this if you only want to have
- individually selected checks.
+ This option enables -fsanitize=enum which checks for values being loaded
+ into an enum that are outside the range of given values for the given enum.
+
+config UBSAN_ALIGNMENT
+ bool "Perform checking for misaligned pointer usage"
+ default !HAVE_EFFICIENT_UNALIGNED_ACCESS
+ depends on !UBSAN_TRAP && !COMPILE_TEST
+ depends on $(cc-option,-fsanitize=alignment)
+ help
+ This option enables the check of unaligned memory accesses.
+ Enabling this option on architectures that support unaligned
+ accesses may produce a lot of false positives.
config UBSAN_SANITIZE_ALL
bool "Enable instrumentation for the entire kernel"
depends on ARCH_HAS_UBSAN_SANITIZE_ALL
-
- # We build with -Wno-maybe-uninitilzed, but we still want to
- # use -Wmaybe-uninitilized in allmodconfig builds.
- # So dependsy bellow used to disable this option in allmodconfig
- depends on !COMPILE_TEST
default y
help
This option activates instrumentation for the entire kernel.
@@ -85,15 +178,6 @@ config UBSAN_SANITIZE_ALL
Enabling this option will get kernel image size increased
significantly.
-config UBSAN_ALIGNMENT
- bool "Enable checks for pointers alignment"
- default !HAVE_EFFICIENT_UNALIGNED_ACCESS
- depends on !UBSAN_TRAP
- help
- This option enables the check of unaligned memory accesses.
- Enabling this option on architectures that support unaligned
- accesses may produce a lot of false positives.
-
config TEST_UBSAN
tristate "Module for testing for undefined behavior detection"
depends on m
diff --git a/lib/Makefile b/lib/Makefile
index ce45af50983a..8598e8796edf 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -107,7 +107,7 @@ obj-$(CONFIG_TEST_FREE_PAGES) += test_free_pages.o
# off the generation of FPU/SSE* instructions for kernel proper but FPU_FLAGS
# get appended last to CFLAGS and thus override those previous compiler options.
#
-FPU_CFLAGS := -mhard-float -msse -msse2
+FPU_CFLAGS := -msse -msse2
ifdef CONFIG_CC_IS_GCC
# Stack alignment mismatch, proceed with caution.
# GCC < 7.1 cannot compile code using `double` and -mpreferred-stack-boundary=3
@@ -120,6 +120,7 @@ ifdef CONFIG_CC_IS_GCC
# -mpreferred-stack-boundary=3 is not between 4 and 12
#
# can be triggered. Otherwise gcc doesn't complain.
+FPU_CFLAGS += -mhard-float
FPU_CFLAGS += $(call cc-option,-msse -mpreferred-stack-boundary=3,-mpreferred-stack-boundary=4)
endif
@@ -352,3 +353,4 @@ obj-$(CONFIG_BITFIELD_KUNIT) += bitfield_kunit.o
obj-$(CONFIG_LIST_KUNIT_TEST) += list-test.o
obj-$(CONFIG_LINEAR_RANGES_TEST) += test_linear_ranges.o
obj-$(CONFIG_BITS_TEST) += test_bits.o
+obj-$(CONFIG_CMDLINE_KUNIT_TEST) += cmdline_kunit.o
diff --git a/lib/asn1_decoder.c b/lib/asn1_decoder.c
index 58f72b25f8e9..13da529e2e72 100644
--- a/lib/asn1_decoder.c
+++ b/lib/asn1_decoder.c
@@ -381,7 +381,7 @@ next_op:
case ASN1_OP_END_SET_ACT:
if (unlikely(!(flags & FLAG_MATCHED)))
goto tag_mismatch;
- /* fall through */
+ fallthrough;
case ASN1_OP_END_SEQ:
case ASN1_OP_END_SET_OF:
@@ -448,7 +448,7 @@ next_op:
pc += asn1_op_lengths[op];
goto next_op;
}
- /* fall through */
+ fallthrough;
case ASN1_OP_ACT:
ret = actions[machine[pc + 1]](context, hdr, tag, data + tdp, len);
diff --git a/lib/assoc_array.c b/lib/assoc_array.c
index 6f4bcf524554..04c98799c3ba 100644
--- a/lib/assoc_array.c
+++ b/lib/assoc_array.c
@@ -1113,7 +1113,7 @@ struct assoc_array_edit *assoc_array_delete(struct assoc_array *array,
index_key))
goto found_leaf;
}
- /* fall through */
+ fallthrough;
case assoc_array_walk_tree_empty:
case assoc_array_walk_found_wrong_shortcut:
default:
diff --git a/lib/bootconfig.c b/lib/bootconfig.c
index 649ed44f199c..9f8c70a98fcf 100644
--- a/lib/bootconfig.c
+++ b/lib/bootconfig.c
@@ -827,7 +827,7 @@ int __init xbc_init(char *buf, const char **emsg, int *epos)
q - 2);
break;
}
- /* fall through */
+ fallthrough;
case '=':
ret = xbc_parse_kv(&p, q, c);
break;
@@ -836,7 +836,7 @@ int __init xbc_init(char *buf, const char **emsg, int *epos)
break;
case '#':
q = skip_comment(q);
- /* fall through */
+ fallthrough;
case ';':
case '\n':
ret = xbc_parse_key(&p, q);
diff --git a/lib/cmdline.c b/lib/cmdline.c
index fbb9981a04a4..b390dd03363b 100644
--- a/lib/cmdline.c
+++ b/lib/cmdline.c
@@ -35,25 +35,37 @@ static int get_range(char **str, int *pint, int n)
/**
* get_option - Parse integer from an option string
* @str: option string
- * @pint: (output) integer value parsed from @str
+ * @pint: (optional output) integer value parsed from @str
*
* Read an int from an option string; if available accept a subsequent
* comma as well.
*
+ * When @pint is NULL the function can be used as a validator of
+ * the current option in the string.
+ *
* Return values:
* 0 - no int in string
* 1 - int found, no subsequent comma
* 2 - int found including a subsequent comma
* 3 - hyphen found to denote a range
+ *
+ * Leading hyphen without integer is no integer case, but we consume it
+ * for the sake of simplification.
*/
int get_option(char **str, int *pint)
{
char *cur = *str;
+ int value;
if (!cur || !(*cur))
return 0;
- *pint = simple_strtol(cur, str, 0);
+ if (*cur == '-')
+ value = -simple_strtoull(++cur, str, 0);
+ else
+ value = simple_strtoull(cur, str, 0);
+ if (pint)
+ *pint = value;
if (cur == *str)
return 0;
if (**str == ',') {
@@ -132,27 +144,28 @@ unsigned long long memparse(const char *ptr, char **retptr)
case 'E':
case 'e':
ret <<= 10;
- /* fall through */
+ fallthrough;
case 'P':
case 'p':
ret <<= 10;
- /* fall through */
+ fallthrough;
case 'T':
case 't':
ret <<= 10;
- /* fall through */
+ fallthrough;
case 'G':
case 'g':
ret <<= 10;
- /* fall through */
+ fallthrough;
case 'M':
case 'm':
ret <<= 10;
- /* fall through */
+ fallthrough;
case 'K':
case 'k':
ret <<= 10;
endptr++;
+ fallthrough;
default:
break;
}
diff --git a/lib/cmdline_kunit.c b/lib/cmdline_kunit.c
new file mode 100644
index 000000000000..550e7a47fd24
--- /dev/null
+++ b/lib/cmdline_kunit.c
@@ -0,0 +1,100 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Test cases for API provided by cmdline.c
+ */
+
+#include <kunit/test.h>
+#include <linux/kernel.h>
+#include <linux/random.h>
+#include <linux/string.h>
+
+static const char *cmdline_test_strings[] = {
+ "\"\"", "" , "=" , "\"-", "," , "-," , ",-" , "-" ,
+ "+," , "--", ",,", "''" , "\"\",", "\",\"", "-\"\"", "\"",
+};
+
+static const int cmdline_test_values[] = {
+ 1, 1, 1, 1, 2, 3, 2, 3,
+ 1, 3, 2, 1, 1, 1, 3, 1,
+};
+
+static void cmdline_do_one_test(struct kunit *test, const char *in, int rc, int offset)
+{
+ const char *fmt = "Pattern: %s";
+ const char *out = in;
+ int dummy;
+ int ret;
+
+ ret = get_option((char **)&out, &dummy);
+
+ KUNIT_EXPECT_EQ_MSG(test, ret, rc, fmt, in);
+ KUNIT_EXPECT_PTR_EQ_MSG(test, out, in + offset, fmt, in);
+}
+
+static void cmdline_test_noint(struct kunit *test)
+{
+ unsigned int i = 0;
+
+ do {
+ const char *str = cmdline_test_strings[i];
+ int rc = 0;
+ int offset;
+
+ /* Only first