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: Wed, 22 Jun 2022 16:38:55 +0300 Message-ID: <83a6a4kec0.fsf@gnu.org> References: <83mte7kv7c.fsf@gnu.org> <32e548cc-ffd3-4669-ad9a-317c130b0c93@Spark> 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="15529"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 56108@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 Wed Jun 22 15:40:13 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 1o40ab-0003r6-88 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 22 Jun 2022 15:40:13 +0200 Original-Received: from localhost ([::1]:34832 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o40aY-0007i8-Ju for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 22 Jun 2022 09:40:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47464) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o40aR-0007i0-1J for bug-gnu-emacs@gnu.org; Wed, 22 Jun 2022 09:40:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:40529) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o40aQ-00063d-OO for bug-gnu-emacs@gnu.org; Wed, 22 Jun 2022 09:40:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1o40aQ-00011I-JW for bug-gnu-emacs@gnu.org; Wed, 22 Jun 2022 09:40: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: Wed, 22 Jun 2022 13:40: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.16559051543864 (code B ref 56108); Wed, 22 Jun 2022 13:40:02 +0000 Original-Received: (at 56108) by debbugs.gnu.org; 22 Jun 2022 13:39:14 +0000 Original-Received: from localhost ([127.0.0.1]:34426 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o40Zd-00010G-PN for submit@debbugs.gnu.org; Wed, 22 Jun 2022 09:39:14 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:34140) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o40Zc-0000zy-4r for 56108@debbugs.gnu.org; Wed, 22 Jun 2022 09:39:12 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:41922) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o40ZW-0005n4-Pa; Wed, 22 Jun 2022 09:39:06 -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=96Z1vFDEqW5oQvAm4tUdYfL483SNmY0dDceZSSL7oeU=; b=ZOVICD3pccZ0JpMQgOcC 0fBZRsnbJb/ujU9Xh3dQvJbzVor6346VgVQm01m3jCYfXHTz7sGda2+kHOfR9GTcM97FgdvSUhcfB rQrNsRPGmrCPUvYiDAx6zogulCoOsh1MYN8+jEl/aJp04/+zrhdK6oTsRuKnn1JmuBMbcTfVQgmkj 3XpidvkwsKpDCeOLrDpuTR1Urj2uyy5OH6iz6jdnh9aHyrzqmrBfM3ADTh047ULZKND0XOiCQOI4Q XFFuASR0S3ye4onXAPgJ0DUR32AlM9ClP03AOkM7IZhknIfK3GQzKlorcS/ZcF84rNZYZcoae+LBe WDugvMW+jaLeAw==; Original-Received: from [87.69.77.57] (port=2606 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 1o40ZU-0003Uj-Pw; Wed, 22 Jun 2022 09:39:06 -0400 In-Reply-To: <32e548cc-ffd3-4669-ad9a-317c130b0c93@Spark> (message from Gerd =?UTF-8?Q?M=C3=B6llmann?= on Wed, 22 Jun 2022 10:13:08 +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:235019 Archived-At: > Date: Wed, 22 Jun 2022 10:13:08 +0200 > From: Gerd Möllmann > Cc: 56108@debbugs.gnu.org > > On 20. Jun 2022, 21:10 +0200, Eli Zaretskii , wrote: > > I don't understand why some callers of compile_pattern 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_pattern_buffer *bufp; > ... > bufp = &compile_pattern (regexp, > ... > > The address operator is there to confuse the Russians. Hmm... did you mean by that to explain why some callers of compile_pattern don't mark the new cache entry as "busy"? Because if so, I guess I'm one of the "confused Russians", as I don't understand the explanation. Please elaborate. Or maybe _I_ should elaborate. By "marking an entry busy" I meant the call to freeze_pattern, not a call to freeze_buffer_relocation (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_pattern's result that bothered me, it's the fact that the pattern cache entry created by compile_pattern is not protected from being freed by shrink_regexp_cache that is called by GC. AFAIU, that entry must be protected for the whole time the compiled pattern is in use by re_match_2 or any of its callers. Does the above make sense?