mariadb/mysys
Martin Beck 4e0dcf1083 MDEV-27088: Server crash on ARM (WMM architecture) due to missing barriers in lf-hash
MariaDB server crashes on ARM (weak memory model architecture) while
concurrently executing l_find to load node->key and add_to_purgatory
to store node->key = NULL. l_find then uses key (which is NULL), to
pass it to a comparison function.

The specific problem is the out-of-order execution that happens on a
weak memory model architecture. Two essential reorderings are possible,
which need to be prevented.

a) As l_find has no barriers in place between the optimistic read of
the key field lf_hash.cc#L117 and the verification of link lf_hash.cc#L124,
the processor can reorder the load to happen after the while-loop.

In that case, a concurrent thread executing add_to_purgatory on the same
node can be scheduled to store NULL at the key field lf_alloc-pin.c#L253
before key is loaded in l_find.

b) A node is marked as deleted by a CAS in l_delete lf_hash.cc#L247 and
taken off the list with an upfollowing CAS lf_hash.cc#L252. Only if both
CAS succeed, the key field is written to by add_to_purgatory. However,
due to a missing barrier, the relaxed store of key lf_alloc-pin.c#L253
can be moved ahead of the two CAS operations, which makes the value of
the local purgatory list stored by add_to_purgatory visible to all threads
operating on the list. As the node is not marked as deleted yet, the
same error occurs in l_find.

This change three accesses to be atomic.

* optimistic read of key in l_find lf_hash.cc#L117
* read of link for verification lf_hash.cc#L124
* write of key in add_to_purgatory lf_alloc-pin.c#L253

Reviewers: Sergei Vojtovich, Sergei Golubchik

Fixes: MDEV-23510 / d30c1331a18d875e553f3fcf544997e4f33fb943
2021-11-30 11:30:52 +11:00
..
array.c MDEV-22387: Do not violate __attribute__((nonnull)) 2020-11-02 14:19:21 +02:00
base64.c Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
ChangeLog
charset-def.c Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
charset.c MDEV-19750 mysql command wrong encoding 2019-06-17 18:04:47 +01:00
checksum.c Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
CMakeLists.txt Only link mysys_ssl when required. 2019-06-03 09:55:59 +02:00
errors.c Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
file_logger.c Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
get_password.c Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
hash.c UBSAN UndefinedBehaviorSanitizer: undefined-behavior ../mysys/hash.c:798:9 2020-10-03 12:38:43 +03:00
lf_alloc-pin.c MDEV-27088: Server crash on ARM (WMM architecture) due to missing barriers in lf-hash 2021-11-30 11:30:52 +11:00
lf_dynarray.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
lf_hash.c MDEV-27088: Server crash on ARM (WMM architecture) due to missing barriers in lf-hash 2021-11-30 11:30:52 +11:00
list.c Merge 10.1 into 10.2 2020-05-13 11:12:31 +03:00
ma_dyncol.c Merge 10.1 into 10.2 2018-02-08 13:53:21 +02:00
mf_arr_appstr.c Update FSF Address 2019-05-11 21:29:06 +03:00
mf_cache.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
mf_dirname.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
mf_fn_ext.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
mf_format.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
mf_getdate.c Update FSF Address 2019-05-11 21:29:06 +03:00
mf_iocache.c fix clang build 2021-06-15 13:10:16 +03:00
mf_iocache2.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
mf_keycache.c Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
mf_keycaches.c Update FSF Address 2019-05-11 21:29:06 +03:00
mf_loadpath.c Update FSF Address 2019-05-11 21:29:06 +03:00
mf_pack.c Update FSF Address 2019-05-11 21:29:06 +03:00
mf_path.c Update FSF Address 2019-05-11 21:29:06 +03:00
mf_qsort.c fix clang build: check alignment the other way 2021-07-26 12:37:25 +03:00
mf_qsort2.c Update FSF Address 2019-05-11 21:29:06 +03:00
mf_radix.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
mf_same.c Update FSF Address 2019-05-11 21:29:06 +03:00
mf_sort.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
mf_soundex.c Update FSF Address 2019-05-11 21:29:06 +03:00
mf_tempdir.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
mf_tempfile.c Update FSF Address 2019-05-11 21:29:06 +03:00
mf_unixpath.c Update FSF Address 2019-05-11 21:29:06 +03:00
mf_wcomp.c Update FSF Address 2019-05-11 21:29:06 +03:00
mulalloc.c Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
my_access.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
my_addr_resolve.c MDEV-21646: postfix - my_addr_resolve: static Dl_info info 2020-12-15 14:47:16 +11:00
my_alarm.c Update FSF Address 2019-05-11 21:29:06 +03:00
my_alloc.c MDEV-22387: Do not violate __attribute__((nonnull)) 2020-11-02 14:19:21 +02:00
my_atomic.c Update FSF Address 2019-05-11 21:29:06 +03:00
my_atomic_writes.c Make atomic writes general 2017-01-11 09:18:35 +02:00
my_basename.c Update FSF Address 2019-05-11 21:29:06 +03:00
my_bit.c Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
my_bitmap.c assert(a && b); -> assert(a); assert(b); 2020-05-27 15:56:40 +02:00
my_chmod.c Merge branch '5.5' into 10.1 2019-05-11 19:15:57 +03:00
my_chsize.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
my_compare.c Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
my_compress.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
my_conio.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
my_context.c Xcode compatibility update 2021-10-12 18:10:56 -04:00
my_copy.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
my_create.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
my_default.c Merge branch '10.1' into 10.2 2020-03-05 10:52:43 +02:00
my_delete.c MDEV-25584 Implement posix semantics file deletion for Windows 10 2021-05-03 15:35:00 +02:00
my_div.c Update FSF Address 2019-05-11 21:29:06 +03:00
my_dlerror.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
my_error.c remove non-working debug assert 2020-10-29 09:35:39 +01:00
my_file.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
my_fopen.c Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
my_fstream.c Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
my_gethwaddr.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
my_getncpus.c Correct FreeBSD cpuset_t type 2020-04-03 15:30:33 +02:00
my_getopt.c Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
my_getpagesize.c Update FSF Address 2019-05-11 21:29:06 +03:00
my_getsystime.c Update FSF Address 2019-05-11 21:29:06 +03:00
my_getwd.c Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
my_init.c Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
my_largepage.c Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
my_lib.c A better fix for edd7e7c 2020-04-01 16:25:07 +04:00
my_libwrap.c Update FSF Address 2019-05-11 21:29:06 +03:00
my_lock.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
my_lockmem.c Update FSF Address 2019-05-11 21:29:06 +03:00
my_malloc.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
my_memmem.c Update FSF Address 2019-05-11 21:29:06 +03:00
my_mess.c Update FSF Address 2019-05-11 21:29:06 +03:00
my_mkdir.c Update FSF Address 2019-05-11 21:29:06 +03:00
my_mmap.c Update FSF Address 2019-05-11 21:29:06 +03:00
my_new.cc Update FSF Address 2019-05-11 21:29:06 +03:00
my_once.c Update FSF Address 2019-05-11 21:29:06 +03:00
my_open.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
my_port.c Follow-up to changing FSF address 2019-05-11 18:30:45 +03:00
my_pread.c Fix debug assert to match its intention. 2019-06-17 19:01:15 +01:00
my_pthread.c Update FSF Address 2019-05-11 21:29:06 +03:00
my_quick.c Update FSF Address 2019-05-11 21:29:06 +03:00
my_rdtsc.c speed up my_timer_init() 2020-07-29 08:21:32 +03:00
my_read.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
my_redel.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
my_rename.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
my_rnd.c Merge branch '5.5' into 10.1 2019-05-11 19:15:57 +03:00
my_safehash.c Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
my_safehash.h Update FSF address 2019-05-10 20:52:00 +03:00
my_seek.c myseek: AIX has no "tell" 2021-03-19 11:14:53 +11:00
my_setuser.c MDEV-11676 Starting service with mysqld_safe_helper fails in SELINUX "enforcing" mode 2017-01-04 13:38:03 +01:00
my_sleep.c Update FSF Address 2019-05-11 21:29:06 +03:00
my_static.c Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
my_static.h Update FSF Address 2019-05-11 21:29:06 +03:00
my_symlink.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
my_symlink2.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
my_sync.c MDEV-20685: compile fixes for Solaris/OSX/AIX 2020-04-29 12:02:47 +03:00
my_thr_init.c cleanup THR_KEY_mysys 2020-04-25 00:55:39 +03:00
my_timer_cycles.il Update FSF Address 2019-05-11 21:29:06 +03:00
my_uuid.c Merge branch '5.5' into 10.1 2019-05-11 19:15:57 +03:00
my_wincond.c Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
my_windac.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
my_winerr.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
my_winfile.c Update FSF Address 2019-05-11 21:29:06 +03:00
my_winthread.c Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
my_write.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
mysys_priv.h Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
psi_noop.c Fix GCC 11 -Wmaybe-uninitialized for PLUGIN_PERFSCHEMA 2021-08-30 11:52:59 +03:00
ptr_cmp.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
queues.c Merge branch '5.5' into 10.1 2020-04-30 17:36:41 +02:00
safemalloc.c Safemalloc typo fix found by clang. 2021-10-26 15:05:13 +02:00
stacktrace.c Merge 10.1 into 10.2 2020-08-20 06:00:36 +03:00
string.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
test_charset.c Update FSF Address 2019-05-11 21:29:06 +03:00
test_dir.c Update FSF Address 2019-05-11 21:29:06 +03:00
test_thr_mutex.c Update FSF address 2019-05-10 20:52:00 +03:00
test_xml.c Update FSF Address 2019-05-11 21:29:06 +03:00
testhash.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
thr_alarm.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
thr_lock.c Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
thr_mutex.c Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
thr_rwlock.c Update FSF Address 2019-05-11 21:29:06 +03:00
thr_timer.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
tree.c Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
typelib.c Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
waiting_threads.c Merge branch '5.5' into 10.1 2019-05-11 19:15:57 +03:00
wqueue.c Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00