Skip to content

Commit 1acd85f

Browse files
committed
x86/mce: Check regs before accessing it
Commit in Fixes accesses pt_regs before checking whether it is NULL or not. Make sure the NULL pointer check happens first. Fixes: 0a5b288 ("x86/mce: Prevent severity computation from being instrumented") Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Borislav Petkov <bp@suse.de> Reviewed-by: Tony Luck <tony.luck@intel.com> Link: https://lore.kernel.org/r/20211217102029.GA29708@kili
1 parent e3d72e8 commit 1acd85f

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

arch/x86/kernel/cpu/mce/severity.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ static bool is_copy_from_user(struct pt_regs *regs)
222222
struct insn insn;
223223
int ret;
224224

225+
if (!regs)
226+
return false;
227+
225228
if (copy_from_kernel_nofault(insn_buf, (void *)regs->ip, MAX_INSN_SIZE))
226229
return false;
227230

@@ -283,7 +286,7 @@ static noinstr int error_context(struct mce *m, struct pt_regs *regs)
283286
switch (fixup_type) {
284287
case EX_TYPE_UACCESS:
285288
case EX_TYPE_COPY:
286-
if (!regs || !copy_user)
289+
if (!copy_user)
287290
return IN_KERNEL;
288291
m->kflags |= MCE_IN_KERNEL_COPYIN;
289292
fallthrough;

0 commit comments

Comments
 (0)