diff options
| author | Andrea Corallo | 2019-12-27 16:28:44 +0100 |
|---|---|---|
| committer | Andrea Corallo | 2020-01-01 11:38:17 +0100 |
| commit | c00236a880567c72dcdba5fc90d6de1125616c76 (patch) | |
| tree | 1510bee3f3fb730a682af593bae15fa8adec4d12 /src | |
| parent | 1c08dc82121d50e80bd2dcb0d1f39654cc6762dd (diff) | |
| download | emacs-c00236a880567c72dcdba5fc90d6de1125616c76.tar.gz emacs-c00236a880567c72dcdba5fc90d6de1125616c76.zip | |
sign and check function link table
Diffstat (limited to 'src')
| -rw-r--r-- | src/comp.c | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/src/comp.c b/src/comp.c index eacda5de550..5ef09086407 100644 --- a/src/comp.c +++ b/src/comp.c | |||
| @@ -33,12 +33,14 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 33 | #include "dynlib.h" | 33 | #include "dynlib.h" |
| 34 | #include "buffer.h" | 34 | #include "buffer.h" |
| 35 | #include "blockinput.h" | 35 | #include "blockinput.h" |
| 36 | #include "sha512.h" | ||
| 36 | 37 | ||
| 37 | /* C symbols emitted for the load relocation mechanism. */ | 38 | /* C symbols emitted for the load relocation mechanism. */ |
| 38 | #define CURRENT_THREAD_RELOC_SYM "current_thread_reloc" | 39 | #define CURRENT_THREAD_RELOC_SYM "current_thread_reloc" |
| 39 | #define PURE_RELOC_SYM "pure_reloc" | 40 | #define PURE_RELOC_SYM "pure_reloc" |
| 40 | #define DATA_RELOC_SYM "d_reloc" | 41 | #define DATA_RELOC_SYM "d_reloc" |
| 41 | #define FUNC_LINK_TABLE_SYM "freloc_link_table" | 42 | #define FUNC_LINK_TABLE_SYM "freloc_link_table" |
| 43 | #define LINK_TABLE_HASH_SYM "freloc_hash" | ||
| 42 | #define TEXT_DATA_RELOC_SYM "text_data_reloc" | 44 | #define TEXT_DATA_RELOC_SYM "text_data_reloc" |
| 43 | 45 | ||
| 44 | #define SPEED XFIXNUM (Fsymbol_value (Qcomp_speed)) | 46 | #define SPEED XFIXNUM (Fsymbol_value (Qcomp_speed)) |
| @@ -225,6 +227,21 @@ format_string (const char *format, ...) | |||
| 225 | return scratch_area; | 227 | return scratch_area; |
| 226 | } | 228 | } |
| 227 | 229 | ||
| 230 | /* Produce a key hashing Vcomp_subr_list. */ | ||
| 231 | |||
| 232 | static Lisp_Object | ||
| 233 | hash_subr_list (void) | ||
| 234 | { | ||
| 235 | Lisp_Object string = Fmapconcat (intern_c_string ("subr-name"), | ||
| 236 | Vcomp_subr_list, build_string (" ")); | ||
| 237 | Lisp_Object digest = make_uninit_string (SHA512_DIGEST_SIZE * 2); | ||
| 238 | |||
| 239 | sha512_buffer (SSDATA (string), SCHARS (string), SSDATA (digest)); | ||
| 240 | hexbuf_digest (SSDATA (digest), SDATA (digest), SHA512_DIGEST_SIZE); | ||
| 241 | |||
| 242 | return digest; | ||
| 243 | } | ||
| 244 | |||
| 228 | static void | 245 | static void |
| 229 | freloc_check_fill (void) | 246 | freloc_check_fill (void) |
| 230 | { | 247 | { |
| @@ -1852,6 +1869,9 @@ emit_ctxt_code (void) | |||
| 1852 | fields[n_frelocs++] = xmint_pointer (XCDR (el)); | 1869 | fields[n_frelocs++] = xmint_pointer (XCDR (el)); |
| 1853 | } | 1870 | } |
| 1854 | 1871 | ||
| 1872 | /* Compute and store function link table hash. */ | ||
| 1873 | emit_static_object (LINK_TABLE_HASH_SYM, hash_subr_list ()); | ||
| 1874 | |||
| 1855 | Lisp_Object subr_l = Vcomp_subr_list; | 1875 | Lisp_Object subr_l = Vcomp_subr_list; |
| 1856 | FOR_EACH_TAIL (subr_l) | 1876 | FOR_EACH_TAIL (subr_l) |
| 1857 | { | 1877 | { |
| @@ -3205,10 +3225,12 @@ typedef char *(*comp_lit_str_func) (void); | |||
| 3205 | 3225 | ||
| 3206 | /* Deserialize read and return static object. */ | 3226 | /* Deserialize read and return static object. */ |
| 3207 | static Lisp_Object | 3227 | static Lisp_Object |
| 3208 | load_static_obj (dynlib_handle_ptr handle, const char *name) | 3228 | load_static_obj (struct Lisp_Native_Comp_Unit *comp_u, const char *name) |
| 3209 | { | 3229 | { |
| 3210 | static_obj_t *(*f)(void) = dynlib_sym (handle, name); | 3230 | static_obj_t *(*f)(void) = dynlib_sym (comp_u->handle, name); |
| 3211 | eassert (f); | 3231 | if (!f) |
| 3232 | xsignal1 (Qnative_lisp_file_inconsistent, comp_u->file); | ||
| 3233 | |||
| 3212 | static_obj_t *res = f (); | 3234 | static_obj_t *res = f (); |
| 3213 | return Fread (make_string (res->data, res->len)); | 3235 | return Fread (make_string (res->data, res->len)); |
| 3214 | } | 3236 | } |
| @@ -3230,7 +3252,9 @@ load_comp_unit (struct Lisp_Native_Comp_Unit *comp_u, bool loading_dump) | |||
| 3230 | && pure_reloc | 3252 | && pure_reloc |
| 3231 | && data_relocs | 3253 | && data_relocs |
| 3232 | && freloc_link_table | 3254 | && freloc_link_table |
| 3233 | && top_level_run)) | 3255 | && top_level_run) |
| 3256 | || NILP (Fstring_equal (load_static_obj (comp_u, LINK_TABLE_HASH_SYM), | ||
| 3257 | hash_subr_list ()))) | ||
| 3234 | xsignal1 (Qnative_lisp_file_inconsistent, comp_u->file); | 3258 | xsignal1 (Qnative_lisp_file_inconsistent, comp_u->file); |
| 3235 | 3259 | ||
| 3236 | *current_thread_reloc = ¤t_thread; | 3260 | *current_thread_reloc = ¤t_thread; |
| @@ -3241,7 +3265,7 @@ load_comp_unit (struct Lisp_Native_Comp_Unit *comp_u, bool loading_dump) | |||
| 3241 | 3265 | ||
| 3242 | /* Imported data. */ | 3266 | /* Imported data. */ |
| 3243 | if (!loading_dump) | 3267 | if (!loading_dump) |
| 3244 | comp_u->data_vec = load_static_obj (handle, TEXT_DATA_RELOC_SYM); | 3268 | comp_u->data_vec = load_static_obj (comp_u, TEXT_DATA_RELOC_SYM); |
| 3245 | 3269 | ||
| 3246 | EMACS_INT d_vec_len = XFIXNUM (Flength (comp_u->data_vec)); | 3270 | EMACS_INT d_vec_len = XFIXNUM (Flength (comp_u->data_vec)); |
| 3247 | 3271 | ||
| @@ -3408,7 +3432,8 @@ syms_of_comp (void) | |||
| 3408 | Fput (Qnative_lisp_file_inconsistent, Qerror_conditions, | 3432 | Fput (Qnative_lisp_file_inconsistent, Qerror_conditions, |
| 3409 | pure_list (Qnative_lisp_file_inconsistent, Qnative_lisp_load_failed, Qerror)); | 3433 | pure_list (Qnative_lisp_file_inconsistent, Qnative_lisp_load_failed, Qerror)); |
| 3410 | Fput (Qnative_lisp_file_inconsistent, Qerror_message, | 3434 | Fput (Qnative_lisp_file_inconsistent, Qerror_message, |
| 3411 | build_pure_c_string ("inconsistent eln file")); | 3435 | build_pure_c_string ("eln file inconsistent with current runtime " |
| 3436 | "configuration, please recompile")); | ||
| 3412 | 3437 | ||
| 3413 | defsubr (&Scomp__init_ctxt); | 3438 | defsubr (&Scomp__init_ctxt); |
| 3414 | defsubr (&Scomp__release_ctxt); | 3439 | defsubr (&Scomp__release_ctxt); |