From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Gerd =?UTF-8?Q?M=C3=B6llmann?= Newsgroups: gmane.emacs.bugs Subject: bug#56108: 29.0.50; ASAN use-after-free in re_match_2_internal Date: Wed, 22 Jun 2022 16:10:23 +0200 Message-ID: <6e56407a-b564-4aa9-b74c-78883727ef09@Spark> References: <83mte7kv7c.fsf@gnu.org> <32e548cc-ffd3-4669-ad9a-317c130b0c93@Spark> <83a6a4kec0.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="62b322d8_3f06ecb2_588f" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15425"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 56108@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jun 22 16:11:15 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 1o414c-0003pw-Uy for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 22 Jun 2022 16:11:15 +0200 Original-Received: from localhost ([::1]:34824 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o414b-0003Qr-Hz for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 22 Jun 2022 10:11:13 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54758) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o414R-0003QN-59 for bug-gnu-emacs@gnu.org; Wed, 22 Jun 2022 10:11:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:42302) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o414Q-0002rP-TN for bug-gnu-emacs@gnu.org; Wed, 22 Jun 2022 10:11:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1o414Q-0002ID-PK for bug-gnu-emacs@gnu.org; Wed, 22 Jun 2022 10:11:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Gerd =?UTF-8?Q?M=C3=B6llmann?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 22 Jun 2022 14:11: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.16559070448769 (code B ref 56108); Wed, 22 Jun 2022 14:11:02 +0000 Original-Received: (at 56108) by debbugs.gnu.org; 22 Jun 2022 14:10:44 +0000 Original-Received: from localhost ([127.0.0.1]:36194 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o4147-0002HL-UV for submit@debbugs.gnu.org; Wed, 22 Jun 2022 10:10:44 -0400 Original-Received: from mail-ed1-f44.google.com ([209.85.208.44]:47078) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o4142-0002H6-OE for 56108@debbugs.gnu.org; Wed, 22 Jun 2022 10:10:42 -0400 Original-Received: by mail-ed1-f44.google.com with SMTP id z7so24066182edm.13 for <56108@debbugs.gnu.org>; Wed, 22 Jun 2022 07:10:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:message-id:in-reply-to:references:subject :mime-version; bh=jZeLY5Zc4fkBqZr8ECOHyxDBwl4Y8PV4kw4i/cDn7kw=; b=XW+QS5SeLrjl6tKfNJhIc++965g5xKG59h/T6LgY+F89BVHyr54LiPlZP21xmkG+y/ L++HWWKJxAs9Qk58CkGdz6aL7gU478BXsyTfa9kV8APRdb/XifINhNla7pICD3CfagVp X/EEJrjhiI8KI3n9mKqmzyOZhIpgHRrt2+gK/8ulBSG9VrlEuejPEBMICEwPJOwqwVXt yhBW+ozsy8QqZBzbmG9o54MGyButGIw4dqt916HoxM3BiaC1XWkPmyFR1K9C4IALmp1i hEF2fw+uGPngv2UKnz27IZYkIhboi6UDBpdeuTmvN/jbzmX/SmAbhQfsnFDVfM4HitUr G9Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:message-id:in-reply-to :references:subject:mime-version; bh=jZeLY5Zc4fkBqZr8ECOHyxDBwl4Y8PV4kw4i/cDn7kw=; b=h7TjPNvQcqv3GMcT00gHV8DkKk7ZP7ILpBsuhK4nGCJjt9hLzK5mK9j5stZyBwNAgy 4vGj+rdbl88CIwCXTUZPgnWCdcfPto7/+J00iyH/9/8Y/vUXyQVrE3l7Jgb508Q0sqlY +ntt5rKckVlkdJqW7+VswYEwWYNE/LKyNjo6INKOsffWe5bSyXo8ZSYZrKFBCzsqTQIN vzoNxKKr6p0gEfzF6tSpQff6X0gP+rdzkccBr9065nmpaywn+eRqjh8Sql19U6U9SpEk g4hGLmA6NBYD4wilnYaIv4tedpKUfIPWbAAC0G/gbzYvreOGu8OHsDAij+O2ALMt8Ya3 jqTA== X-Gm-Message-State: AJIora+QS4MWzj4Uz9uKv4kAFmQ9FbxXULhbOHpId9HKM/mKrypMl+0m nko1jeYmC4fkNBr6zKhthA0= X-Google-Smtp-Source: AGRyM1uJXXs0x4jRSLRiJ0hnsAskY12NSL/bBpxMUFNowN0Lb2kr2n76dOvyxNtTNRmv8vkJRxdiKw== X-Received: by 2002:a05:6402:14c4:b0:435:717a:fd63 with SMTP id f4-20020a05640214c400b00435717afd63mr4460293edx.395.1655907032735; Wed, 22 Jun 2022 07:10:32 -0700 (PDT) Original-Received: from [192.168.178.21] (pd9e3676b.dip0.t-ipconnect.de. [217.227.103.107]) by smtp.gmail.com with ESMTPSA id se14-20020a170906ce4e00b00722e3760558sm2805911ejb.100.2022.06.22.07.10.32 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Jun 2022 07:10:32 -0700 (PDT) In-Reply-To: <83a6a4kec0.fsf@gnu.org> X-Readdle-Message-ID: 6e56407a-b564-4aa9-b74c-78883727ef09@Spark 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:235025 Archived-At: --62b322d8_3f06ecb2_588f Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 22. Jun 2022, 15:39 +0200, Eli Zaretskii , wrote: > > Date: Wed, 22 Jun 2022 10:13:08 +0200 > > =46rom: Gerd M=C3=B6llmann > > Cc: 56108=40debbugs.gnu.org > > > > On 20. Jun 2022, 21:10 +0200, Eli Zaretskii , wrote: > > > > I don't understand why some callers of compile=5Fpattern mark the cac= he > > entry as busy, but some others don't. If a cache entry that is in use= > > is not marked as busy, then any GC can decide to shrink the cache by > > freeing that entry. > > > > struct re=5Fpattern=5Fbuffer *bufp; > > ... > > bufp =3D &compile=5Fpattern (regexp, > > ... > > > > The address operator is there to confuse the Russians. > > > > Hmm... did you mean by that to explain why some callers of > > compile=5Fpattern don't mark the new cache entry as =22busy=22=3F Bec= ause if > > so, I guess I'm one of the =22confused Russians=22, as I don't unders= tand > > the explanation. Please elaborate. > > Sorry, looking at this again, I'm now also completely confused. I see, all in search.c: static struct regexp=5Fcache * compile=5Fpattern (Lisp=5FObject pattern, struct re=5Fregisters *regp, and then, later struct re=5Fpattern=5Fbuffer *bufp; bufp =3D &compile=5Fpattern How the heck does this compile=3F > > > > Or maybe =5FI=5F should elaborate. By =22marking an entry busy=22 I m= eant the > > call to freeze=5Fpattern, Yes, I've seen that. > > not a call to freeze=5Fbuffer=5Frelocation (the > > latter is mostly a no-op nowadays, as almost all the supported > > platforms don't use ralloc.c). So it isn't the C pointer we keep > > around to compile=5Fpattern's result that bothered me, it's the fact > > that the pattern cache entry created by compile=5Fpattern is not > > protected from being freed by shrink=5Fregexp=5Fcache that is called = by > > GC. A=46AIU, that entry must be protected for the whole time the > > compiled pattern is in use by re=5Fmatch=5F2 or any of its callers. > > > > Does the above make sense=3F Yes, it's the same I see. =46unctions fast=5Fstring=5Fmatch=5Finternal* don't freeze in the sense y= ou explained.=C2=A0=C2=A0What I don't see so far is what could lead to a = GC in these cases, between the compile=5Fpattern and the use of its resul= t... Did you find other places where there's no freeze=3F Can Emacs GC while handling a signal=3F Does Emacs use threads nowadays=3F --62b322d8_3f06ecb2_588f Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
On 22. Jun 2022, 15:39 +0200, Eli Zaretskii <eli= z=40gnu.org>, wrote:
Date: Wed, 22 Jun 2022 10:13:08 +0200
=46rom: Gerd M=C3=B6llmann <gerd.moellmann=40gmail.com>
Cc: 56108=40debbugs.gnu.org

On 20. Jun 2022, 21:10 +0200, Eli Zaretskii <eliz=40gnu.org>, wrote= :

I don't understand why some callers of compile=5Fpattern mark the cache entry as busy, but some others don't. If a cache entry that is in use
is not marked as busy, then any GC can decide to shrink the cache by
freeing that entry.

struct re=5Fpattern=5Fbuffer *bufp;
...
bufp =3D &compile=5Fpattern (regexp,
...

The address operator is there to confuse the Russians.

Hmm... did you mean by that to explain why some callers of
compile=5Fpattern don't mark the new cache entry as =22busy=22=3F Because= if
so, I guess I'm one of the =22confused Russians=22, as I don't understand=
the explanation. Please elaborate.

Sorry, looking at this again, I'm now also complete= ly confused.&=23160;&=23160;

I see, all in search.c:

static struct regexp=5Fcache *
compile=5Fpattern (Lisp=5FObject pat= tern, struct re=5Fregisters *regp,

and then, later

struct re=5Fpattern=5Fbuffer *bufp;<= /span>
bufp =3D &compile=5Fpattern

How the heck does this compile=3F&=23160;

Or maybe =5FI=5F should elaborate. By =22marking an entry busy=22 I meant= the
call to freeze=5Fpattern,&=23160;
Yes, I've seen that.
not a call to freeze=5Fbuffer=5Frelocation (the
latter is mostly a no-op nowadays, as almost all the supported
platforms don't use ralloc.c). So it isn't the C pointer we keep
around to compile=5Fpattern's result that bothered me, it's the fact
that the pattern cache entry created by compile=5Fpattern is not
protected from being freed by shrink=5Fregexp=5Fcache that is called by GC. A=46AIU, that entry must be protected for the whole time the
compiled pattern is in use by re=5Fmatch=5F2 or any of its callers.
=
Does the above make sense=3F

Yes, it's the same I see.&=23160;&=23160;

=46unctions fast=5Fstring=5Fmatch=5Finternal* don't freeze in the sense y= ou explained.&=23160;&=23160;What I don't see so far is what could lead t= o a GC in these cases, between the compile=5Fpattern and the use of its r= esult...

Did you find other places where there's no freeze=3F
Can Emacs GC while handling a signal=3F
Does Emacs use threads nowadays=3F
--62b322d8_3f06ecb2_588f--