public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Ingo Molnar <mingo@kernel.org>
Cc: Josh Poimboeuf <jpoimboe@kernel.org>,
	x86@kernel.org, linux-kernel@vger.kernel.org,
	Nathan Chancellor <nathan@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Alexandre Chartre <alexandre.chartre@oracle.com>
Subject: Re: [PATCH] objtool: Fix stack overflow in validate_branch()
Date: Tue, 2 Dec 2025 22:05:40 +0000	[thread overview]
Message-ID: <20251202220540.5849bdc6@pumpkin> (raw)
In-Reply-To: <aS9KJ-gQ59Wv_H00@gmail.com>

On Tue, 2 Dec 2025 21:20:55 +0100
Ingo Molnar <mingo@kernel.org> wrote:

> * Josh Poimboeuf <jpoimboe@kernel.org> wrote:
> 
> > On Tue, Dec 02, 2025 at 09:11:50AM -0800, Josh Poimboeuf wrote:  
> > > > > > That's weird - how can a user-space tool run into stack 
> > > > > > limits, are they set particularly conservatively?  
> > > > > 
> > > > > On my Fedora system, "ulimit -s" is 8MB.  You'd think that would be
> > > > > enough :-)
> > > > > 
> > > > > In this case, objtool had over 20,000 stack frames caused by recursively
> > > > > following over 7,000(!) conditional jumps in a single function.  
> > > > 
> > > > Ouch ...
> > > > 
> > > > ... which means that very likely we'll run into this problem again. :-/
> > > > 
> > > > Time to add stack overflow self-detection?
> > > > 
> > > > I've attached a simple proof-of-concept that uses 
> > > > sigaltstacks based SIGSEGV handler to catch a stack 
> > > > overflow:
> > > > 
> > > >   starship:/s/stack-overflow> ./overflow 
> > > >   # Starting stack recursion:
> > > > 
> > > >   # WARNING: SIGSEGV received: Possible stack overflow detected!
> > > > 
> > > >   starship:/s/stack-overflow> 
> > > > 
> > > > Could we add something like this to objtool, with 
> > > > perhaps a look at the interrupted stack pointer from 
> > > > SIGSEGV_handler(), to make sure the SIGSEGV was due to 
> > > > a stack overflow?  
> > > 
> > > Yes, I think that would be wise.  I've been thinking objtool could use a
> > > SIGSEGV handler anyway, as it crashes more often than one would hope,
> > > with a cryptic non-helpful error message for the user.
> > > 
> > > I'll work on it.  
> > 
> > Is something like the below sufficient?  Or do you think we should add
> > logic to distinguish the stack overflow from other crashes?
> > 
> > ---8<---
> > 
> > From: Josh Poimboeuf <jpoimboe@kernel.org>
> > Subject: [PATCH] objtool: Improve error message for SIGSEGV
> > 
> > When the kernel build fails due to an objtool seg fault, the error
> > message is confusing:
> > 
> >   make[5]: *** [scripts/Makefile.build:503: drivers/scsi/qla2xxx/qla2xxx.o] Error 139
> >   make[5]: *** Deleting file 'drivers/scsi/qla2xxx/qla2xxx.o'
> >   make[4]: *** [scripts/Makefile.build:556: drivers/scsi/qla2xxx] Error 2
> >   make[3]: *** [scripts/Makefile.build:556: drivers/scsi] Error 2
> >   make[2]: *** [scripts/Makefile.build:556: drivers] Error 2
> >   make[1]: *** [/home/jpoimboe/git/linux/Makefile:2013: .] Error 2
> >   make: *** [Makefile:248: __sub-make] Error 2
> > 
> > Add a signal handler which prints an error message like:
> > 
> >   drivers/scsi/qla2xxx/qla2xxx.o: error: objtool: SIGSEGV (Segmentation Fault) received at address 0x7ffc5f33bf30
> > 
> > ... and re-raises the signal so the core dump still gets triggered.  
> 
> Could we somehow determine that 0x7ffc5f33bf30 is off 
> the end of the stack or so and that this is a stack 
> overflow?

You could compare it to the address of something on-stack during program startup.
Probably even argv[] - isn't that always at the bottom of the stack?
If you read the rlimit value, maybe the recursive loop could abort
before the fault.

	David

> 
> Maybe objtool could have a look into /proc/self/maps:
> 
>    7fc21a543000-7fc21a544000 rw-p 0003f000 103:02 96610309                  /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
>    7fc21a544000-7fc21a545000 rw-p 00000000 00:00 0 
>    7ffd6a5a0000-7ffd6a5c1000 rw-p 00000000 00:00 0                          [stack]
> 
> ?
> 
> Thanks,
> 
> 	Ingo
> 


  reply	other threads:[~2025-12-02 22:05 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-02 16:16 [PATCH] objtool: Fix stack overflow in validate_branch() Josh Poimboeuf
2025-12-02 16:20 ` Ingo Molnar
2025-12-02 16:49   ` Josh Poimboeuf
2025-12-02 17:03     ` Ingo Molnar
2025-12-02 17:11       ` Josh Poimboeuf
2025-12-02 19:56         ` Josh Poimboeuf
2025-12-02 20:20           ` Ingo Molnar
2025-12-02 22:05             ` David Laight [this message]
2025-12-02 23:01               ` Josh Poimboeuf
2025-12-03 11:02                 ` David Laight
2025-12-03 16:11                 ` Ingo Molnar
2025-12-03 16:40                 ` [tip: objtool/urgent] objtool: Add more robust signal error handling, detect and warn about stack overflows tip-bot2 for Josh Poimboeuf
2025-12-03 18:48                 ` tip-bot2 for Josh Poimboeuf
2025-12-03  9:25     ` [PATCH] objtool: Fix stack overflow in validate_branch() Ingo Molnar
2025-12-03 18:54       ` Josh Poimboeuf
2025-12-03 18:58         ` Josh Poimboeuf
2025-12-03 19:15           ` Ingo Molnar
2025-12-03 19:37             ` David Laight
2025-12-03 20:30               ` Linus Torvalds
2025-12-03 23:53             ` Josh Poimboeuf
2025-12-03 19:11         ` Ingo Molnar
2025-12-04  2:47           ` Josh Poimboeuf
2025-12-02 16:27 ` [tip: objtool/urgent] " tip-bot2 for Josh Poimboeuf
2025-12-02 16:28 ` [PATCH] " Josh Poimboeuf
2025-12-02 16:41   ` Ingo Molnar
2025-12-02 16:44 ` [tip: objtool/urgent] " tip-bot2 for Josh Poimboeuf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251202220540.5849bdc6@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=alexandre.chartre@oracle.com \
    --cc=jpoimboe@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=nathan@kernel.org \
    --cc=peterz@infradead.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox