Skip to content

Commit 261b8e8

Browse files
committed
Merge tag 'riscv-for-linus-6.9-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux
Pull RISC-V fixes from Palmer Dabbelt: - A fix for an __{get,put}_kernel_nofault to avoid an uninitialized value causing spurious failures - compat_vdso.so.dbg is now installed to the standard install location - A fix to avoid initializing PERF_SAMPLE_BRANCH_*-related events, as they aren't supported and will just later fail - A fix to make AT_VECTOR_SIZE_ARCH correct now that we're providing AT_MINSIGSTKSZ - pgprot_nx() is now implemented, which fixes vmap W^X protection - A fix for the vector save/restore code, which at least manifests as corrupted vector state when a signal is taken - A fix for a race condition in instruction patching - A fix to avoid leaking the kernel-mode GP to userspace, which is a kernel pointer leak that can be used to defeat KASLR in various ways - A handful of smaller fixes to build warnings, an overzealous printk, and some missing tracing annotations * tag 'riscv-for-linus-6.9-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: riscv: process: Fix kernel gp leakage riscv: Disable preemption when using patch_map() riscv: Fix warning by declaring arch_cpu_idle() as noinstr riscv: use KERN_INFO in do_trap riscv: Fix vector state restore in rt_sigreturn() riscv: mm: implement pgprot_nx riscv: compat_vdso: align VDSOAS build log RISC-V: Update AT_VECTOR_SIZE_ARCH for new AT_MINSIGSTKSZ riscv: Mark __se_sys_* functions __used drivers/perf: riscv: Disable PERF_SAMPLE_BRANCH_* while not supported riscv: compat_vdso: install compat_vdso.so.dbg to /lib/modules/*/vdso/ riscv: hwprobe: do not produce frtace relocation riscv: Fix spurious errors from __get/put_kernel_nofault riscv: mm: Fix prototype to avoid discarding const
2 parents 5009447 + d14fa1f commit 261b8e8

File tree

13 files changed

+38
-20
lines changed

13 files changed

+38
-20
lines changed

arch/riscv/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ endif
151151
endif
152152

153153
vdso-install-y += arch/riscv/kernel/vdso/vdso.so.dbg
154-
vdso-install-$(CONFIG_COMPAT) += arch/riscv/kernel/compat_vdso/compat_vdso.so.dbg:../compat_vdso/compat_vdso.so
154+
vdso-install-$(CONFIG_COMPAT) += arch/riscv/kernel/compat_vdso/compat_vdso.so.dbg
155155

156156
ifneq ($(CONFIG_XIP_KERNEL),y)
157157
ifeq ($(CONFIG_RISCV_M_MODE)$(CONFIG_ARCH_CANAAN),yy)

arch/riscv/include/asm/pgtable.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,12 @@ static inline int ptep_clear_flush_young(struct vm_area_struct *vma,
593593
return ptep_test_and_clear_young(vma, address, ptep);
594594
}
595595

596+
#define pgprot_nx pgprot_nx
597+
static inline pgprot_t pgprot_nx(pgprot_t _prot)
598+
{
599+
return __pgprot(pgprot_val(_prot) & ~_PAGE_EXEC);
600+
}
601+
596602
#define pgprot_noncached pgprot_noncached
597603
static inline pgprot_t pgprot_noncached(pgprot_t _prot)
598604
{

arch/riscv/include/asm/syscall_wrapper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ asmlinkage long __riscv_sys_ni_syscall(const struct pt_regs *);
3636
ulong) \
3737
__attribute__((alias(__stringify(___se_##prefix##name)))); \
3838
__diag_pop(); \
39-
static long noinline ___se_##prefix##name(__MAP(x,__SC_LONG,__VA_ARGS__)); \
39+
static long noinline ___se_##prefix##name(__MAP(x,__SC_LONG,__VA_ARGS__)) \
40+
__used; \
4041
static long ___se_##prefix##name(__MAP(x,__SC_LONG,__VA_ARGS__))
4142

4243
#define SC_RISCV_REGS_TO_ARGS(x, ...) \

arch/riscv/include/asm/uaccess.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ unsigned long __must_check clear_user(void __user *to, unsigned long n)
319319

320320
#define __get_kernel_nofault(dst, src, type, err_label) \
321321
do { \
322-
long __kr_err; \
322+
long __kr_err = 0; \
323323
\
324324
__get_user_nocheck(*((type *)(dst)), (type *)(src), __kr_err); \
325325
if (unlikely(__kr_err)) \
@@ -328,7 +328,7 @@ do { \
328328

329329
#define __put_kernel_nofault(dst, src, type, err_label) \
330330
do { \
331-
long __kr_err; \
331+
long __kr_err = 0; \
332332
\
333333
__put_user_nocheck(*((type *)(src)), (type *)(dst), __kr_err); \
334334
if (unlikely(__kr_err)) \

arch/riscv/include/uapi/asm/auxvec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#define AT_L3_CACHEGEOMETRY 47
3535

3636
/* entries in ARCH_DLINFO */
37-
#define AT_VECTOR_SIZE_ARCH 9
37+
#define AT_VECTOR_SIZE_ARCH 10
3838
#define AT_MINSIGSTKSZ 51
3939

4040
#endif /* _UAPI_ASM_RISCV_AUXVEC_H */

arch/riscv/kernel/compat_vdso/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,5 @@ quiet_cmd_compat_vdsold = VDSOLD $@
7474
rm $@.tmp
7575

7676
# actual build commands
77-
quiet_cmd_compat_vdsoas = VDSOAS $@
77+
quiet_cmd_compat_vdsoas = VDSOAS $@
7878
cmd_compat_vdsoas = $(COMPAT_CC) $(a_flags) $(COMPAT_CC_FLAGS) -c -o $@ $<

arch/riscv/kernel/patch.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ static int __patch_insn_set(void *addr, u8 c, size_t len)
8080
*/
8181
lockdep_assert_held(&text_mutex);
8282

83+
preempt_disable();
84+
8385
if (across_pages)
8486
patch_map(addr + PAGE_SIZE, FIX_TEXT_POKE1);
8587

@@ -92,6 +94,8 @@ static int __patch_insn_set(void *addr, u8 c, size_t len)
9294
if (across_pages)
9395
patch_unmap(FIX_TEXT_POKE1);
9496

97+
preempt_enable();
98+
9599
return 0;
96100
}
97101
NOKPROBE_SYMBOL(__patch_insn_set);
@@ -122,6 +126,8 @@ static int __patch_insn_write(void *addr, const void *insn, size_t len)
122126
if (!riscv_patch_in_stop_machine)
123127
lockdep_assert_held(&text_mutex);
124128

129+
preempt_disable();
130+
125131
if (across_pages)
126132
patch_map(addr + PAGE_SIZE, FIX_TEXT_POKE1);
127133

@@ -134,6 +140,8 @@ static int __patch_insn_write(void *addr, const void *insn, size_t len)
134140
if (across_pages)
135141
patch_unmap(FIX_TEXT_POKE1);
136142

143+
preempt_enable();
144+
137145
return ret;
138146
}
139147
NOKPROBE_SYMBOL(__patch_insn_write);

arch/riscv/kernel/process.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
#include <asm/vector.h>
2828
#include <asm/cpufeature.h>
2929

30-
register unsigned long gp_in_global __asm__("gp");
31-
3230
#if defined(CONFIG_STACKPROTECTOR) && !defined(CONFIG_STACKPROTECTOR_PER_TASK)
3331
#include <linux/stackprotector.h>
3432
unsigned long __stack_chk_guard __read_mostly;
@@ -37,7 +35,7 @@ EXPORT_SYMBOL(__stack_chk_guard);
3735

3836
extern asmlinkage void ret_from_fork(void);
3937

40-
void arch_cpu_idle(void)
38+
void noinstr arch_cpu_idle(void)
4139
{
4240
cpu_do_idle();
4341
}
@@ -207,7 +205,6 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
207205
if (unlikely(args->fn)) {
208206
/* Kernel thread */
209207
memset(childregs, 0, sizeof(struct pt_regs));
210-
childregs->gp = gp_in_global;
211208
/* Supervisor/Machine, irqs on: */
212209
childregs->status = SR_PP | SR_PIE;
213210

arch/riscv/kernel/signal.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ static long __restore_v_state(struct pt_regs *regs, void __user *sc_vec)
119119
struct __sc_riscv_v_state __user *state = sc_vec;
120120
void __user *datap;
121121

122+
/*
123+
* Mark the vstate as clean prior performing the actual copy,
124+
* to avoid getting the vstate incorrectly clobbered by the
125+
* discarded vector state.
126+
*/
127+
riscv_v_vstate_set_restore(current, regs);
128+
122129
/* Copy everything of __sc_riscv_v_state except datap. */
123130
err = __copy_from_user(&current->thread.vstate, &state->v_state,
124131
offsetof(struct __riscv_v_ext_state, datap));
@@ -133,13 +140,7 @@ static long __restore_v_state(struct pt_regs *regs, void __user *sc_vec)
133140
* Copy the whole vector content from user space datap. Use
134141
* copy_from_user to prevent information leak.
135142
*/
136-
err = copy_from_user(current->thread.vstate.datap, datap, riscv_v_vsize);
137-
if (unlikely(err))
138-
return err;
139-
140-
riscv_v_vstate_set_restore(current, regs);
141-
142-
return err;
143+
return copy_from_user(current->thread.vstate.datap, datap, riscv_v_vsize);
143144
}
144145
#else
145146
#define save_v_state(task, regs) (0)

arch/riscv/kernel/traps.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ void do_trap(struct pt_regs *regs, int signo, int code, unsigned long addr)
122122
print_vma_addr(KERN_CONT " in ", instruction_pointer(regs));
123123
pr_cont("\n");
124124
__show_regs(regs);
125-
dump_instr(KERN_EMERG, regs);
125+
dump_instr(KERN_INFO, regs);
126126
}
127127

128128
force_sig_fault(signo, code, (void __user *)addr);

0 commit comments

Comments
 (0)