x86/mce: Prevent severity computation from being instrumented
Subsystems (3)
Hello Borislav Petkov,
This is a semi-automatic email about new static checker warnings.
The patch 0a5b288e85bb: "x86/mce: Prevent severity computation from being instrumented" from Oct 13, 2021, leads to the following Smatch complaint:
arch/x86/kernel/cpu/mce/severity.c:286 error_context()
warn: variable dereferenced before check 'regs' (see line 280)
arch/x86/kernel/cpu/mce/severity.c
279 fixup_type = ex_get_fixup_type(m->ip);
280 copy_user = is_copy_from_user(regs);
^^^^New unchecked dereference
281 instrumentation_end();
282
283 switch (fixup_type) {
284 case EX_TYPE_UACCESS:
285 case EX_TYPE_COPY:
286 if (!regs || !copy_user)
^^^^
Old code checked for NULL
287 return IN_KERNEL; 288 m->kflags |= MCE_IN_KERNEL_COPYIN;
regards,
dan carpenter
Borislav Petkov
maintainer+ Tony.
Quoted 24 lines · Dan Carpenter
Hello Borislav Petkov,
This is a semi-automatic email about new static checker warnings.
The patch
0a5b288e85bb: "x86/mce: Prevent severity computation from being instrumented" from Oct 13, 2021, leads to the following Smatch complaint:
arch/x86/kernel/cpu/mce/severity.c:286error_context()
warn: variable dereferenced before check 'regs' (see line 280)
arch/x86/kernel/cpu/mce/severity.c279 fixup_type = ex_get_fixup_type(m->ip); 280 copy_user = is_copy_from_user(regs); ^^^^New unchecked dereference
281 instrumentation_end(); 282 283 switch (fixup_type) { 284 case EX_TYPE_UACCESS: 285 case EX_TYPE_COPY: 286 if (!regs || !copy_user) ^^^^
Quoted 4 lines
Old code checked for NULL
287 return IN_KERNEL; 288 m->kflags |= MCE_IN_KERNEL_COPYIN;
Good catch, thanks!
I guess we can do something like this:
---
arch/x86/kernel/cpu/mce/severity.c +4 -1
@@ -222,6 +222,9 @@ static bool is_copy_from_user(struct pt_regs *regs)struct insn insn;int ret; +if (!regs) +return false; +if (copy_from_kernel_nofault (insn_buf, (void *)regs->ip,MAX_INSN_SIZE ))return false;
@@ -283,7 +286,7 @@ static noinstr int error_context(struct mce *m, struct pt_regs *regs)switch (fixup_type) {case EX_TYPE_UACCESS :case EX_TYPE_COPY : -if (!regs || !copy_user) +if (!copy_user)return IN_KERNEL ; m->kflags |=MCE_IN_KERNEL_COPYIN ; fallthrough;
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 53 lines · Borislav Petkov
+ Tony.
Quoted 24 lines · Dan Carpenter
Hello Borislav Petkov,
This is a semi-automatic email about new static checker warnings.
The patch
0a5b288e85bb: "x86/mce: Prevent severity computation from being instrumented" from Oct 13, 2021, leads to the following Smatch complaint:
arch/x86/kernel/cpu/mce/severity.c:286error_context()
warn: variable dereferenced before check 'regs' (see line 280)
arch/x86/kernel/cpu/mce/severity.c279 fixup_type = ex_get_fixup_type(m->ip); 280 copy_user = is_copy_from_user(regs); ^^^^New unchecked dereference
281 instrumentation_end(); 282 283 switch (fixup_type) { 284 case EX_TYPE_UACCESS: 285 case EX_TYPE_COPY: 286 if (!regs || !copy_user) ^^^^Quoted 4 lines
Old code checked for NULL
287 return IN_KERNEL; 288 m->kflags |= MCE_IN_KERNEL_COPYIN;Good catch, thanks!
I guess we can do something like this:
---
arch/x86/kernel/cpu/mce/severity.c +3
-0@@ -222,6 +222,9 @@ static bool is_copy_from_user(struct pt_regs *regs)struct insn insn;int ret; +if (!regs) +return false; +if (copy_from_kernel_nofault (insn_buf, (void *)regs->ip,MAX_INSN_SIZE ))return false;
arch/x86/kernel/cpu/mce/severity.c static noinstr int error_context(struct mce *m, struct pt_regs *regs) · line 292
Quoted 8 lines
arch/x86/kernel/cpu/mce/severity.c +1
-1@@ -283,7 +286,7 @@ static noinstr int error_context(struct mce *m, struct pt_regs *regs)switch (fixup_type) {case EX_TYPE_UACCESS :case EX_TYPE_COPY : -if (!regs || !copy_user) +if (!copy_user)return IN_KERNEL ; m->kflags |=MCE_IN_KERNEL_COPYIN ; fallthrough;
Looks good to me.
-Tony
Borislav Petkov
maintainerPATCH 1/1 x86/mce: Check regs before accessing it
From: Borislav Petkov <[email protected]>
Commit in Fixes accesses pt_regs before checking whether it is NULL or not. Change the flow so that the NULL pointer check happens first.
--- arch/x86/kernel/cpu/mce/severity.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/mce/severity.c +4 -1
@@ -222,6 +222,9 @@ static bool is_copy_from_user(struct pt_regs *regs)struct insn insn;int ret; +if (!regs) +return false; +if (copy_from_kernel_nofault (insn_buf, (void *)regs->ip,MAX_INSN_SIZE ))return false;
@@ -283,7 +286,7 @@ static noinstr int error_context(struct mce *m, struct pt_regs *regs)switch (fixup_type) {case EX_TYPE_UACCESS :case EX_TYPE_COPY : -if (!regs || !copy_user) +if (!copy_user)return IN_KERNEL ; m->kflags |=MCE_IN_KERNEL_COPYIN ; fallthrough;
Signature · 8 lines
2.29.2
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette[tip: ras/core] x86/mce: Check regs before accessing it
In reply to Dan CarpenterThe following commit has been merged into the ras/core branch of tip:
The following commit has been merged into the ras/core branch of tip:
Commit-ID: 1acd85feba81084fcef00b73fc1601e42b77c5d8 Gitweb: https://git.kernel.org/tip/1acd85feba81084fcef00b73fc1601e42b77c5d8 Author: Borislav Petkov <[email protected]> AuthorDate: Fri, 17 Dec 2021 16:49:25 +01:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Mon, 20 Dec 2021 11:41:02 +01:00
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.
--- arch/x86/kernel/cpu/mce/severity.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/mce/severity.c +4 -1
@@ -222,6 +222,9 @@ static bool is_copy_from_user(struct pt_regs *regs)struct insn insn;int ret; +if (!regs) +return false; +if (copy_from_kernel_nofault (insn_buf, (void *)regs->ip,MAX_INSN_SIZE ))return false;
@@ -283,7 +286,7 @@ static noinstr int error_context(struct mce *m, struct pt_regs *regs)switch (fixup_type) {case EX_TYPE_UACCESS :case EX_TYPE_COPY : -if (!regs || !copy_user) +if (!copy_user)return IN_KERNEL ; m->kflags |=MCE_IN_KERNEL_COPYIN ; fallthrough;