GNU bug report logs - #21004
25.0.50; Questionable call to getrlimit in handle_sigsegv

Previous Next

Package: emacs;

Reported by: Ken Brown <kbrown <at> cornell.edu>

Date: Tue, 7 Jul 2015 20:13:02 UTC

Severity: normal

Tags: patch

Found in version 25.0.50

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 21004 in the body.
You can then email your comments to 21004 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#21004; Package emacs. (Tue, 07 Jul 2015 20:13:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Ken Brown <kbrown <at> cornell.edu>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 07 Jul 2015 20:13:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Ken Brown <kbrown <at> cornell.edu>
To: bug-gnu-emacs <at> gnu.org
Subject: 25.0.50; Questionable call to getrlimit in handle_sigsegv
Date: Tue, 07 Jul 2015 16:11:53 -0400
There is a call to setrlimit in main() that tries to increase the stack
size.  As a result of this, the value of rlim.rlim_cur in
handle_sigsegv() might exceed the actual stack size.  See Corinna
Vinschen's message at

  https://www.cygwin.com/ml/cygwin/2015-07/msg00092.html

for a more detailed explanation.

Corinna suggests using pthread_getattr_np instead of getrlimit to avoid
this problem, as in the following patch:

diff --git a/src/sysdep.c b/src/sysdep.c
index 91036f0..c49e333 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -1625,6 +1625,8 @@ handle_arith_signal (int sig)

#ifdef HAVE_STACK_OVERFLOW_HANDLING

+#include <pthread.h>
+
/* -1 if stack grows down as expected on most OS/ABI variants, 1 
otherwise.  */

static int stack_direction;
@@ -1642,9 +1644,11 @@ handle_sigsegv (int sig, siginfo_t *siginfo, void 
*arg)
too nested calls to mark_object.  No way to survive.  */
if (!gc_in_progress)
{
-      struct rlimit rlim;
+      pthread_attr_t attr;
+      size_t stacksize;

-      if (!getrlimit (RLIMIT_STACK, &rlim))
+      if (!pthread_getattr_np (pthread_self (), &attr)
+         && !pthread_attr_getstacksize (&attr, &stacksize))
{
/* STACK_DANGER_ZONE has to be bigger than 16K on Cygwin, for
reasons explained in
@@ -1657,7 +1661,7 @@ handle_sigsegv (int sig, siginfo_t *siginfo, void 
*arg)
char *beg, *end, *addr;

beg = stack_bottom;
-         end = stack_bottom + stack_direction * rlim.rlim_cur;
+         end = stack_bottom + stack_direction * stacksize;
if (beg > end)
addr = beg, beg = end, end = addr;
addr = (char *) siginfo->si_addr;

Of course, the definition of HAVE_STACK_OVERFLOW_HANDLING would have to
be changed to ensure that pthread_getattr_np exists.

In GNU Emacs 25.0.50.17 (x86_64-unknown-cygwin, GTK+ Version 3.14.13)
 of 2015-07-07 on moufang
Repository revision: 0bfc94047da4960af55196242728a7a55120867f
Windowing system distributor `The Cygwin/X Project', version 11.0.11701000
Configured using:
 `configure 'CFLAGS=-g3 -O0''

Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND DBUS GSETTINGS NOTIFY ACL
GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS
GTK3 X11

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
Making completion list...

Load-path shadows:
None found.

Features:
(shadow sort gnus-util mail-extr emacsbug message dired format-spec
rfc822 mml mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util help-fns help-mode easymenu cl-loaddefs pcase cl-lib mail-prsvr
mail-utils time-date mule-util tooltip eldoc electric uniquify
ediff-hook vc-hooks lisp-float-type mwheel x-win term/common-win x-dnd
tool-bar dnd fontset image regexp-opt fringe tabulated-list newcomment
elisp-mode lisp-mode prog-mode register page menu-bar rfn-eshadow timer
select scroll-bar mouse jit-lock font-lock syntax facemenu font-core
frame cl-generic cham georgian utf-8-lang misc-lang vietnamese tibetan
thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek romanian
slovak czech european ethiopic indian cyrillic chinese charscript
case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer
cl-preloaded nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote dbusbind gfilenotify
dynamic-setting system-font-setting font-render-setting move-toolbar gtk
x-toolkit x multi-tty make-network-process emacs)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21004; Package emacs. (Wed, 08 Jul 2015 13:35:03 GMT) Full text and rfc822 format available.

Message #8 received at 21004 <at> debbugs.gnu.org (full text, mbox):

From: Wolfgang Jenkner <wjenkner <at> inode.at>
To: Ken Brown <kbrown <at> cornell.edu>
Cc: 21004 <at> debbugs.gnu.org
Subject: Re: bug#21004: 25.0.50;
 Questionable call to getrlimit in handle_sigsegv
Date: Wed, 08 Jul 2015 15:33:58 +0200
On Tue, Jul 07 2015, Ken Brown wrote:

> Of course, the definition of HAVE_STACK_OVERFLOW_HANDLING would have to
> be changed to ensure that pthread_getattr_np exists.

Other systems may have this under a different name (e.g., FreeBSD has
pthread_attr_get_np and needs to include pthread_np.h).  By the way,
Guile has already some code to deal with this.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21004; Package emacs. (Wed, 08 Jul 2015 14:22:02 GMT) Full text and rfc822 format available.

Message #11 received at 21004 <at> debbugs.gnu.org (full text, mbox):

From: Ken Brown <kbrown <at> cornell.edu>
To: Wolfgang Jenkner <wjenkner <at> inode.at>
Cc: Dmitry Antipov <dmantipov <at> yandex.ru>, 21004 <at> debbugs.gnu.org
Subject: Re: bug#21004: 25.0.50;
 Questionable call to getrlimit in handle_sigsegv
Date: Wed, 08 Jul 2015 10:20:56 -0400
On 7/8/2015 9:33 AM, Wolfgang Jenkner wrote:
> On Tue, Jul 07 2015, Ken Brown wrote:
>
>> Of course, the definition of HAVE_STACK_OVERFLOW_HANDLING would have to
>> be changed to ensure that pthread_getattr_np exists.
>
> Other systems may have this under a different name (e.g., FreeBSD has
> pthread_attr_get_np and needs to include pthread_np.h).  By the way,
> Guile has already some code to deal with this.

So someone (Dmitry?) would have to do some work to make this more 
portable.  It may or may not be worth the trouble; I'm not even sure yet 
that recovery from stack overflow actually works (see bug#20996).

Ken





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21004; Package emacs. (Thu, 16 Jul 2015 07:59:02 GMT) Full text and rfc822 format available.

Message #14 received at 21004 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Ken Brown <kbrown <at> cornell.edu>
Cc: Corinna Vinschen <corinna-cygwin <at> cygwin.com>, Eli Zaretskii <eliz <at> gnu.org>,
 Wolfgang Jenkner <wjenkner <at> inode.at>, Dmitry Antipov <dmantipov <at> yandex.ru>,
 21004 <at> debbugs.gnu.org
Subject: Re: 25.0.50; Questionable call to getrlimit in handle_sigsegv
Date: Thu, 16 Jul 2015 00:58:10 -0700
[Message part 1 (text/plain, inline)]
Ken, thanks for reporting the problem in <http://bugs.gnu.org/21004>.  Please 
try the attached patch.  Although it avoids getrlimit and it works for me on 
both GNU/Linux and Solaris, I can't easily test it on Cygwin.  I'll CC: this to 
Eli as a heads-up, as he's interested in the MS-Windows case.
[0001-Better-heuristic-for-C-stack-overflow.patch (text/x-diff, attachment)]

Added tag(s) patch. Request was from Paul Eggert <eggert <at> cs.ucla.edu> to control <at> debbugs.gnu.org. (Thu, 16 Jul 2015 08:31:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21004; Package emacs. (Thu, 16 Jul 2015 12:17:02 GMT) Full text and rfc822 format available.

Message #19 received at 21004 <at> debbugs.gnu.org (full text, mbox):

From: Ken Brown <kbrown <at> cornell.edu>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: Corinna Vinschen <corinna-cygwin <at> cygwin.com>, Eli Zaretskii <eliz <at> gnu.org>,
 Wolfgang Jenkner <wjenkner <at> inode.at>, Dmitry Antipov <dmantipov <at> yandex.ru>,
 21004 <at> debbugs.gnu.org
Subject: Re: 25.0.50; Questionable call to getrlimit in handle_sigsegv
Date: Thu, 16 Jul 2015 08:15:45 -0400
On 7/16/2015 3:58 AM, Paul Eggert wrote:
> Ken, thanks for reporting the problem in <http://bugs.gnu.org/21004>.  Please
> try the attached patch.  Although it avoids getrlimit and it works for me on
> both GNU/Linux and Solaris, I can't easily test it on Cygwin.  I'll CC: this to
> Eli as a heads-up, as he's interested in the MS-Windows case.

It works on Cygwin.  Thanks.

Ken




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21004; Package emacs. (Thu, 16 Jul 2015 14:35:02 GMT) Full text and rfc822 format available.

Message #22 received at 21004 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: corinna-cygwin <at> cygwin.com, wjenkner <at> inode.at, dmantipov <at> yandex.ru,
 21004 <at> debbugs.gnu.org, kbrown <at> cornell.edu
Subject: Re: 25.0.50; Questionable call to getrlimit in handle_sigsegv
Date: Thu, 16 Jul 2015 17:34:03 +0300
> Date: Thu, 16 Jul 2015 00:58:10 -0700
> From: Paul Eggert <eggert <at> cs.ucla.edu>
> CC: 21004 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>, 
>  Wolfgang Jenkner <wjenkner <at> inode.at>,
>  Dmitry Antipov <dmantipov <at> yandex.ru>, 
>  Corinna Vinschen <corinna-cygwin <at> cygwin.com>
> 
> Ken, thanks for reporting the problem in <http://bugs.gnu.org/21004>.  Please 
> try the attached patch.  Although it avoids getrlimit and it works for me on 
> both GNU/Linux and Solaris, I can't easily test it on Cygwin.  I'll CC: this to 
> Eli as a heads-up, as he's interested in the MS-Windows case.

Thanks.  The native MS-Windows build doesn't (yet) support
stack-overflow recovery, so the affected code is not compiled into
that build.




Reply sent to Paul Eggert <eggert <at> cs.ucla.edu>:
You have taken responsibility. (Thu, 16 Jul 2015 14:39:02 GMT) Full text and rfc822 format available.

Notification sent to Ken Brown <kbrown <at> cornell.edu>:
bug acknowledged by developer. (Thu, 16 Jul 2015 14:39:02 GMT) Full text and rfc822 format available.

Message #27 received at 21004-done <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: wjenkner <at> inode.at, dmantipov <at> yandex.ru, 21004-done <at> debbugs.gnu.org,
 kbrown <at> cornell.edu
Subject: Re: 25.0.50; Questionable call to getrlimit in handle_sigsegv
Date: Thu, 16 Jul 2015 07:38:18 -0700
Thanks, Ken and Eli, for the quick responses.  I've installed the patch as 
master commit a5522abbca2235771384949dfa87c8efc68831b2 and am closing the bug.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 14 Aug 2015 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 9 years and 308 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.