Skip to content

Commit fd0b2a5

Browse files
author
Alex Shi
committed
Merge branch 'v4.4/topic/mm-kaslr' into v4.4/topic/mm-kaslr-pax_usercopy
2 parents 0731824 + 0f0c7c1 commit fd0b2a5

8 files changed

Lines changed: 38 additions & 25 deletions

File tree

arch/arm64/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ config RELOCATABLE
751751

752752
config RANDOMIZE_BASE
753753
bool "Randomize the address of the kernel image"
754-
select ARM64_MODULE_PLTS
754+
select ARM64_MODULE_PLTS if MODULES
755755
select RELOCATABLE
756756
help
757757
Randomizes the virtual address at which the kernel image is

arch/arm64/Kconfig.debug

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ config DEBUG_SET_MODULE_RONX
6464

6565
config DEBUG_RODATA
6666
bool "Make kernel text and rodata read-only"
67+
default y
6768
help
6869
If this is set, kernel text and rodata will be made read-only. This
6970
is to help catch accidental or malicious attempts to change the
70-
kernel's executable code. Additionally splits rodata from kernel
71-
text so it can be made explicitly non-executable.
71+
kernel's executable code.
7272

73-
If in doubt, say Y
73+
If in doubt, say Y
7474

7575
config DEBUG_ALIGN_RODATA
7676
depends on DEBUG_RODATA

arch/arm64/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ head-y := arch/arm64/kernel/head.o
6060

6161
# The byte offset of the kernel image in RAM from the start of RAM.
6262
ifeq ($(CONFIG_ARM64_RANDOMIZE_TEXT_OFFSET), y)
63-
TEXT_OFFSET := $(shell awk 'BEGIN {srand(); printf "0x%03x000\n", int(512 * rand())}')
63+
TEXT_OFFSET := $(shell awk "BEGIN {srand(); printf \"0x%06x\n\", \
64+
int(2 * 1024 * 1024 / (2 ^ $(CONFIG_ARM64_PAGE_SHIFT)) * \
65+
rand()) * (2 ^ $(CONFIG_ARM64_PAGE_SHIFT))}")
6466
else
6567
TEXT_OFFSET := 0x00080000
6668
endif

arch/arm64/include/asm/spinlock.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,29 @@ static inline void arch_spin_unlock_wait(arch_spinlock_t *lock)
3131
unsigned int tmp;
3232
arch_spinlock_t lockval;
3333

34+
/*
35+
* Ensure prior spin_lock operations to other locks have completed
36+
* on this CPU before we test whether "lock" is locked.
37+
*/
38+
smp_mb();
39+
3440
asm volatile(
3541
" sevl\n"
3642
"1: wfe\n"
3743
"2: ldaxr %w0, %2\n"
3844
" eor %w1, %w0, %w0, ror #16\n"
3945
" cbnz %w1, 1b\n"
46+
/* Serialise against any concurrent lockers */
4047
ARM64_LSE_ATOMIC_INSN(
4148
/* LL/SC */
4249
" stxr %w1, %w0, %2\n"
43-
" cbnz %w1, 2b\n", /* Serialise against any concurrent lockers */
44-
/* LSE atomics */
4550
" nop\n"
46-
" nop\n")
51+
" nop\n",
52+
/* LSE atomics */
53+
" mov %w1, %w0\n"
54+
" cas %w0, %w0, %2\n"
55+
" eor %w1, %w1, %w0\n")
56+
" cbnz %w1, 2b\n"
4757
: "=&r" (lockval), "=&r" (tmp), "+Q" (*lock)
4858
:
4959
: "memory");
@@ -148,6 +158,7 @@ static inline int arch_spin_value_unlocked(arch_spinlock_t lock)
148158

149159
static inline int arch_spin_is_locked(arch_spinlock_t *lock)
150160
{
161+
smp_mb(); /* See arch_spin_unlock_wait */
151162
return !arch_spin_value_unlocked(READ_ONCE(*lock));
152163
}
153164

arch/arm64/kernel/head.S

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,9 @@ __enable_mmu:
697697
isb
698698
bl __create_page_tables // recreate kernel mapping
699699

700+
tlbi vmalle1 // Remove any stale TLB entries
701+
dsb nsh
702+
700703
msr sctlr_el1, x19 // re-enable the MMU
701704
isb
702705
ic iallu // flush instructions fetched

arch/arm64/kernel/traps.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ static void dump_mem(const char *lvl, const char *str, unsigned long bottom,
6464

6565
/*
6666
* We need to switch to kernel mode so that we can use __get_user
67-
* to safely read from kernel space. Note that we now dump the
68-
* code first, just in case the backtrace kills us.
67+
* to safely read from kernel space.
6968
*/
7069
fs = get_fs();
7170
set_fs(KERNEL_DS);
@@ -111,21 +110,12 @@ static void dump_backtrace_entry(unsigned long where)
111110
print_ip_sym(where);
112111
}
113112

114-
static void dump_instr(const char *lvl, struct pt_regs *regs)
113+
static void __dump_instr(const char *lvl, struct pt_regs *regs)
115114
{
116115
unsigned long addr = instruction_pointer(regs);
117-
mm_segment_t fs;
118116
char str[sizeof("00000000 ") * 5 + 2 + 1], *p = str;
119117
int i;
120118

121-
/*
122-
* We need to switch to kernel mode so that we can use __get_user
123-
* to safely read from kernel space. Note that we now dump the
124-
* code first, just in case the backtrace kills us.
125-
*/
126-
fs = get_fs();
127-
set_fs(KERNEL_DS);
128-
129119
for (i = -4; i < 1; i++) {
130120
unsigned int val, bad;
131121

@@ -139,8 +129,18 @@ static void dump_instr(const char *lvl, struct pt_regs *regs)
139129
}
140130
}
141131
printk("%sCode: %s\n", lvl, str);
132+
}
142133

143-
set_fs(fs);
134+
static void dump_instr(const char *lvl, struct pt_regs *regs)
135+
{
136+
if (!user_mode(regs)) {
137+
mm_segment_t fs = get_fs();
138+
set_fs(KERNEL_DS);
139+
__dump_instr(lvl, regs);
140+
set_fs(fs);
141+
} else {
142+
__dump_instr(lvl, regs);
143+
}
144144
}
145145

146146
static void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk)

drivers/hwtracing/coresight/coresight-tmc.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,6 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id)
388388
err_misc_register:
389389
coresight_unregister(drvdata->csdev);
390390
err_devm_kzalloc:
391-
if (drvdata->config_type == TMC_CONFIG_TYPE_ETR)
392-
dma_free_coherent(dev, drvdata->size,
393-
drvdata->vaddr, drvdata->paddr);
394391
return ret;
395392
}
396393

kernel/events/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5797,7 +5797,7 @@ static int __perf_pmu_output_stop(void *info)
57975797
{
57985798
struct perf_event *event = info;
57995799
struct pmu *pmu = event->pmu;
5800-
struct perf_cpu_context *cpuctx = get_cpu_ptr(pmu->pmu_cpu_context);
5800+
struct perf_cpu_context *cpuctx = this_cpu_ptr(pmu->pmu_cpu_context);
58015801
struct remote_output ro = {
58025802
.rb = event->rb,
58035803
};

0 commit comments

Comments
 (0)