Skip to content

Commit

Permalink
Fix libunwind segfaults from JIT frames on FreeBSD (#42970)
Browse files Browse the repository at this point in the history
This adds libunwind PR 308 as a patch and updates LibUnwind_jll to use a
version with that patch included.

(cherry picked from commit 96a99c2)
  • Loading branch information
ararslan authored and KristofferC committed Nov 10, 2021
1 parent 40b53d3 commit 6a0cc34
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 26 deletions.
2 changes: 1 addition & 1 deletion deps/Versions.make
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ SUITESPARSE_JLL_NAME := SuiteSparse
# unwind
UNWIND_VER := 1.3.2
UNWIND_JLL_NAME := LibUnwind
UNWIND_JLL_VER := 1.3.2+4
UNWIND_JLL_VER := 1.3.2+6

# zlib
ZLIB_VER := 1.2.11
Expand Down
48 changes: 24 additions & 24 deletions deps/checksums/unwind
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
LibOSXUnwind.v0.0.6+1.x86_64-apple-darwin.tar.gz/md5/fd98df2005d13aa16341c5aecba1af70
LibOSXUnwind.v0.0.6+1.x86_64-apple-darwin.tar.gz/sha512/2d2263c3e5f095ad9eba7fea7cb882a19fece8a10486489d0a15b8e81ea0f8626804c4822b8c92a26a608d568c0ff1a4e976ea6d746be47ac1a70891455162a6
LibUnwind.v1.3.2+4.aarch64-linux-gnu.tar.gz/md5/8f5cbf9820033211513f6d33e36194f1
LibUnwind.v1.3.2+4.aarch64-linux-gnu.tar.gz/sha512/589886c4f141064126aecc1bf63365c610a4c3dd70e386aa8e17ce562505cac873542fa92cea023850e9bf54fcef3cf475d52f035d17d830a81c01d06d0454e4
LibUnwind.v1.3.2+4.aarch64-linux-musl.tar.gz/md5/836a2d8ea7a11d87a74aee09f82582b5
LibUnwind.v1.3.2+4.aarch64-linux-musl.tar.gz/sha512/4cd3805ae59854fdceee441967ba4b812246cf1a1e9ed20367f5bbbad9a47f0093731b4f78f881c696e52c101dec83498398c7b798c81c1a441232cd4ee96b58
LibUnwind.v1.3.2+4.armv6l-linux-gnueabihf.tar.gz/md5/0047d02c4b4888050b363c77106d4ea1
LibUnwind.v1.3.2+4.armv6l-linux-gnueabihf.tar.gz/sha512/8b02fb5189ca749e421fc17d560601e8624cbcc19a4c5c45e38828323b33db30ced8a92e08ebd429c663e52358c486d3e284e7e04898229cff2839cc01c067d5
LibUnwind.v1.3.2+4.armv6l-linux-musleabihf.tar.gz/md5/1fe78c6f0ff7120b35c6745b16c6f838
LibUnwind.v1.3.2+4.armv6l-linux-musleabihf.tar.gz/sha512/9576f913fbc40d00b42573f600c038fea85eb3c9b88a4878cff0e041c4096d9d005b856dbcd0d057dc40a3cdb74deeca6e9c1cc5c213e6e062328f75633ba8e3
LibUnwind.v1.3.2+4.armv7l-linux-gnueabihf.tar.gz/md5/510db51b0364cf17207eb00e44d58974
LibUnwind.v1.3.2+4.armv7l-linux-gnueabihf.tar.gz/sha512/76f119654a65b460917f41a321008c5a0593523db53fa12ac9aa82732368ebdee05d6366fdfdcdd300ba0fe4c7239aac25d80fb3b1ad0235f79b235dab68c796
LibUnwind.v1.3.2+4.armv7l-linux-musleabihf.tar.gz/md5/4bb58bdc423312c74eafe52a781dd712
LibUnwind.v1.3.2+4.armv7l-linux-musleabihf.tar.gz/sha512/02b69ec40dfcacc447169786bab3aac39c6db6b07874e9657c49a2907654be79efe16863abf09ee1e2a647cd6a651155b65bdbbd6d810a3ceaa332fc0a3ace4b
LibUnwind.v1.3.2+4.i686-linux-gnu.tar.gz/md5/76f549ae171aad91570d7874e73f44f6
LibUnwind.v1.3.2+4.i686-linux-gnu.tar.gz/sha512/a5a654dd6233099e841d1b9c54b16cb99d736549d063e28d17d5f2014c3090d829a4a8dc4fee042d0f4a9d8a155fb30c5840cb84b9fd71758256fa072137baad
LibUnwind.v1.3.2+4.i686-linux-musl.tar.gz/md5/f8b58f061a03f24111f39f2f8cf72c61
LibUnwind.v1.3.2+4.i686-linux-musl.tar.gz/sha512/cc6dedc551ee4d5e131cdd7ea7dd4a9cc64efe930d16cddb0c21dca7b13076b6810e00e406acb949404c80b506ca9e09d1e223069d8159e9f73fa8aa022e3f41
LibUnwind.v1.3.2+4.powerpc64le-linux-gnu.tar.gz/md5/2fd4fda3c82c99ff102b630d078723f5
LibUnwind.v1.3.2+4.powerpc64le-linux-gnu.tar.gz/sha512/b1c7f16d2877e08cfc9d1aa63c5c9acf30049bd11bdad90c6b1425a09f86762c76f0c1a27817ea1b939244f6e24320854552bc860c95f297a772403eeddc053d
LibUnwind.v1.3.2+4.x86_64-linux-gnu.tar.gz/md5/cd98359922fddcbbcfda56fbc011bea4
LibUnwind.v1.3.2+4.x86_64-linux-gnu.tar.gz/sha512/7b2d78869be148db23ab8372bb6699abcf26cc58718871f050b8e67054c0c6c909f9a8c59d27c748abeef0ecb5eabc09484043c3b2232469d03c78a42a590e13
LibUnwind.v1.3.2+4.x86_64-linux-musl.tar.gz/md5/bd8ea5006d6078a1d91743f599f37732
LibUnwind.v1.3.2+4.x86_64-linux-musl.tar.gz/sha512/1c7feea46d70c60dbecfe6b945a29a086dc120e0d674ea9d488dc7943901711ba0505288694c94a2b0804bab6cd826b32e58912e407ed918724d16b6b6ec1d3d
LibUnwind.v1.3.2+4.x86_64-unknown-freebsd.tar.gz/md5/e72c36f0563a088282147275de90048b
LibUnwind.v1.3.2+4.x86_64-unknown-freebsd.tar.gz/sha512/3aaa7e5c21b3bcc30ff7826af4bc0b926865cac3a5b14dfa7f27f0c5d4344fa2a568a78c0c4ee32a18e668758cdac70c09f31f5ca55cc56c3d6a88654aa906fa
LibUnwind.v1.3.2+6.aarch64-linux-gnu.tar.gz/md5/dcd327c5b3d7b2ba082f2ad7f11939d3
LibUnwind.v1.3.2+6.aarch64-linux-gnu.tar.gz/sha512/fffedf6df127538dff7cd394b4a780862fded082c7299e5ac36dc682dcd28a35db596c4621e94d9dce8483fb8053c6d0030a25b7a4bbbecc39af3efd3af14ab3
LibUnwind.v1.3.2+6.aarch64-linux-musl.tar.gz/md5/d1582fc675158d3838f4d36214e51105
LibUnwind.v1.3.2+6.aarch64-linux-musl.tar.gz/sha512/0636bfc0159b66d6427ae3437be3989930b6d404f94b2ffac92bd9115d87a5509a9bddc723f0c38b7c30ba2098da48c92a74b4648d6361dbebf547ccc4139813
LibUnwind.v1.3.2+6.armv6l-linux-gnueabihf.tar.gz/md5/3e621439132504c14daae4944fb5eab8
LibUnwind.v1.3.2+6.armv6l-linux-gnueabihf.tar.gz/sha512/d324018841343873b256df9684b51fdc9108d5b1af73f5275cd2e81d31a4c00917027afac1554b0cdc5bffd5d52a6417612d3f9399bedfb6a49100df594709f4
LibUnwind.v1.3.2+6.armv6l-linux-musleabihf.tar.gz/md5/4603961011230cf0ef8c24881d7add7a
LibUnwind.v1.3.2+6.armv6l-linux-musleabihf.tar.gz/sha512/64e87f9074cb51442539a7907c979424682dc5a9a4cf4d538fbdc5f3bcba169c9b4d5aeb445c76060c0b0604d3fb5b0b88dbc7d3d919a4153c403d9c39110115
LibUnwind.v1.3.2+6.armv7l-linux-gnueabihf.tar.gz/md5/2c8c2ca6b238bfdbd1c4d021df7ac7a6
LibUnwind.v1.3.2+6.armv7l-linux-gnueabihf.tar.gz/sha512/b665d8d6b5de0b4a23f2577fe12208c4921f7ee6c3643f1434732c3c5203d1892d86f84875e3488cfc85efb250ceb0c66d02f2356e0accb3c24f200c936eeb84
LibUnwind.v1.3.2+6.armv7l-linux-musleabihf.tar.gz/md5/0f786d4baf3d5f4fc94884ad7ae1b74b
LibUnwind.v1.3.2+6.armv7l-linux-musleabihf.tar.gz/sha512/1e4c447983d3aee05705b90962f0bbccd58f255b1d7b582069408d8927d21697fdeefea3aeb7ad84d7d087a70417164194d60c66e57bbb3a587845bbf636c06d
LibUnwind.v1.3.2+6.i686-linux-gnu.tar.gz/md5/d022d2a6a88ccf741c19889055132882
LibUnwind.v1.3.2+6.i686-linux-gnu.tar.gz/sha512/75615cba1b4e945cd5969fd4debf7edd3913d5ae3819abf8ca724b0f1ece8f03064dcd2fde54d14d052f7e3e15bcb0efa5c7d9b55c4875e7dedee38034038b7f
LibUnwind.v1.3.2+6.i686-linux-musl.tar.gz/md5/5e57a072a0c683005921db5597f43d64
LibUnwind.v1.3.2+6.i686-linux-musl.tar.gz/sha512/4bbaac240ef37ed48d1273cb68302e1b856622804f7704917a3db2a213118a9e0bd95ca504555a537aeec7f5baa2057cf93ca62e350a64b428a34770e64602a6
LibUnwind.v1.3.2+6.powerpc64le-linux-gnu.tar.gz/md5/1ee397961af5567c37b5429d7b7a52cd
LibUnwind.v1.3.2+6.powerpc64le-linux-gnu.tar.gz/sha512/902017d1c64d00a67a378d0e7aef64493655a88480d27a5f720cac363bbd0aeab2f03f2b77560fae395a5799ae3da1f4122b6e8cda8d80f158c751215a1848bb
LibUnwind.v1.3.2+6.x86_64-linux-gnu.tar.gz/md5/e45a0c38c35ed4afbdcffe385998e6d3
LibUnwind.v1.3.2+6.x86_64-linux-gnu.tar.gz/sha512/049ac0d6b74fbc6a96a7abe345b4ec783968a90bd0f3c230558ad9b3a44cbe65cf4553bfc9abdc9128529d746077308570a14f55317ffef5f65836a8413aa938
LibUnwind.v1.3.2+6.x86_64-linux-musl.tar.gz/md5/77f053b93396484f3e4d37af9a294ad6
LibUnwind.v1.3.2+6.x86_64-linux-musl.tar.gz/sha512/e87406503348d316940ea28f09b304c9349f3915e1ed193c87b823b7c5c7a1f6046e6b0e5eeba3b4760d5a403def5f87aa42a3f5f4d8c5f540dd4fba3743394b
LibUnwind.v1.3.2+6.x86_64-unknown-freebsd.tar.gz/md5/33c56decf549b45712642ebc73b622bd
LibUnwind.v1.3.2+6.x86_64-unknown-freebsd.tar.gz/sha512/ffb3866b2ccd3ddea168b7ce0b345d475914fa4f87a3743b92e3c07ac9453b4ad929ff01596677e00f08d4d30cf67676052cc3c4f985f722a800b82cba8334c3
36 changes: 36 additions & 0 deletions deps/patches/libunwind-dwarf-table.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
From a5b5fd28ed03cb1ab524d24dc534c1fa167bf5a1 Mon Sep 17 00:00:00 2001
From: Alex Arslan <ararslan@comcast.net>
Date: Fri, 5 Nov 2021 16:58:41 -0700
Subject: [PATCH] Fix table indexing in `dwarf_search_unwind_table`

`table_len` is used as an index into `table`, assuming it represents the
number of entries. However, it is defined as the number of entries
multiplied by `sizeof(unw_word_t)`. This is accounted for in other
places that use `table_len`, e.g. in `lookup`, which divides out the
size of `unw_word_t`, but the indexing expression uses `table_len`
directly. So when `table` has say 2 entries, we're actually looking at
index 15 rather than 1 in the comparison. This can cause the conditional
to erroneously evaluate to true, allowing the following line to
segfault.

This was observed with JIT compiled code from Julia with LLVM on
FreeBSD.

Co-Authored-By: Jameson Nash <vtjnash@gmail.com>
---
src/dwarf/Gfind_proc_info-lsb.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/dwarf/Gfind_proc_info-lsb.c b/src/dwarf/Gfind_proc_info-lsb.c
index 5e27a501..af4cbce8 100644
--- a/src/dwarf/Gfind_proc_info-lsb.c
+++ b/src/dwarf/Gfind_proc_info-lsb.c
@@ -866,7 +866,7 @@ dwarf_search_unwind_table (unw_addr_space_t as, unw_word_t ip,
if (as == unw_local_addr_space)
{
e = lookup (table, table_len, ip - ip_base);
- if (e && &e[1] < &table[table_len])
+ if (e && &e[1] < &table[table_len / sizeof (unw_word_t)])
last_ip = e[1].start_ip_offset + ip_base;
else
last_ip = di->end_ip;
6 changes: 5 additions & 1 deletion deps/unwind.mk
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ $(SRCCACHE)/libunwind-$(UNWIND_VER)/libunwind-cfa-rsp.patch-applied: $(SRCCACHE)
cd $(SRCCACHE)/libunwind-$(UNWIND_VER) && patch -p1 -f -u < $(SRCDIR)/patches/libunwind-cfa-rsp.patch
echo 1 > $@

$(BUILDDIR)/libunwind-$(UNWIND_VER)/build-configured: $(SRCCACHE)/libunwind-$(UNWIND_VER)/source-extracted $(SRCCACHE)/libunwind-$(UNWIND_VER)/libunwind-cfa-rsp.patch-applied
$(SRCCACHE)/libunwind-$(UNWIND_VER)/libunwind-dwarf-table.patch-applied: $(SRCCACHE)/libunwind-$(UNWIND_VER)/libunwind-cfa-rsp.patch-applied
cd $(SRCCACHE)/libunwind-$(UNWIND_VER) && patch -p1 -f -u -l < $(SRCDIR)/patches/libunwind-dwarf-table.patch
echo 1 > $@

$(BUILDDIR)/libunwind-$(UNWIND_VER)/build-configured: $(SRCCACHE)/libunwind-$(UNWIND_VER)/source-extracted $(SRCCACHE)/libunwind-$(UNWIND_VER)/libunwind-dwarf-table.patch-applied
mkdir -p $(dir $@)
cd $(dir $@) && \
$(dir $<)/configure $(CONFIGURE_COMMON) CPPFLAGS="$(CPPFLAGS) $(LIBUNWIND_CPPFLAGS)" CFLAGS="$(CFLAGS) $(LIBUNWIND_CFLAGS)" --disable-shared --disable-minidebuginfo --disable-tests
Expand Down

0 comments on commit 6a0cc34

Please sign in to comment.