Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126696 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id D8AE31A00BC for ; Mon, 10 Mar 2025 16:47:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1741625079; bh=LCE+uvmu3fDoXrc0YpnCjUtHp+g3hUk2BQ6Yk6egiYM=; h=Date:From:To:In-Reply-To:References:Subject:From; b=bzbMi2IBM7VFO/IEoTvjc2C2M7tf91PID48S7mhZ2mWAWaHRrO3/Sx4ANOi1+wHrE 7G3OPFM2x8G/zfQS6Dj7KB5/wh2AHSsf0J2KlZTsxjwBs01Z8SpLDgocAxNyFVa3sw EeeVnUlACGQNBlqUZ0bFFY18BxJ0zvp6UMZ6xD4nIF+JuIvU2AtdFl4LqpzPriigSL lDktZVYjOei/xPitUtEB6J7VdV4egSqbHwkJj6sBkUI2gSDm5TIqrQqMg1dO/7J1fX w5G2wl43HFQVfdEjPZepB5xcVgFgbWpPjgdHaUl8ZxbsHgMAinggpDLrQP1PqMUkgM 9s/9Z1PVO8hbQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 42887180032 for ; Mon, 10 Mar 2025 16:44:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fhigh-b8-smtp.messagingengine.com (fhigh-b8-smtp.messagingengine.com [202.12.124.159]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 10 Mar 2025 16:44:28 +0000 (UTC) Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfhigh.stl.internal (Postfix) with ESMTP id 978DC254012F for ; Mon, 10 Mar 2025 12:47:01 -0400 (EDT) Received: from phl-imap-09 ([10.202.2.99]) by phl-compute-11.internal (MEProxy); Mon, 10 Mar 2025 12:47:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1741625221; x=1741711621; bh=LCE+uvmu3f DoXrc0YpnCjUtHp+g3hUk2BQ6Yk6egiYM=; b=HFousF3Vrl4hhBlpt9kpBEXgPG eOQgYLbiPnTPgaAyPVg0OQg4wSc5Z1vMINhBzhTeRKmkyKJ8cNoHFEziQ0RmLWp4 bDCOuMC1HUUWLNkkBHQ/0xtLqjEoyAx85rLPQey8946Cf+tEk1wYJLRyWvhUzpwN thps5gRCcgYr/NHLFgd8v32KnCJx/rVVZdHLRT7A/A+PO0l/F3kLbm0uejNGrjXK sdbj4lr+3vDYFlD/lJ4d7wFAXP85LWipuqwhZqZFoYsiJzXDUJ19eFE3bCTJma97 oMIyGTvhq15/4VBt/maO5oWx1qjgBtZcIPl/yZXy7PCiL/eoNyupxBRGd0CQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1741625221; x=1741711621; bh=LCE+uvmu3fDoXrc0YpnCjUtHp+g3hUk2BQ6 Yk6egiYM=; b=WNhVg+PekblP+MdMS8FCm8pIXZlnu/iraifDk35k+5o3Y8N8VoA Xb1eSCOTEX01KcuZGys9MgEI2ST8KL/AlJtDBjuYPcOQp9utqArWrpjQQZ0EcSK2 xD3KbBQ/YYa0ukXage/FZa0FXWVQ2pWsDKVQw3gZvS3Yp7DJS/L1PejCPPsmQA8X t9TtzDiGh/GXslSZ09IxYUnupFlhTZkNXeglKiBt9Mu0JUtqYiL58H88niJbUtj0 406d5rR0qJQoKNIyhIbDtZyoIr6LnpED+s0QljprqvbDUkwIfw+Kq3QhIiciajPa Uef3eB/voe8NqpxhgXYCCaT8riUsZdFv2kQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduudelkeeiucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefogg ffhffvkfgjfhfutgesrgdtreerredtjeenucfhrhhomhepfdftohgsucfnrghnuggvrhhs fdcuoehrohgssegsohhtthhlvggurdgtohguvghsqeenucggtffrrghtthgvrhhnpedtue ejtdethfeulefhtdelieduteelffdtudelheffgedtieehhfelieejgfevgeenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehrohgssegsohhtth hlvggurdgtohguvghspdhnsggprhgtphhtthhopedupdhmohguvgepshhmthhpohhuthdp rhgtphhtthhopehinhhtvghrnhgrlhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 1A383780067; Mon, 10 Mar 2025 12:47:01 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Mon, 10 Mar 2025 17:46:40 +0100 To: internals@lists.php.net Message-ID: <2d7ad0d5-8455-442e-a1d4-07580f1a6d7d@app.fastmail.com> In-Reply-To: References: <9548e5df-1cd3-4097-8961-7a087b21839f@app.fastmail.com> Subject: Re: [PHP-DEV] OPcache should zero out cache slots? Content-Type: multipart/alternative; boundary=11392d1268854a119a51c82ea14c530b From: rob@bottled.codes ("Rob Landers") --11392d1268854a119a51c82ea14c530b Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Mon, Mar 10, 2025, at 15:43, Ilija Tovilo wrote: > Hi Rob >=20 > On Mon, Mar 10, 2025 at 9:23=E2=80=AFAM Rob Landers wrote: > > > > I=E2=80=99ve been trying to chase down a very subtle bug in 8.4 that= only happens when OPcache is enabled (I'm trying to create a reproducer= to file an actual bug). From what I can tell, OPcache doesn=E2=80=99t z= ero out cache slots, so occasionally, a cache slot will contain garbage = that happens to pass asserts/checks that causes the program to behave in= correctly. Without OPcache, cache slots are always NULL if not set. > > > > It's quite rare to end up in that situation, though, but I was wonde= ring if anyone has any opinions on this? >=20 > I don't believe this is accurate. If we're talking about the cache > used within the VM, "cache slots" are a contiguous list of arbitrary > void pointers. The compiler tracks how many cache slots each function > needs, but the actual array of pointers is allocated at runtime, in > init_func_run_time_cache_i(), when the function is executed for the > first time on each request. init_func_run_time_cache_i() zeros the > cache with memset. If it wouldn't, we'd run into issues quickly, > because a non-0 cache is generally interpreted as a primed cache. >=20 > Potentially, you might also be referring to the pointer map, which is > a related concept. But this map is also zero'ed for each request (in > zend_activate()). >=20 > If you think you might be dealing with uninitialized memory in your > case, MemorySanitizer or Valgrind may help. >=20 > Does that help? >=20 > Ilija >=20 Thanks Ilija, You are correct! This issue appears to be an "off-by-one" type error, so= the data in the cache slot is just something unexpected, which looks li= ke garbage. I think I finally found the issue, maybe... in zend_compile_= static_call where the logic to determine the number of cache slots is di= fferent from the logic to set the cache slots. At least, that is where I= am at right now. But that you for your help! =E2=80=94 Rob --11392d1268854a119a51c82ea14c530b Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Mon, Mar 10,= 2025, at 15:43, Ilija Tovilo wrote:
Hi Rob

On Mon, Ma= r 10, 2025 at 9:23=E2=80=AFAM Rob Landers <rob@bottled.codes> wrote:
>
=
> I=E2=80=99ve been trying to chase down a very subtle bug in 8.= 4 that only happens when OPcache is enabled (I'm trying to create a repr= oducer to file an actual bug). From what I can tell, OPcache doesn=E2=80= =99t zero out cache slots, so occasionally, a cache slot will contain ga= rbage that happens to pass asserts/checks that causes the program to beh= ave incorrectly. Without OPcache, cache slots are always NULL if not set= .
>
> It's quite rare to end up in tha= t situation, though, but I was wondering if anyone has any opinions on t= his?

I don't believe this is accurate. If w= e're talking about the cache
used within the VM, "cache sl= ots" are a contiguous list of arbitrary
void pointers. The= compiler tracks how many cache slots each function
needs,= but the actual array of pointers is allocated at runtime, in
<= div>init_func_run_time_cache_i(), when the function is executed for the<= br>
first time on each request. init_func_run_time_cache_i() z= eros the
cache with memset. If it wouldn't, we'd run into = issues quickly,
because a non-0 cache is generally interpr= eted as a primed cache.

Potentially, you mi= ght also be referring to the pointer map, which is
a relat= ed concept. But this map is also zero'ed for each request (in
<= div>zend_activate()).

If you think you migh= t be dealing with uninitialized memory in your
case, Memor= ySanitizer or Valgrind may help.

Does that = help?

Ilija


Thanks Ilija,

You are correct! This issue appears to be an "off-by-one" type error, = so the data in the cache slot is just something unexpected, which looks = like garbage. I think I finally found the issue, maybe... in zend_c= ompile_static_call where the logic to determine the number of cache slot= s is different from the logic to set the cache slots. At least, that is = where I am at right now. But that you for your help!

<= /div>
=E2=80=94 Rob
--11392d1268854a119a51c82ea14c530b--