Skip to content

Commit c96bb95

Browse files
committed
Merge tag 'loongarch-fixes-6.1-1' of git://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson
Pull LoongArch fixes from Huacai Chen: "Remove unused kernel stack padding, fix some build errors/warnings and two bugs in laptop platform driver" * tag 'loongarch-fixes-6.1-1' of git://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson: platform/loongarch: laptop: Fix possible UAF and simplify generic_acpi_laptop_init() platform/loongarch: laptop: Adjust resume order for loongson_hotkey_resume() LoongArch: BPF: Avoid declare variables in switch-case LoongArch: Use flexible-array member instead of zero-length array LoongArch: Remove unused kernel stack padding
2 parents 28b7bd4 + d819169 commit c96bb95

File tree

7 files changed

+34
-36
lines changed

7 files changed

+34
-36
lines changed

arch/loongarch/include/asm/processor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ static inline void flush_thread(void)
191191
unsigned long __get_wchan(struct task_struct *p);
192192

193193
#define __KSTK_TOS(tsk) ((unsigned long)task_stack_page(tsk) + \
194-
THREAD_SIZE - 32 - sizeof(struct pt_regs))
194+
THREAD_SIZE - sizeof(struct pt_regs))
195195
#define task_pt_regs(tsk) ((struct pt_regs *)__KSTK_TOS(tsk))
196196
#define KSTK_EIP(tsk) (task_pt_regs(tsk)->csr_era)
197197
#define KSTK_ESP(tsk) (task_pt_regs(tsk)->regs[3])

arch/loongarch/include/asm/ptrace.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct pt_regs {
2929
unsigned long csr_euen;
3030
unsigned long csr_ecfg;
3131
unsigned long csr_estat;
32-
unsigned long __last[0];
32+
unsigned long __last[];
3333
} __aligned(8);
3434

3535
static inline int regs_irqs_disabled(struct pt_regs *regs)
@@ -133,7 +133,7 @@ static inline void die_if_kernel(const char *str, struct pt_regs *regs)
133133
#define current_pt_regs() \
134134
({ \
135135
unsigned long sp = (unsigned long)__builtin_frame_address(0); \
136-
(struct pt_regs *)((sp | (THREAD_SIZE - 1)) + 1 - 32) - 1; \
136+
(struct pt_regs *)((sp | (THREAD_SIZE - 1)) + 1) - 1; \
137137
})
138138

139139
/* Helpers for working with the user stack pointer */

arch/loongarch/kernel/head.S

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,9 @@ SYM_CODE_START(kernel_entry) # kernel entry point
8484

8585
la.pcrel tp, init_thread_union
8686
/* Set the SP after an empty pt_regs. */
87-
PTR_LI sp, (_THREAD_SIZE - 32 - PT_SIZE)
87+
PTR_LI sp, (_THREAD_SIZE - PT_SIZE)
8888
PTR_ADD sp, sp, tp
8989
set_saved_sp sp, t0, t1
90-
PTR_ADDI sp, sp, -4 * SZREG # init stack pointer
9190

9291
bl start_kernel
9392
ASM_BUG()

arch/loongarch/kernel/process.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
129129
unsigned long clone_flags = args->flags;
130130
struct pt_regs *childregs, *regs = current_pt_regs();
131131

132-
childksp = (unsigned long)task_stack_page(p) + THREAD_SIZE - 32;
132+
childksp = (unsigned long)task_stack_page(p) + THREAD_SIZE;
133133

134134
/* set up new TSS. */
135135
childregs = (struct pt_regs *) childksp - 1;
@@ -236,7 +236,7 @@ bool in_task_stack(unsigned long stack, struct task_struct *task,
236236
struct stack_info *info)
237237
{
238238
unsigned long begin = (unsigned long)task_stack_page(task);
239-
unsigned long end = begin + THREAD_SIZE - 32;
239+
unsigned long end = begin + THREAD_SIZE;
240240

241241
if (stack < begin || stack >= end)
242242
return false;

arch/loongarch/kernel/switch.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ SYM_FUNC_START(__switch_to)
2626
move tp, a2
2727
cpu_restore_nonscratch a1
2828

29-
li.w t0, _THREAD_SIZE - 32
29+
li.w t0, _THREAD_SIZE
3030
PTR_ADD t0, t0, tp
3131
set_saved_sp t0, t1, t2
3232

arch/loongarch/net/bpf_jit.c

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ static void emit_atomic(const struct bpf_insn *insn, struct jit_ctx *ctx)
279279
const u8 t1 = LOONGARCH_GPR_T1;
280280
const u8 t2 = LOONGARCH_GPR_T2;
281281
const u8 t3 = LOONGARCH_GPR_T3;
282+
const u8 r0 = regmap[BPF_REG_0];
282283
const u8 src = regmap[insn->src_reg];
283284
const u8 dst = regmap[insn->dst_reg];
284285
const s16 off = insn->off;
@@ -359,8 +360,6 @@ static void emit_atomic(const struct bpf_insn *insn, struct jit_ctx *ctx)
359360
break;
360361
/* r0 = atomic_cmpxchg(dst + off, r0, src); */
361362
case BPF_CMPXCHG:
362-
u8 r0 = regmap[BPF_REG_0];
363-
364363
move_reg(ctx, t2, r0);
365364
if (isdw) {
366365
emit_insn(ctx, lld, r0, t1, 0);
@@ -390,8 +389,11 @@ static bool is_signed_bpf_cond(u8 cond)
390389

391390
static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool extra_pass)
392391
{
393-
const bool is32 = BPF_CLASS(insn->code) == BPF_ALU ||
394-
BPF_CLASS(insn->code) == BPF_JMP32;
392+
u8 tm = -1;
393+
u64 func_addr;
394+
bool func_addr_fixed;
395+
int i = insn - ctx->prog->insnsi;
396+
int ret, jmp_offset;
395397
const u8 code = insn->code;
396398
const u8 cond = BPF_OP(code);
397399
const u8 t1 = LOONGARCH_GPR_T1;
@@ -400,8 +402,8 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool ext
400402
const u8 dst = regmap[insn->dst_reg];
401403
const s16 off = insn->off;
402404
const s32 imm = insn->imm;
403-
int jmp_offset;
404-
int i = insn - ctx->prog->insnsi;
405+
const u64 imm64 = (u64)(insn + 1)->imm << 32 | (u32)insn->imm;
406+
const bool is32 = BPF_CLASS(insn->code) == BPF_ALU || BPF_CLASS(insn->code) == BPF_JMP32;
405407

406408
switch (code) {
407409
/* dst = src */
@@ -724,24 +726,23 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool ext
724726
case BPF_JMP32 | BPF_JSGE | BPF_K:
725727
case BPF_JMP32 | BPF_JSLT | BPF_K:
726728
case BPF_JMP32 | BPF_JSLE | BPF_K:
727-
u8 t7 = -1;
728729
jmp_offset = bpf2la_offset(i, off, ctx);
729730
if (imm) {
730731
move_imm(ctx, t1, imm, false);
731-
t7 = t1;
732+
tm = t1;
732733
} else {
733734
/* If imm is 0, simply use zero register. */
734-
t7 = LOONGARCH_GPR_ZERO;
735+
tm = LOONGARCH_GPR_ZERO;
735736
}
736737
move_reg(ctx, t2, dst);
737738
if (is_signed_bpf_cond(BPF_OP(code))) {
738-
emit_sext_32(ctx, t7, is32);
739+
emit_sext_32(ctx, tm, is32);
739740
emit_sext_32(ctx, t2, is32);
740741
} else {
741-
emit_zext_32(ctx, t7, is32);
742+
emit_zext_32(ctx, tm, is32);
742743
emit_zext_32(ctx, t2, is32);
743744
}
744-
if (emit_cond_jmp(ctx, cond, t2, t7, jmp_offset) < 0)
745+
if (emit_cond_jmp(ctx, cond, t2, tm, jmp_offset) < 0)
745746
goto toofar;
746747
break;
747748

@@ -775,10 +776,6 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool ext
775776

776777
/* function call */
777778
case BPF_JMP | BPF_CALL:
778-
int ret;
779-
u64 func_addr;
780-
bool func_addr_fixed;
781-
782779
mark_call(ctx);
783780
ret = bpf_jit_get_func_addr(ctx->prog, insn, extra_pass,
784781
&func_addr, &func_addr_fixed);
@@ -811,8 +808,6 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool ext
811808

812809
/* dst = imm64 */
813810
case BPF_LD | BPF_IMM | BPF_DW:
814-
u64 imm64 = (u64)(insn + 1)->imm << 32 | (u32)insn->imm;
815-
816811
move_imm(ctx, dst, imm64, is32);
817812
return 1;
818813

drivers/platform/loongarch/loongson-laptop.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,13 @@ static int loongson_hotkey_resume(struct device *dev)
199199
struct key_entry ke;
200200
struct backlight_device *bd;
201201

202+
bd = backlight_device_get_by_type(BACKLIGHT_PLATFORM);
203+
if (bd) {
204+
loongson_laptop_backlight_update(bd) ?
205+
pr_warn("Loongson_backlight: resume brightness failed") :
206+
pr_info("Loongson_backlight: resume brightness %d\n", bd->props.brightness);
207+
}
208+
202209
/*
203210
* Only if the firmware supports SW_LID event model, we can handle the
204211
* event. This is for the consideration of development board without EC.
@@ -228,13 +235,6 @@ static int loongson_hotkey_resume(struct device *dev)
228235
}
229236
}
230237

231-
bd = backlight_device_get_by_type(BACKLIGHT_PLATFORM);
232-
if (bd) {
233-
loongson_laptop_backlight_update(bd) ?
234-
pr_warn("Loongson_backlight: resume brightness failed") :
235-
pr_info("Loongson_backlight: resume brightness %d\n", bd->props.brightness);
236-
}
237-
238238
return 0;
239239
}
240240

@@ -448,6 +448,7 @@ static int __init event_init(struct generic_sub_driver *sub_driver)
448448
if (ret < 0) {
449449
pr_err("Failed to setup input device keymap\n");
450450
input_free_device(generic_inputdev);
451+
generic_inputdev = NULL;
451452

452453
return ret;
453454
}
@@ -502,8 +503,11 @@ static int __init generic_subdriver_init(struct generic_sub_driver *sub_driver)
502503
if (ret)
503504
return -EINVAL;
504505

505-
if (sub_driver->init)
506-
sub_driver->init(sub_driver);
506+
if (sub_driver->init) {
507+
ret = sub_driver->init(sub_driver);
508+
if (ret)
509+
goto err_out;
510+
}
507511

508512
if (sub_driver->notify) {
509513
ret = setup_acpi_notify(sub_driver);
@@ -519,7 +523,7 @@ static int __init generic_subdriver_init(struct generic_sub_driver *sub_driver)
519523

520524
err_out:
521525
generic_subdriver_exit(sub_driver);
522-
return (ret < 0) ? ret : 0;
526+
return ret;
523527
}
524528

525529
static void generic_subdriver_exit(struct generic_sub_driver *sub_driver)

0 commit comments

Comments
 (0)