x86/mce: Fix buggy error path in cpu_bank_alloc() leading to UAF
PATCH 1/1 x86/mce: Fix buggy error path in cpu_bank_alloc() leading to UAF
When cleaning up from a mcabanks_alloc() failure, the memory is freed but stale pointers are left in the percpu variables.
Use cpu_bank_free() which is idempotent and behaves correctly.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
2e6c8f182c9c updated the success path but missed the associated error path.
Prior to that, the paths were at least consistent since their introduction in commit 78c579426fb5 ("x86/MCE: Implement clearbank callback for AMD").
--- xen/arch/x86/cpu/mcheck/mce.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
xen/arch/x86/cpu/mcheck/mce.c +1 -2
@@ -694,8 +694,7 @@ static int cpu_bank_alloc(unsigned int cpu)if ( !poll || !clr ) { -mcabanks_free (poll); -mcabanks_free (clr); +cpu_bank_free (cpu);return -ENOMEM ; }
Signature · 1 line
2.39.5
Quoted 5 lines · Andrew Cooper
When cleaning up from a
mcabanks_alloc()failure, the memory is freed but stale pointers are left in the percpu variables.Use
cpu_bank_free()which is idempotent and behaves correctly.
Quoted 7 lines
Fixes 2e6c8f182c9c ("x86: distinguish CPU offlining from CPU removal")Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
2e6c8f182c9cupdated the success path but missed the associated error path.
I don't think so, see below.
Quoted 11 lines
Prior to that, the paths were at least consistent since their introduction in commit
78c579426fb5("x86/MCE: Implement clearbank callback for AMD").--- xen/arch/x86/cpu/mcheck/mce.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)xen/arch/x86/cpu/mcheck/mce.c +0
-0
xen/arch/x86/cpu/mcheck/mce.c static int cpu_bank_alloc(unsigned int cpu) · line 697
Quoted 6 lines
xen/arch/x86/cpu/mcheck/mce.c +1
-2@@ -694,8 +694,7 @@ static int cpu_bank_alloc(unsigned int cpu)if ( !poll || !clr ) { -mcabanks_free (poll); -mcabanks_free (clr); +cpu_bank_free (cpu);
But this way we'll leak the allocation that may have succeeded, as the per-CPU data is updated only afterwards. Yet it's those per-CPU items which cpu_bank_free() reads.
I don't think there's any bug to fix here: Neither of the two pointers is allocated anywhere else, so the per-CPU slots are always both NULL or both non-NULL.
Jan