unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Gerd Möllmann" <gerd.moellmann@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 58042@debbugs.gnu.org
Subject: bug#58042: 29.0.50; ASAN use-after-free in re_match_2_internal
Date: Sat, 24 Sep 2022 17:08:12 +0200	[thread overview]
Message-ID: <m25yhcq083.fsf@Mini.fritz.box> (raw)
In-Reply-To: <835yhcom6g.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 24 Sep 2022 17:56:55 +0300")

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Gerd Möllmann <gerd.moellmann@gmail.com>
>> Date: Sat, 24 Sep 2022 16:17:20 +0200
>> 
>> Gerd Möllmann <gerd.moellmann@gmail.com> writes:
>> 
>> > ==79227==ERROR: AddressSanitizer: heap-use-after-free on address
>> > 0x00011f81e7d1 at pc 0x0001005825c4 bp 0x00016fdcf370 sp
>> > 0x00016fdcf368
>> > READ of size 1 at 0x00011f81e7d1 thread T0
>> >     #0 0x1005825c0 in re_match_2_internal regex-emacs.c:4352
>> >     #1 0x10057e5cc in rpl_re_search_2 regex-emacs.c:3383
>> >     #2 0x10057d1c4 in rpl_re_search regex-emacs.c:3177
>> >     #3 0x10056115c in fast_string_match_internal search.c:492
>> >     #4 0x1005045c0 in fast_string_match lisp.h:4818
>> >     #5 0x100504018 in Ffind_file_name_handler fileio.c:324
>> >     #6 0x1006dbe5c in openp lread.c:1911
>> >     #7 0x1006d8844 in Fload lread.c:1302
>> >     #8 0x1006e1af0 in save_match_data_load lread.c:1630
>> >     #9 0x10064f8cc in load_with_autoload_queue eval.c:2269
>> >     #10 0x10067d2f8 in Frequire fns.c:3274
>> 
>> Forget to copy the part where it is freed:
>> 
>> freed by thread T0 here:
>>     #0 0x103332de4 in wrap_free+0x98 (libclang_rt.asan_osx_dynamic.dylib:arm64e+0x3ede4)
>>     #1 0x100985e38 in rpl_free free.c:48
>>     #2 0x1005b71a4 in lisp_free alloc.c:1038
>>     #3 0x1005cbda4 in compact_small_strings alloc.c:2191
>>     #4 0x1005c9f24 in sweep_strings alloc.c:2072
>>     #5 0x1005bd028 in gc_sweep alloc.c:7397
>>     #6 0x1005bb178 in garbage_collect alloc.c:6245
>>     #7 0x1005ba694 in maybe_garbage_collect alloc.c:6090
>>     #8 0x1006505ac in maybe_gc lisp.h:5624
>>     #9 0x100648ffc in Ffuncall eval.c:2972
>>     #10 0x10064bcd0 in internal_condition_case_n eval.c:1555
>>     #11 0x1000cdc8c in safe__call xdisp.c:3026
>>     #12 0x1000cdfc4 in safe__call1 xdisp.c:3062
>>     #13 0x1001d6404 in prepare_menu_bars xdisp.c:13572
>>     #14 0x1000f2340 in redisplay_internal xdisp.c:16523
>>     #15 0x100108f34 in redisplay xdisp.c:16105
>>     #16 0x10088fa84 in -[EmacsView layoutSublayersOfLayer:] nsterm.m:8662
>>     #17 0x1900a9624 in CA::Layer::layout_if_needed(CA::Transaction*)+0x224 (QuartzCore:arm64e+0x20624)
>>     #18 0x1901f661c in
>> CA::Context::commit_transaction(CA::Transaction*, double,
>> double*)+0x1c0 (QuartzCore:arm64e+0x16d61c)
>>     #19 0x19008b4c8 in CA::Transaction::commit()+0x2bc (QuartzCore:arm64e+0x24c8)
>>     #20 0x18bee1698 in __62+[CATransaction(NSCATransaction)
>> NS_setFlushesWithDisplayLink]_block_invoke+0x12c
>> (AppKit:arm64e+0x1ac698)
>>     #21 0x18c646754 in ___NSRunLoopObserverCreateWithHandler_block_invoke+0x3c (AppKit:arm64e+0x911754)
>>     #22 0x1892101a0 in
>> __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__+0x20
>> (CoreFoundation:arm64e+0x841a0)
>>     #23 0x18920fff0 in __CFRunLoopDoObservers+0x24c (CoreFoundation:arm64e+0x83ff0)
>>     #24 0x18920f524 in __CFRunLoopRun+0x300 (CoreFoundation:arm64e+0x83524)
>>     #25 0x18920ea80 in CFRunLoopRunSpecific+0x254 (CoreFoundation:arm64e+0x82a80)
>>     #26 0x191e4e334 in RunCurrentEventLoopInMode+0x120 (HIToolbox:arm64e+0x32334)
>>     #27 0x191e4dfc0 in ReceiveNextEventCommon+0x140 (HIToolbox:arm64e+0x31fc0)
>>     #28 0x191e4de64 in _BlockUntilNextEventMatchingListInModeWithFilter+0x44 (HIToolbox:arm64e+0x31e64)
>>     #29 0x18bd76518 in _DPSNextEvent+0x358 (AppKit:arm64e+0x41518)
>
> So it was freed by GC, which probably relocated string data or
> something.  But I don't understand the relation between these two
> backtraces: was the one that accessed a freed string called by the one
> which triggered GC?  IOW, what is the relation between the call to
> 'require', which ended up calling re_match_2_internal, and the call to
> prepare_menu_bars, which triggered GC?

I don't understand that part either.

> re_search gets Lisp strings as its arguments, so unless GC was called
> while the regexp search was in progress, I cannot understand how this
> could happen.

Right, that's what I also think.  See also my other mail.

> Is there any way to know which argument of re_match_2_internal was
> used to access the free'd heap?

I can't figure it out from the code, and LLDB got the segmentation
fault, so I can't look.  Maybe Stefan can figure that out.

But in general, I think the small string compaction could be a serious
problem here, as soon as a GC happens while the regexp machine holds
pointers.





  reply	other threads:[~2022-09-24 15:08 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-24 13:45 bug#58042: 29.0.50; ASAN use-after-free in re_match_2_internal Gerd Möllmann
2022-09-24 14:17 ` Gerd Möllmann
2022-09-24 14:48   ` Gerd Möllmann
2022-09-24 14:56   ` Eli Zaretskii
2022-09-24 15:08     ` Gerd Möllmann [this message]
2022-09-24 15:24       ` Eli Zaretskii
2022-09-25  5:50         ` Gerd Möllmann
2022-09-25  6:32           ` Eli Zaretskii
2022-09-25  7:06             ` Gerd Möllmann
2022-09-25  8:08               ` Eli Zaretskii
2022-09-25  8:28                 ` Gerd Möllmann
2022-09-25  8:43                   ` Eli Zaretskii
2022-09-26  5:13                     ` Gerd Möllmann
2022-10-04 14:33 ` Gerd Möllmann
2022-10-04 16:35   ` Eli Zaretskii
2022-10-05  4:37     ` Gerd Möllmann
2022-10-05  6:16       ` Eli Zaretskii
2022-10-05  6:58         ` Gerd Möllmann
2022-10-05  7:22           ` Eli Zaretskii
2022-10-05  7:34             ` Gerd Möllmann
2022-10-05  9:00               ` Gerd Möllmann
2022-10-05  9:23                 ` Eli Zaretskii
2022-10-05 10:14                   ` Gerd Möllmann
2022-10-05 10:24                     ` Gerd Möllmann
2022-10-05 10:43                       ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-05 10:49                         ` Gerd Möllmann
2022-10-05 11:10                           ` Gerd Möllmann
2022-10-05 11:15                             ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-05 11:37                               ` Gerd Möllmann
2022-10-05 13:37                               ` Eli Zaretskii
2022-10-05 13:52                                 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-05 14:09                                   ` Eli Zaretskii
2022-10-05 14:24                                     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-05 13:27                             ` Eli Zaretskii
2022-10-05 13:31                               ` Gerd Möllmann
2022-10-05 13:55                                 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-08 14:01                         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-09  1:04                           ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-09  2:25                             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-09  5:30                             ` Eli Zaretskii
2022-10-05 10:45                       ` Gerd Möllmann
2022-10-05 11:10                         ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-05 11:15                           ` Gerd Möllmann
2022-10-05 11:23                             ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-05 11:35                               ` Gerd Möllmann
2022-10-05 12:02                               ` Gerd Möllmann
2022-10-05 12:08                                 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-05 13:40                               ` Eli Zaretskii
2022-10-05 13:53                                 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-05 14:10                                   ` Eli Zaretskii
2022-10-05 12:05                             ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-05 12:32                               ` Gerd Möllmann
2022-10-05 12:38                                 ` Gerd Möllmann
2022-10-05 12:49                                   ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-05 12:48                                 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-06  5:20                                   ` Gerd Möllmann
2022-10-05 13:39                           ` Eli Zaretskii
2022-10-05 13:13                         ` Eli Zaretskii
2022-10-05 13:24                           ` Gerd Möllmann
2022-10-05 12:59                     ` Eli Zaretskii
2022-10-06  5:35 ` Gerd Möllmann
2022-10-06  6:59   ` Eli Zaretskii
2022-10-06  7:21     ` Gerd Möllmann
2022-10-06  8:08       ` Eli Zaretskii
2022-10-06  8:23         ` Gerd Möllmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m25yhcq083.fsf@Mini.fritz.box \
    --to=gerd.moellmann@gmail.com \
    --cc=58042@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).