Skip to content

Commit 50c7389

Browse files
miniplitorvalds
authored andcommitted
x86/extable: ensure entries are swapped completely when sorting
The x86 exception table sorting was changed in commit 29934b0 ("x86/extable: use generic search and sort routines") to use the arch independent code in lib/extable.c. However, the patch was mangled somehow on its way into the kernel from the last version posted at [1]. The committed version kind of attempted to incorporate the changes of commit 548acf1 ("x86/mm: Expand the exception table logic to allow new handling options") as in _completely_ _ignoring_ the x86 specific 'handler' member of struct exception_table_entry. This effectively broke the sorting as entries will only partly be swapped now. Fortunately, the x86 Kconfig selects BUILDTIME_EXTABLE_SORT, so the exception table doesn't need to be sorted at runtime. However, in case that ever changes, we better not break the exception table sorting just because of that. [ Ard Biesheuvel points out that BUILDTIME_EXTABLE_SORT applies to the core image only, but we still rely on the sorting routines for modules in that case - Linus ] Fix this by providing a swap_ex_entry_fixup() macro that takes care of the 'handler' member. [1] https://lkml.org/lkml/2016/1/27/232 Signed-off-by: Mathias Krause <minipli@googlemail.com> Fixes: 29934b0 ("x86/extable: use generic search and sort routines") Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@suse.de> Cc: H. Peter Anvin <hpa@linux.intel.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Tony Luck <tony.luck@intel.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent e0d09e3 commit 50c7389

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

arch/x86/include/asm/uaccess.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ struct exception_table_entry {
108108

109109
#define ARCH_HAS_RELATIVE_EXTABLE
110110

111+
#define swap_ex_entry_fixup(a, b, tmp, delta) \
112+
do { \
113+
(a)->fixup = (b)->fixup + (delta); \
114+
(b)->fixup = (tmp).fixup - (delta); \
115+
(a)->handler = (b)->handler + (delta); \
116+
(b)->handler = (tmp).handler - (delta); \
117+
} while (0)
118+
111119
extern int fixup_exception(struct pt_regs *regs, int trapnr);
112120
extern bool ex_has_fault_handler(unsigned long ip);
113121
extern int early_fixup_exception(unsigned long *ip);

0 commit comments

Comments
 (0)