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#56108: 29.0.50; ASAN use-after-free in re_match_2_internal Date: Fri, 24 Jun 2022 08:55:54 +0300 Message-ID: <83tu8ad2qd.fsf@gnu.org> References: <83mte7kv7c.fsf@gnu.org> <32e548cc-ffd3-4669-ad9a-317c130b0c93@Spark> <83a6a4kec0.fsf@gnu.org> <6e56407a-b564-4aa9-b74c-78883727ef09@Spark> <831qvgkc8d.fsf@gnu.org> <83sfnwisbb.fsf@gnu.org> <3146c990-63d9-4aa5-ab78-7bae2b7d6cd5@Spark> <835ykrg93i.fsf@gnu.org> <831qvfg876.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18612"; mail-complaints-to="usenet@ciao.gmane.io" Cc: gerd.moellmann@gmail.com, 56108@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jun 24 07:57:10 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 1o4cJa-0004fz-9Y for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 24 Jun 2022 07:57:10 +0200 Original-Received: from localhost ([::1]:45990 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4cJY-00023a-DD for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 24 Jun 2022 01:57:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55546) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4cJS-00023S-Sr for bug-gnu-emacs@gnu.org; Fri, 24 Jun 2022 01:57:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:46665) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o4cJS-0004Lh-JG for bug-gnu-emacs@gnu.org; Fri, 24 Jun 2022 01:57:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1o4cJS-0005r6-H5 for bug-gnu-emacs@gnu.org; Fri, 24 Jun 2022 01:57: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: Fri, 24 Jun 2022 05:57:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 56108 X-GNU-PR-Package: emacs Original-Received: via spool by 56108-submit@debbugs.gnu.org id=B56108.165605017722456 (code B ref 56108); Fri, 24 Jun 2022 05:57:02 +0000 Original-Received: (at 56108) by debbugs.gnu.org; 24 Jun 2022 05:56:17 +0000 Original-Received: from localhost ([127.0.0.1]:40562 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o4cIi-0005q8-P6 for submit@debbugs.gnu.org; Fri, 24 Jun 2022 01:56:17 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:42288) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o4cIg-0005pu-LP for 56108@debbugs.gnu.org; Fri, 24 Jun 2022 01:56:15 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:55980) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4cIa-0004D0-N9; Fri, 24 Jun 2022 01:56:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=4ExJM4FKR5la+asSBzhGuZ7X0wH0dPvLFvP7R66XEao=; b=HsqZxcMxQzRF IPNQt9VOgKGz9DLLEknoWHus5OJ1LC5kQJZNkJxbOdKGjcqLghBbCiV3+gXWsxar5ktm45w2go5Lo TS+VnQVfzqiUGeIFu4aJxQHZsAkr0CCURwHjR6YPVsUSXYqgqWzghjFG/9lQmfSYGqZRxz/XlKlXv PkqM1QX+mtY5taYvAQ/0CJ6Gv4Ocj4ZWXXm0aM/jbWKTlIAWIorO06hG/Q+ypNslgYFmAy6qiqxLc eKhJB4LX+FtzemECFRLzsVMV+89h48psIMug2enxerDopiGOxwANvHJQlunUVFYQH49y8tuGJTbzD agBsDFQpZgapjlIadCEghg==; Original-Received: from [87.69.77.57] (port=3001 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 1o4cIT-0001ZM-6w; Fri, 24 Jun 2022 01:56:06 -0400 In-Reply-To: (message from Stefan Monnier on Thu, 23 Jun 2022 17:29:13 -0400) 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:235150 Archived-At: > From: Stefan Monnier > Cc: gerd.moellmann@gmail.com, 56108@debbugs.gnu.org > Date: Thu, 23 Jun 2022 17:29:13 -0400 > > Before `freeze_pattern`, the design was that nothing could happen while > running the regexp matcher (no GC, no execution of Lisp code). > > Commit 938d252d1c6c5e2027aa250c649deb024154f936 changed that so that > searching inside a *buffer* could end up running ELisp code (and hence > also GC). AFAIK this still can't happen when searching in strings. > [ IIRC The need to run ELisp is so as to apply `syntax-table` text > properties on demand via `syntax-propertize`. ] > > So I think freeze_pattern should be used in all cases where > `compile_pattern` is used to search inside a buffer, but it shouldn't be > necessary when searching within a string. I think at least the scenario uncovered by Gerd, shown in this backtrace-like form: > maybe_gc > Ffuncall > call2 > signal_or_quit (eval.c:1741) > quit (eval.c:1697) > process_quit_flag (eval.c:1657) > probably_quit (eval.c:1864) > maybe_quit (lisp.h:3681) > re_match_2_internal (regexp-emacs.c:4691) could happen even when searching within strings. And in general, as I tried to explain up-thread, relying on what cannot happen _today_ wrt GC is not future-proof, the way Emacs development advances. So I think we should install a change that calls freeze_pattern for every pattern-cache entry as long as it is in use. Gerd, would you please show the patch for that?