@@ -228,3 +228,21 @@ unsigned long asmlinkage search_pre_exception_table(struct cpu_user_regs *regs)
}
return fixup;
}
+
+#ifdef CONFIG_LIVEPATCH
+bool extable_in_bounds(const struct exception_table_entry *ex_start,
+ const struct exception_table_entry *ex_end,
+ const void *start, const void *end)
+{
+ for ( ; ex_start < ex_end; ex_start++ )
+ {
+ const void *addr = _p(ex_addr(ex_start));
+ const void *cont = _p(ex_cont(ex_start));
+
+ if ( addr < start || addr >= end || cont < start || cont >= end )
+ return false;
+ }
+
+ return true;
+}
+#endif
@@ -426,5 +426,8 @@ extern unsigned long search_exception_table(const struct cpu_user_regs *regs,
extern void sort_exception_tables(void);
extern void sort_exception_table(struct exception_table_entry *start,
const struct exception_table_entry *stop);
+extern bool extable_in_bounds(const struct exception_table_entry *ex_start,
+ const struct exception_table_entry *ex_end,
+ const void *start, const void *end);
#endif /* __X86_UACCESS_H__ */
@@ -912,6 +912,15 @@ static int prepare_payload(struct payload *payload,
s = sec->load_addr;
e = sec->load_addr + sec->sec->sh_size;
+ if ( !extable_in_bounds(s, e, payload->text_addr,
+ payload->text_addr + payload->text_size) )
+ {
+ printk(XENLOG_ERR LIVEPATCH
+ "%s: Invalid exception table with out of bounds entries\n",
+ elf->name);
+ return -EINVAL;
+ }
+
sort_exception_table(s ,e);
region->ex = s;