Skip to content

Commit 5130680

Browse files
committed
Merge branch 'akpm' (patches from Andrew)
Merge misc fixes from Andrew Morton: "18 patches. Subsystems affected by this patch series: mm (pagealloc, memcg, kasan, memory-failure, and highmem), ubsan, proc, and MAINTAINERS" * emailed patches from Andrew Morton <[email protected]>: MAINTAINERS: add a couple more files to the Clang/LLVM section proc_sysctl: fix oops caused by incorrect command parameters powerpc/mm/highmem: use __set_pte_at() for kmap_local() mips/mm/highmem: use set_pte() for kmap_local() mm/highmem: prepare for overriding set_pte_at() sparc/mm/highmem: flush cache and TLB mm: fix page reference leak in soft_offline_page() ubsan: disable unsigned-overflow check for i386 kasan, mm: fix resetting page_alloc tags for HW_TAGS kasan, mm: fix conflicts with init_on_alloc/free kasan: fix HW_TAGS boot parameters kasan: fix incorrect arguments passing in kasan_add_zero_shadow kasan: fix unaligned address is unhandled in kasan_remove_zero_shadow mm: fix numa stats for thp migration mm: memcg: fix memcg file_dirty numa stat mm: memcg/slab: optimize objcg stock draining mm: fix initialization of struct page for holes in memory layout x86/setup: don't remove E820_TYPE_RAM for pfn 0
2 parents fdbc80b + e82d891 commit 5130680

File tree

16 files changed

+168
-148
lines changed

16 files changed

+168
-148
lines changed

Documentation/dev-tools/kasan.rst

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -160,29 +160,14 @@ intended for use in production as a security mitigation. Therefore it supports
160160
boot parameters that allow to disable KASAN competely or otherwise control
161161
particular KASAN features.
162162

163-
The things that can be controlled are:
163+
- ``kasan=off`` or ``=on`` controls whether KASAN is enabled (default: ``on``).
164164

165-
1. Whether KASAN is enabled at all.
166-
2. Whether KASAN collects and saves alloc/free stacks.
167-
3. Whether KASAN panics on a detected bug or not.
165+
- ``kasan.stacktrace=off`` or ``=on`` disables or enables alloc and free stack
166+
traces collection (default: ``on`` for ``CONFIG_DEBUG_KERNEL=y``, otherwise
167+
``off``).
168168

169-
The ``kasan.mode`` boot parameter allows to choose one of three main modes:
170-
171-
- ``kasan.mode=off`` - KASAN is disabled, no tag checks are performed
172-
- ``kasan.mode=prod`` - only essential production features are enabled
173-
- ``kasan.mode=full`` - all KASAN features are enabled
174-
175-
The chosen mode provides default control values for the features mentioned
176-
above. However it's also possible to override the default values by providing:
177-
178-
- ``kasan.stacktrace=off`` or ``=on`` - enable alloc/free stack collection
179-
(default: ``on`` for ``mode=full``,
180-
otherwise ``off``)
181-
- ``kasan.fault=report`` or ``=panic`` - only print KASAN report or also panic
182-
(default: ``report``)
183-
184-
If ``kasan.mode`` parameter is not provided, it defaults to ``full`` when
185-
``CONFIG_DEBUG_KERNEL`` is enabled, and to ``prod`` otherwise.
169+
- ``kasan.fault=report`` or ``=panic`` controls whether to only print a KASAN
170+
report or also panic the kernel (default: ``report``).
186171

187172
For developers
188173
~~~~~~~~~~~~~~

MAINTAINERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4311,7 +4311,9 @@ W: https://clangbuiltlinux.github.io/
43114311
B: https://github.com/ClangBuiltLinux/linux/issues
43124312
C: irc://chat.freenode.net/clangbuiltlinux
43134313
F: Documentation/kbuild/llvm.rst
4314+
F: include/linux/compiler-clang.h
43144315
F: scripts/clang-tools/
4316+
F: scripts/clang-version.sh
43154317
F: scripts/lld-version.sh
43164318
K: \b(?i:clang|llvm)\b
43174319

arch/mips/include/asm/highmem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ extern void kmap_flush_tlb(unsigned long addr);
5151

5252
#define flush_cache_kmaps() BUG_ON(cpu_has_dc_aliases)
5353

54+
#define arch_kmap_local_set_pte(mm, vaddr, ptep, ptev) set_pte(ptep, ptev)
5455
#define arch_kmap_local_post_map(vaddr, pteval) local_flush_tlb_one(vaddr)
5556
#define arch_kmap_local_post_unmap(vaddr) local_flush_tlb_one(vaddr)
5657

arch/powerpc/include/asm/highmem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ extern pte_t *pkmap_page_table;
5858

5959
#define flush_cache_kmaps() flush_cache_all()
6060

61+
#define arch_kmap_local_set_pte(mm, vaddr, ptep, ptev) \
62+
__set_pte_at(mm, vaddr, ptep, ptev, 1)
6163
#define arch_kmap_local_post_map(vaddr, pteval) \
6264
local_flush_tlb_page(NULL, vaddr)
6365
#define arch_kmap_local_post_unmap(vaddr) \

arch/sparc/include/asm/highmem.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ extern pte_t *pkmap_page_table;
5050

5151
#define flush_cache_kmaps() flush_cache_all()
5252

53-
/* FIXME: Use __flush_tlb_one(vaddr) instead of flush_cache_all() -- Anton */
54-
#define arch_kmap_local_post_map(vaddr, pteval) flush_cache_all()
55-
#define arch_kmap_local_post_unmap(vaddr) flush_cache_all()
56-
53+
/* FIXME: Use __flush_*_one(vaddr) instead of flush_*_all() -- Anton */
54+
#define arch_kmap_local_pre_map(vaddr, pteval) flush_cache_all()
55+
#define arch_kmap_local_pre_unmap(vaddr) flush_cache_all()
56+
#define arch_kmap_local_post_map(vaddr, pteval) flush_tlb_all()
57+
#define arch_kmap_local_post_unmap(vaddr) flush_tlb_all()
5758

5859
#endif /* __KERNEL__ */
5960

arch/x86/kernel/setup.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -660,17 +660,6 @@ static void __init trim_platform_memory_ranges(void)
660660

661661
static void __init trim_bios_range(void)
662662
{
663-
/*
664-
* A special case is the first 4Kb of memory;
665-
* This is a BIOS owned area, not kernel ram, but generally
666-
* not listed as such in the E820 table.
667-
*
668-
* This typically reserves additional memory (64KiB by default)
669-
* since some BIOSes are known to corrupt low memory. See the
670-
* Kconfig help text for X86_RESERVE_LOW.
671-
*/
672-
e820__range_update(0, PAGE_SIZE, E820_TYPE_RAM, E820_TYPE_RESERVED);
673-
674663
/*
675664
* special case: Some BIOSes report the PC BIOS
676665
* area (640Kb -> 1Mb) as RAM even though it is not.
@@ -728,6 +717,15 @@ early_param("reservelow", parse_reservelow);
728717

729718
static void __init trim_low_memory_range(void)
730719
{
720+
/*
721+
* A special case is the first 4Kb of memory;
722+
* This is a BIOS owned area, not kernel ram, but generally
723+
* not listed as such in the E820 table.
724+
*
725+
* This typically reserves additional memory (64KiB by default)
726+
* since some BIOSes are known to corrupt low memory. See the
727+
* Kconfig help text for X86_RESERVE_LOW.
728+
*/
731729
memblock_reserve(0, ALIGN(reserve_low, PAGE_SIZE));
732730
}
733731

fs/proc/proc_sysctl.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1770,6 +1770,12 @@ static int process_sysctl_arg(char *param, char *val,
17701770
return 0;
17711771
}
17721772

1773+
if (!val)
1774+
return -EINVAL;
1775+
len = strlen(val);
1776+
if (len == 0)
1777+
return -EINVAL;
1778+
17731779
/*
17741780
* To set sysctl options, we use a temporary mount of proc, look up the
17751781
* respective sys/ file and write to it. To avoid mounting it when no
@@ -1811,7 +1817,6 @@ static int process_sysctl_arg(char *param, char *val,
18111817
file, param, val);
18121818
goto out;
18131819
}
1814-
len = strlen(val);
18151820
wret = kernel_write(file, val, len, &pos);
18161821
if (wret < 0) {
18171822
err = wret;

lib/Kconfig.ubsan

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ config UBSAN_SIGNED_OVERFLOW
123123
config UBSAN_UNSIGNED_OVERFLOW
124124
bool "Perform checking for unsigned arithmetic overflow"
125125
depends on $(cc-option,-fsanitize=unsigned-integer-overflow)
126+
depends on !X86_32 # avoid excessive stack usage on x86-32/clang
126127
help
127128
This option enables -fsanitize=unsigned-integer-overflow which checks
128129
for overflow of any arithmetic operations with unsigned integers. This

mm/highmem.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,11 @@ static inline void *arch_kmap_local_high_get(struct page *page)
473473
}
474474
#endif
475475

476+
#ifndef arch_kmap_local_set_pte
477+
#define arch_kmap_local_set_pte(mm, vaddr, ptep, ptev) \
478+
set_pte_at(mm, vaddr, ptep, ptev)
479+
#endif
480+
476481
/* Unmap a local mapping which was obtained by kmap_high_get() */
477482
static inline bool kmap_high_unmap_local(unsigned long vaddr)
478483
{
@@ -515,7 +520,7 @@ void *__kmap_local_pfn_prot(unsigned long pfn, pgprot_t prot)
515520
vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
516521
BUG_ON(!pte_none(*(kmap_pte - idx)));
517522
pteval = pfn_pte(pfn, prot);
518-
set_pte_at(&init_mm, vaddr, kmap_pte - idx, pteval);
523+
arch_kmap_local_set_pte(&init_mm, vaddr, kmap_pte - idx, pteval);
519524
arch_kmap_local_post_map(vaddr, pteval);
520525
current->kmap_ctrl.pteval[kmap_local_idx()] = pteval;
521526
preempt_enable();

mm/kasan/hw_tags.c

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@
1919

2020
#include "kasan.h"
2121

22-
enum kasan_arg_mode {
23-
KASAN_ARG_MODE_DEFAULT,
24-
KASAN_ARG_MODE_OFF,
25-
KASAN_ARG_MODE_PROD,
26-
KASAN_ARG_MODE_FULL,
22+
enum kasan_arg {
23+
KASAN_ARG_DEFAULT,
24+
KASAN_ARG_OFF,
25+
KASAN_ARG_ON,
2726
};
2827

2928
enum kasan_arg_stacktrace {
@@ -38,7 +37,7 @@ enum kasan_arg_fault {
3837
KASAN_ARG_FAULT_PANIC,
3938
};
4039

41-
static enum kasan_arg_mode kasan_arg_mode __ro_after_init;
40+
static enum kasan_arg kasan_arg __ro_after_init;
4241
static enum kasan_arg_stacktrace kasan_arg_stacktrace __ro_after_init;
4342
static enum kasan_arg_fault kasan_arg_fault __ro_after_init;
4443

@@ -52,26 +51,24 @@ DEFINE_STATIC_KEY_FALSE(kasan_flag_stacktrace);
5251
/* Whether panic or disable tag checking on fault. */
5352
bool kasan_flag_panic __ro_after_init;
5453

55-
/* kasan.mode=off/prod/full */
56-
static int __init early_kasan_mode(char *arg)
54+
/* kasan=off/on */
55+
static int __init early_kasan_flag(char *arg)
5756
{
5857
if (!arg)
5958
return -EINVAL;
6059

6160
if (!strcmp(arg, "off"))
62-
kasan_arg_mode = KASAN_ARG_MODE_OFF;
63-
else if (!strcmp(arg, "prod"))
64-
kasan_arg_mode = KASAN_ARG_MODE_PROD;
65-
else if (!strcmp(arg, "full"))
66-
kasan_arg_mode = KASAN_ARG_MODE_FULL;
61+
kasan_arg = KASAN_ARG_OFF;
62+
else if (!strcmp(arg, "on"))
63+
kasan_arg = KASAN_ARG_ON;
6764
else
6865
return -EINVAL;
6966

7067
return 0;
7168
}
72-
early_param("kasan.mode", early_kasan_mode);
69+
early_param("kasan", early_kasan_flag);
7370

74-
/* kasan.stack=off/on */
71+
/* kasan.stacktrace=off/on */
7572
static int __init early_kasan_flag_stacktrace(char *arg)
7673
{
7774
if (!arg)
@@ -113,8 +110,8 @@ void kasan_init_hw_tags_cpu(void)
113110
* as this function is only called for MTE-capable hardware.
114111
*/
115112

116-
/* If KASAN is disabled, do nothing. */
117-
if (kasan_arg_mode == KASAN_ARG_MODE_OFF)
113+
/* If KASAN is disabled via command line, don't initialize it. */
114+
if (kasan_arg == KASAN_ARG_OFF)
118115
return;
119116

120117
hw_init_tags(KASAN_TAG_MAX);
@@ -124,43 +121,28 @@ void kasan_init_hw_tags_cpu(void)
124121
/* kasan_init_hw_tags() is called once on boot CPU. */
125122
void __init kasan_init_hw_tags(void)
126123
{
127-
/* If hardware doesn't support MTE, do nothing. */
124+
/* If hardware doesn't support MTE, don't initialize KASAN. */
128125
if (!system_supports_mte())
129126
return;
130127

131-
/* Choose KASAN mode if kasan boot parameter is not provided. */
132-
if (kasan_arg_mode == KASAN_ARG_MODE_DEFAULT) {
133-
if (IS_ENABLED(CONFIG_DEBUG_KERNEL))
134-
kasan_arg_mode = KASAN_ARG_MODE_FULL;
135-
else
136-
kasan_arg_mode = KASAN_ARG_MODE_PROD;
137-
}
138-
139-
/* Preset parameter values based on the mode. */
140-
switch (kasan_arg_mode) {
141-
case KASAN_ARG_MODE_DEFAULT:
142-
/* Shouldn't happen as per the check above. */
143-
WARN_ON(1);
144-
return;
145-
case KASAN_ARG_MODE_OFF:
146-
/* If KASAN is disabled, do nothing. */
128+
/* If KASAN is disabled via command line, don't initialize it. */
129+
if (kasan_arg == KASAN_ARG_OFF)
147130
return;
148-
case KASAN_ARG_MODE_PROD:
149-
static_branch_enable(&kasan_flag_enabled);
150-
break;
151-
case KASAN_ARG_MODE_FULL:
152-
static_branch_enable(&kasan_flag_enabled);
153-
static_branch_enable(&kasan_flag_stacktrace);
154-
break;
155-
}
156131

157-
/* Now, optionally override the presets. */
132+
/* Enable KASAN. */
133+
static_branch_enable(&kasan_flag_enabled);
158134

159135
switch (kasan_arg_stacktrace) {
160136
case KASAN_ARG_STACKTRACE_DEFAULT:
137+
/*
138+
* Default to enabling stack trace collection for
139+
* debug kernels.
140+
*/
141+
if (IS_ENABLED(CONFIG_DEBUG_KERNEL))
142+
static_branch_enable(&kasan_flag_stacktrace);
161143
break;
162144
case KASAN_ARG_STACKTRACE_OFF:
163-
static_branch_disable(&kasan_flag_stacktrace);
145+
/* Do nothing, kasan_flag_stacktrace keeps its default value. */
164146
break;
165147
case KASAN_ARG_STACKTRACE_ON:
166148
static_branch_enable(&kasan_flag_stacktrace);
@@ -169,11 +151,16 @@ void __init kasan_init_hw_tags(void)
169151

170152
switch (kasan_arg_fault) {
171153
case KASAN_ARG_FAULT_DEFAULT:
154+
/*
155+
* Default to no panic on report.
156+
* Do nothing, kasan_flag_panic keeps its default value.
157+
*/
172158
break;
173159
case KASAN_ARG_FAULT_REPORT:
174-
kasan_flag_panic = false;
160+
/* Do nothing, kasan_flag_panic keeps its default value. */
175161
break;
176162
case KASAN_ARG_FAULT_PANIC:
163+
/* Enable panic on report. */
177164
kasan_flag_panic = true;
178165
break;
179166
}

0 commit comments

Comments
 (0)