Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108349 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 69968 invoked from network); 3 Feb 2020 16:09:45 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Feb 2020 16:09:45 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A4E141804D1 for ; Mon, 3 Feb 2020 06:21:41 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NEUTRAL autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS20857 149.210.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail.alphaserver.nl (mail.alphaserver.nl [149.210.157.144]) by php-smtp4.php.net (Postfix) with ESMTP for ; Mon, 3 Feb 2020 06:21:41 -0800 (PST) X-Virus-Scanned: amavisd-new at mail.alphaserver.nl Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Date: Mon, 3 Feb 2020 15:16:39 +0100 References: To: PHP internals In-Reply-To: Message-ID: <7270D83F-7C65-4399-9D64-FD54499B2CDC@php.net> X-Mailer: Apple Mail (2.3445.104.11) Subject: Re: [PHP-DEV] VM reentry limit From: ruudboon@php.net (Ruud Boon) > On 3 Feb 2020, at 14:29, Nikita Popov wrote: >=20 > Hi internals, >=20 > We have a long-standing issue (tracked at > https://bugs.php.net/bug.php?id=3D64196 and the very numerous = duplicates) > that certain types of infinite recursion can lead to a stack overflow. > While for us it is easy to diagnose this, end users will only see a > "segmentation fault" and will be unable to correlate this with = infinite > recursion as the root cause. >=20 > To provide some technical context, recursion in PHP usually occurs on = the > virtual machine stack, in which case unbounded recursion is supported, = as > long as the stack size does not exceed your memory limit. However, = some > types of calls (in particular magic methods and certain callbacks) go > through an internal function and have to reenter the virtual machine. = This > uses up space on the C stack and may ultimately result in a stack = overflow. >=20 > I would like to propose the introduction of a zend.vm_reentry_limit = ini > option as a solution to this problem, implemented in > https://github.com/php/php-src/pull/5135. This ini setting will limit = the > number of nested VM reentries that are allowed before an Error is = thrown. >=20 > It should be noted that this is (intentionally) not a general = recursion > limit. Deep recursion can happen legitimately (e.g. during AST = processing) > and it is hard to put a reasonable upper limit on it that both detects > unintentional infinite recursion while allowing legitimate deep = recursion. > The limit implemented here exists specifically to prevent stack = overflows > and give the programmer a more obvious indication of the cause of the > problem. >=20 > Regards, > Nikita >=20 > PS: Some extensions will force all function calls to occur via VM = reentry. > Such extensions should probably either disable the option (by setting = it to > -1), or significantly increase the limit, to avoid false positives. I would love to see this addition, I think it can be really helpful for = a lot of users. Can we add a function to report the number of VM reentries as well = (get_vm_reentry_count). This could be helpful for determining a = reasonable ini value. Cheers, Ruud