Skip to content

Commit 32d8599

Browse files
ardbiesheuvelctmarinas
authored andcommitted
arm64: compat: Work around uninitialized variable warning
Dan reports that smatch complains about a potential uninitialized variable being used in the compat alignment fixup code. The logic is not wrong per se, but we do end up using an uninitialized variable if reading the instruction that triggered the alignment fault from user space faults, even if the fault ensures that the uninitialized value doesn't propagate any further. Given that we just give up and return 1 if any fault occurs when reading the instruction, let's get rid of the 'success handling' pattern that captures the fault in a variable and aborts later, and instead, just return 1 immediately if any of the get_user() calls result in an exception. Fixes: 3fc24ef ("arm64: compat: Implement misalignment fixups for multiword loads") Reported-by: kernel test robot <[email protected]> Reported-by: Dan Carpenter <[email protected]> Link: https://lore.kernel.org/r/[email protected]/ Signed-off-by: Ard Biesheuvel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent e8d018d commit 32d8599

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

arch/arm64/kernel/compat_alignment.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -314,36 +314,32 @@ int do_compat_alignment_fixup(unsigned long addr, struct pt_regs *regs)
314314
int (*handler)(unsigned long addr, u32 instr, struct pt_regs *regs);
315315
unsigned int type;
316316
u32 instr = 0;
317-
u16 tinstr = 0;
318317
int isize = 4;
319318
int thumb2_32b = 0;
320-
int fault;
321319

322320
instrptr = instruction_pointer(regs);
323321

324322
if (compat_thumb_mode(regs)) {
325323
__le16 __user *ptr = (__le16 __user *)(instrptr & ~1);
324+
u16 tinstr, tinst2;
326325

327-
fault = alignment_get_thumb(regs, ptr, &tinstr);
328-
if (!fault) {
329-
if (IS_T32(tinstr)) {
330-
/* Thumb-2 32-bit */
331-
u16 tinst2;
332-
fault = alignment_get_thumb(regs, ptr + 1, &tinst2);
333-
instr = ((u32)tinstr << 16) | tinst2;
334-
thumb2_32b = 1;
335-
} else {
336-
isize = 2;
337-
instr = thumb2arm(tinstr);
338-
}
326+
if (alignment_get_thumb(regs, ptr, &tinstr))
327+
return 1;
328+
329+
if (IS_T32(tinstr)) { /* Thumb-2 32-bit */
330+
if (alignment_get_thumb(regs, ptr + 1, &tinst2))
331+
return 1;
332+
instr = ((u32)tinstr << 16) | tinst2;
333+
thumb2_32b = 1;
334+
} else {
335+
isize = 2;
336+
instr = thumb2arm(tinstr);
339337
}
340338
} else {
341-
fault = alignment_get_arm(regs, (__le32 __user *)instrptr, &instr);
339+
if (alignment_get_arm(regs, (__le32 __user *)instrptr, &instr))
340+
return 1;
342341
}
343342

344-
if (fault)
345-
return 1;
346-
347343
switch (CODING_BITS(instr)) {
348344
case 0x00000000: /* 3.13.4 load/store instruction extensions */
349345
if (LDSTHD_I_BIT(instr))

0 commit comments

Comments
 (0)