Skip to content

Commit 225a97d

Browse files
committed
Merge tag 'riscv-for-linus-6.18-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux
Pull RISC-V fixes from Paul Walmsley: - A fix to disable KASAN checks while walking a non-current task's stackframe (following x86) - A fix for a kvrealloc()-related memory leak in module_frob_arch_sections() - Two replacements of strcpy() with strscpy() - A change to use the RISC-V .insn assembler directive when possible to assemble instructions from hex opcodes - Some low-impact fixes in the ptdump code and kprobes test code * tag 'riscv-for-linus-6.18-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: cpuidle: riscv-sbi: Replace deprecated strcpy in sbi_cpuidle_init_cpu riscv: KGDB: Replace deprecated strcpy in kgdb_arch_handle_qxfer_pkt riscv: asm: use .insn for making custom instructions riscv: tests: Make RISCV_KPROBES_KUNIT tristate riscv: tests: Rename kprobes_test_riscv to kprobes_riscv riscv: Fix memory leak in module_frob_arch_sections() riscv: ptdump: use seq_puts() in pt_dump_seq_puts() macro riscv: stacktrace: Disable KASAN checks for non-current tasks
2 parents 3a157bd + 2e44856 commit 225a97d

11 files changed

Lines changed: 52 additions & 19 deletions

File tree

arch/riscv/include/asm/asm.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
#define __ASM_STR(x) #x
1313
#endif
1414

15+
#ifdef CONFIG_AS_HAS_INSN
16+
#define ASM_INSN_I(__x) ".insn " __x
17+
#else
18+
#define ASM_INSN_I(__x) ".4byte " __x
19+
#endif
20+
1521
#if __riscv_xlen == 64
1622
#define __REG_SEL(a, b) __ASM_STR(a)
1723
#elif __riscv_xlen == 32

arch/riscv/include/asm/insn-def.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,10 @@
256256
INSN_S(OPCODE_OP_IMM, FUNC3(6), __RS2(3), \
257257
SIMM12((offset) & 0xfe0), RS1(base))
258258

259-
#define RISCV_PAUSE ".4byte 0x100000f"
260-
#define ZAWRS_WRS_NTO ".4byte 0x00d00073"
261-
#define ZAWRS_WRS_STO ".4byte 0x01d00073"
262-
#define RISCV_NOP4 ".4byte 0x00000013"
259+
#define RISCV_PAUSE ASM_INSN_I("0x100000f")
260+
#define ZAWRS_WRS_NTO ASM_INSN_I("0x00d00073")
261+
#define ZAWRS_WRS_STO ASM_INSN_I("0x01d00073")
262+
#define RISCV_NOP4 ASM_INSN_I("0x00000013")
263263

264264
#define RISCV_INSN_NOP4 _AC(0x00000013, U)
265265

arch/riscv/include/asm/vendor_extensions/mips.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ extern struct riscv_isa_vendor_ext_data_list riscv_isa_vendor_ext_list_mips;
3030
* allowing any subsequent instructions to fetch.
3131
*/
3232

33-
#define MIPS_PAUSE ".4byte 0x00501013\n\t"
34-
#define MIPS_EHB ".4byte 0x00301013\n\t"
35-
#define MIPS_IHB ".4byte 0x00101013\n\t"
33+
#define MIPS_PAUSE ASM_INSN_I("0x00501013\n\t")
34+
#define MIPS_EHB ASM_INSN_I("0x00301013\n\t")
35+
#define MIPS_IHB ASM_INSN_I("0x00101013\n\t")
3636

3737
#endif // _ASM_RISCV_VENDOR_EXTENSIONS_MIPS_H

arch/riscv/kernel/kgdb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,10 @@ void kgdb_arch_handle_qxfer_pkt(char *remcom_in_buffer,
265265
{
266266
if (!strncmp(remcom_in_buffer, gdb_xfer_read_target,
267267
sizeof(gdb_xfer_read_target)))
268-
strcpy(remcom_out_buffer, riscv_gdb_stub_target_desc);
268+
strscpy(remcom_out_buffer, riscv_gdb_stub_target_desc, BUFMAX);
269269
else if (!strncmp(remcom_in_buffer, gdb_xfer_read_cpuxml,
270270
sizeof(gdb_xfer_read_cpuxml)))
271-
strcpy(remcom_out_buffer, riscv_gdb_stub_cpuxml);
271+
strscpy(remcom_out_buffer, riscv_gdb_stub_cpuxml, BUFMAX);
272272
}
273273

274274
static inline void kgdb_arch_update_addr(struct pt_regs *regs,

arch/riscv/kernel/module-sections.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ int module_frob_arch_sections(Elf_Ehdr *ehdr, Elf_Shdr *sechdrs,
119119
unsigned int num_plts = 0;
120120
unsigned int num_gots = 0;
121121
Elf_Rela *scratch = NULL;
122+
Elf_Rela *new_scratch;
122123
size_t scratch_size = 0;
123124
int i;
124125

@@ -168,9 +169,12 @@ int module_frob_arch_sections(Elf_Ehdr *ehdr, Elf_Shdr *sechdrs,
168169
scratch_size_needed = (num_scratch_relas + num_relas) * sizeof(*scratch);
169170
if (scratch_size_needed > scratch_size) {
170171
scratch_size = scratch_size_needed;
171-
scratch = kvrealloc(scratch, scratch_size, GFP_KERNEL);
172-
if (!scratch)
172+
new_scratch = kvrealloc(scratch, scratch_size, GFP_KERNEL);
173+
if (!new_scratch) {
174+
kvfree(scratch);
173175
return -ENOMEM;
176+
}
177+
scratch = new_scratch;
174178
}
175179

176180
for (size_t j = 0; j < num_relas; j++)

arch/riscv/kernel/stacktrace.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@
1616

1717
#ifdef CONFIG_FRAME_POINTER
1818

19+
/*
20+
* This disables KASAN checking when reading a value from another task's stack,
21+
* since the other task could be running on another CPU and could have poisoned
22+
* the stack in the meantime.
23+
*/
24+
#define READ_ONCE_TASK_STACK(task, x) \
25+
({ \
26+
unsigned long val; \
27+
unsigned long addr = x; \
28+
if ((task) == current) \
29+
val = READ_ONCE(addr); \
30+
else \
31+
val = READ_ONCE_NOCHECK(addr); \
32+
val; \
33+
})
34+
1935
extern asmlinkage void handle_exception(void);
2036
extern unsigned long ret_from_exception_end;
2137

@@ -69,8 +85,9 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,
6985
fp = frame->ra;
7086
pc = regs->ra;
7187
} else {
72-
fp = frame->fp;
73-
pc = ftrace_graph_ret_addr(current, &graph_idx, frame->ra,
88+
fp = READ_ONCE_TASK_STACK(task, frame->fp);
89+
pc = READ_ONCE_TASK_STACK(task, frame->ra);
90+
pc = ftrace_graph_ret_addr(current, &graph_idx, pc,
7491
&frame->ra);
7592
if (pc >= (unsigned long)handle_exception &&
7693
pc < (unsigned long)&ret_from_exception_end) {

arch/riscv/kernel/tests/Kconfig.debug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ config RISCV_MODULE_LINKING_KUNIT
3131
If unsure, say N.
3232

3333
config RISCV_KPROBES_KUNIT
34-
bool "KUnit test for riscv kprobes" if !KUNIT_ALL_TESTS
34+
tristate "KUnit test for riscv kprobes" if !KUNIT_ALL_TESTS
3535
depends on KUNIT
3636
depends on KPROBES
3737
default KUNIT_ALL_TESTS
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
obj-y += test-kprobes.o test-kprobes-asm.o
1+
obj-$(CONFIG_RISCV_KPROBES_KUNIT) += kprobes_riscv_kunit.o
2+
3+
kprobes_riscv_kunit-objs := test-kprobes.o test-kprobes-asm.o

arch/riscv/kernel/tests/kprobes/test-kprobes.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ static struct kunit_case kprobes_testcases[] = {
4949
};
5050

5151
static struct kunit_suite kprobes_test_suite = {
52-
.name = "kprobes_test_riscv",
52+
.name = "kprobes_riscv",
5353
.test_cases = kprobes_testcases,
5454
};
5555

5656
kunit_test_suites(&kprobes_test_suite);
57+
58+
MODULE_LICENSE("GPL");
59+
MODULE_DESCRIPTION("KUnit test for riscv kprobes");

arch/riscv/mm/ptdump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#define pt_dump_seq_puts(m, fmt) \
2222
({ \
2323
if (m) \
24-
seq_printf(m, fmt); \
24+
seq_puts(m, fmt); \
2525
})
2626

2727
/*

0 commit comments

Comments
 (0)