Skip to content

Commit bc9d671

Browse files
kpamnanygbaraldivtjnash
authored andcommitted
Add boundscheck in bindingkey_eq to avoid OOB access due to data race (JuliaLang#54671) (#158)
The race here is that svec might be replaced and a new binding introduced into the keyset while we hold a reference to the old svec, which led to a OOB access on the svec with the index a binding introduced at the same time. This now introduces a bounds check which will force taking the lock if we fail the lookup i.e we had a data race. Fixes JuliaLang#54285 --------- Co-authored-by: Gabriel Baraldi <baraldigabriel@gmail.com> Co-authored-by: Jameson Nash <vtjnash@gmail.com>
1 parent 4f2881d commit bc9d671

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/module.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,13 +702,15 @@ JL_DLLEXPORT int jl_binding_resolved_p(jl_module_t *m, jl_sym_t *var)
702702

703703
static uint_t bindingkey_hash(size_t idx, jl_svec_t *data)
704704
{
705-
jl_binding_t *b = (jl_binding_t*)jl_svecref(data, idx);
705+
jl_binding_t *b = (jl_binding_t*)jl_svecref(data, idx); // This must always happen inside the lock
706706
jl_sym_t *var = b->globalref->name;
707707
return var->hash;
708708
}
709709

710710
static int bindingkey_eq(size_t idx, const void *var, jl_svec_t *data, uint_t hv)
711711
{
712+
if (idx >= jl_svec_len(data))
713+
return 0; // We got a OOB access, probably due to a data race
712714
jl_binding_t *b = (jl_binding_t*)jl_svecref(data, idx);
713715
jl_sym_t *name = b->globalref->name;
714716
return var == name;

0 commit comments

Comments
 (0)