public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: "Ananthakrishna Sowda (asowda)" <asowda@cisco.com>
To: Simon Marchi <simon.marchi@polymtl.ca>,
	"gdb@sourceware.org" <gdb@sourceware.org>
Subject: Re: GDB abort on glibc detected file descriptor overflow
Date: Fri, 3 Sep 2021 19:26:12 +0000	[thread overview]
Message-ID: <BY5PR11MB441822E46AD8DA28D727CF4CCFCF9@BY5PR11MB4418.namprd11.prod.outlook.com> (raw)
In-Reply-To: <ea8ba0b4-8682-ba23-414a-94bbd7aa711b@polymtl.ca>

I looked in /proc/<pid>/fd for Gdb process and I see 1535 files open. Most of them are pointing to libfoo.so and libfoo.so.debug , where libfoo.so is a library loaded by the process which crashed and generated a core-file. Normally, these file descriptors are re-used and maximum number of open file descriptors stays around 150, even for a process which could load several hundreds of .so libraries.


From: Simon Marchi <simon.marchi@polymtl.ca>
Date: Wednesday, September 1, 2021 at 6:05 PM
To: Ananthakrishna Sowda (asowda) <asowda@cisco.com>, gdb@sourceware.org <gdb@sourceware.org>
Subject: Re: GDB abort on glibc detected file descriptor overflow


On 2021-09-01 6:37 p.m., Ananthakrishna Sowda (asowda) via Gdb wrote:
> I’m observing abort in GDB 9.2.1 version, and same issue is present in git://sourceware.org/git/binutils-gdb.git tip.
>
> The full call trace is shown at the end of this message.
> In frame 7,  call to FD_SET is causing buffer overflow when commands from a GDB macro file are processed.
>
> (gdb) frame 7
> #7  0x000000000076978b in gdb_readline_no_editing (prompt=<optimized out>) at /auto/swtools/prod-builds/src/gdb-9.2.1/gdb/gdb/top.c:850
> 850               FD_SET (fd, &readfds);
> (gdb) p fd
> $1 = 1533
>
> GDB is processing split dwarf  “.dwp” file for the main executable and processing some “.dwo” files in the workspace, which may have something to do with it.  GDB is opening a bunch of .debug files , one each for every  library  and the open file descriptors  go  past 1024.  This results in buffer overflow when gdb.macros file is opened and processed in frame 7 ( file descriptor 1533).
>
> The bfd file descriptor caching code which tries to limit no of open descriptors is not effective in this case.
> Does this explanation make  sense? Any ideas to fix this issue are greatly appreciated.

It won't fix the problem, but I think we could start by adding an
assertion before calling FD_SET (everywhere where we do call it):

  gdb_assert (fd < FD_SETSIZE);

Your build happened to catch it, but other builds could just fail
silently or crash in less clear ways.

As for the solution, maybe this code should be converted to use poll or
other more modern APIs to avoid this limit?

It would be interesting if you could show what are the open file
descriptors at this point (list /proc/<pid>/fd), just to see what uses
the most fds.

Simon

      reply	other threads:[~2021-09-03 19:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-01 22:37 Ananthakrishna Sowda (asowda)
2021-09-02  1:05 ` Simon Marchi
2021-09-03 19:26   ` Ananthakrishna Sowda (asowda) [this message]

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=BY5PR11MB441822E46AD8DA28D727CF4CCFCF9@BY5PR11MB4418.namprd11.prod.outlook.com \
    --to=asowda@cisco.com \
    --cc=gdb@sourceware.org \
    --cc=simon.marchi@polymtl.ca \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).