]> Git Repo - linux.git/commitdiff
x86/ldt: Plug memory leak in error path
authorThomas Gleixner <[email protected]>
Sun, 31 Dec 2017 10:24:34 +0000 (11:24 +0100)
committerIngo Molnar <[email protected]>
Sun, 31 Dec 2017 11:14:07 +0000 (12:14 +0100)
The error path in write_ldt() tries to free 'old_ldt' instead of the newly
allocated 'new_ldt', resulting in a memory leak. It also misses to clean up a
half populated LDT pagetable, which is not a leak as it gets cleaned up
when the process exits.

Free both the potentially half populated LDT pagetable and the newly
allocated LDT struct. This can be done unconditionally because once an LDT
is mapped subsequent maps will succeed, because the PTE page is already
populated and the two LDTs fit into that single page.

Reported-by: Mathieu Desnoyers <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: Dominik Brodowski <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Fixes: f55f0501cbf6 ("x86/pti: Put the LDT in its own PGD if PTI is on")
Link: http://lkml.kernel.org/r/alpine.DEB.2.20.1712311121340.1899@nanos
Signed-off-by: Ingo Molnar <[email protected]>
arch/x86/kernel/ldt.c

index 579cc4a66fdf663c7e1c727d6272a3a83fbf0648..500e90e44f8669b0249dc0b16d815c4f77d269fc 100644 (file)
@@ -421,7 +421,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
         */
        error = map_ldt_struct(mm, new_ldt, old_ldt ? !old_ldt->slot : 0);
        if (error) {
-               free_ldt_struct(old_ldt);
+               /*
+                * This only can fail for the first LDT setup. If an LDT is
+                * already installed then the PTE page is already
+                * populated. Mop up a half populated page table.
+                */
+               free_ldt_pgtables(mm);
+               free_ldt_struct(new_ldt);
                goto out_unlock;
        }
 
This page took 0.056713 seconds and 4 git commands to generate.