From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#58042: 29.0.50; ASAN use-after-free in re_match_2_internal Date: Sun, 25 Sep 2022 09:32:46 +0300 Message-ID: <83mtaom0a9.fsf@gnu.org> References: <835yhcom6g.fsf@gnu.org> <831qs0okx4.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35202"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 58042@debbugs.gnu.org To: Gerd =?UTF-8?Q?M=C3=B6llmann?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Sep 25 08:34:14 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ocLDR-0008zf-Mw for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 25 Sep 2022 08:34:13 +0200 Original-Received: from localhost ([::1]:34174 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ocLDQ-0004XJ-LQ for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 25 Sep 2022 02:34:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58194) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ocLDH-0004XA-0K for bug-gnu-emacs@gnu.org; Sun, 25 Sep 2022 02:34:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:46646) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ocLDG-0007GM-Mz for bug-gnu-emacs@gnu.org; Sun, 25 Sep 2022 02:34:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ocLDG-0000Y4-HM for bug-gnu-emacs@gnu.org; Sun, 25 Sep 2022 02:34:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 25 Sep 2022 06:34:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58042 X-GNU-PR-Package: emacs Original-Received: via spool by 58042-submit@debbugs.gnu.org id=B58042.16640875862036 (code B ref 58042); Sun, 25 Sep 2022 06:34:02 +0000 Original-Received: (at 58042) by debbugs.gnu.org; 25 Sep 2022 06:33:06 +0000 Original-Received: from localhost ([127.0.0.1]:45724 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ocLCM-0000Wl-Br for submit@debbugs.gnu.org; Sun, 25 Sep 2022 02:33:06 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:46152) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ocLCK-0000WF-HJ for 58042@debbugs.gnu.org; Sun, 25 Sep 2022 02:33:05 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:49072) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ocLCF-00079U-BV; Sun, 25 Sep 2022 02:32:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=PeO/Q5ZFH+Yg8dNpWuZXZ+XAVElDQE7JbVE7k1JVzmI=; b=W/In5Dt+H0bQ2J2APzw4 PAmbQ5sqkEqSW1PgzJ7O7lCwOlTBuRga9ThMqDlC1IY8TbiVfP2wxIxZthrDH/wzY2/fH/Q6+V9eQ uzhwYbzS2sbhK8NOpf34tqiVFn3MPv3tOs5jldFckxTz9922gCNBiMTrC+EXD/UvtOcCqn7K+cQ/z b755Z+XKlzoTT7ek2RyaT0taL2uNOAuYUwHOTTWlrA82SmjqD4hoUN07s9qDTp7NcjWuSo0vNsf6H s8FNff1tuoEIor1Z05ha+em9ZzO7CfBFh+pTDorld4z0j9t06RiASei2FVCpkDfyYWPTMSIa1is0p s83XCPfRBRXATQ==; Original-Received: from [87.69.77.57] (port=4811 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ocLCE-0007n1-5H; Sun, 25 Sep 2022 02:32:58 -0400 In-Reply-To: (message from Gerd =?UTF-8?Q?M=C3=B6llmann?= on Sun, 25 Sep 2022 07:50:17 +0200) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:243569 Archived-At: > From: Gerd Möllmann > Cc: 58042@debbugs.gnu.org > Date: Sun, 25 Sep 2022 07:50:17 +0200 > > > The GC was triggered by > > redisplay, but how did redisplay start while regexp match was in > > progress? Do you see any code in regexp that could trigger redisplay? > > I'm afraid, I don't follow. Why do you think redisplay comes into play > here? Because of this part of your message in https://debbugs.gnu.org/cgi/bugreport.cgi?bug=58042#8: 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 AFAIU, this says that the GC which freed the string data was caused by safe__call1 inside prepare_menu_bars, which was called from redisplay_internal. > Anyways, my working hypotheses currently goes like this: > > We match using some Lisp string S and get its data pointer, say D. > Since D is not null, S must be a live string. > > (Actually I didn't check that this is still the case, but I think I've > been setting s.data to null for free strings right from the start, and I > can't imagine why anyone would change that.) > > Between the point we get D, and the point of the crash, a GC happens. > We know in principle that a GC can happen while matching since > bug#56108. I'm taking that as a given. The GC compacts strings and > changes S's data pointer. > > After GC, S.data != D. Yes, but I have difficulty with the fact that GC was caused by redisplay, and redisplay cannot be invoked while we are in re_match_2_internal, AFAIK. So something else is missing here (or maybe I'm misinterpreting the ASAN report you posted).