eh-steve / goloader

Compile, load and run Go code at runtime.
Apache License 2.0
54 stars 4 forks source link

Type deduplication safety improvements #3

Closed eh-steve closed 1 year ago

eh-steve commented 1 year ago

Improve firstmodule type registration by generating fully qualified symbol names from type names correctly. Previously not all typelinks mapped to the correct symbol name due to an overly simplistic renaming scheme. Now, all firstmodule types should be found correctly, and if not, goloader will panic to highlight the bug.

Also only deduplicate structurally identical types, even if symbol names match. Previously, if a type's symbol name was found in the firstmodule, this would be be blindly used in relocations, even if the JIT code's version of the type was different. This could result in unsafe code execution due to a mismatch between type descriptors and generated assembly (see TestMismatchedTypes for an specific (contrived) example).

We now also force the rebuild of types outside the stdlib so they can be compared for structural equality and the correct relocation decision can be made.

pkujhd commented 1 year ago

Sorry, I have been very busy with work recently, so I may not have time to review. If I have free time, I will do it as soon as possible.

eh-steve commented 1 year ago

Sorry, I have been very busy with work recently, so I may not have time to review. If I have free time, I will do it as soon as possible.

No worries, I just tagged you for review as the type registration/naming fixes will be relevant for your branch too, and I thought you might be interested in the other safety fixes