public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
From: "Wendeborn, Jonathan" <Jonathan.Wendeborn@bruker.com>
To: Florian Weimer <fw@deneb.enyo.de>,
	"Wendeborn, Jonathan via Libc-help" <libc-help@sourceware.org>,
	Konstantin Kharlamov <hi-angel@yandex.ru>
Subject: AW: dlopen: Segfault due to overwriting .so file after it was loaded and loading it again
Date: Fri, 20 Nov 2020 12:45:19 +0000	[thread overview]
Message-ID: <c22f96ef84c54b1da2d2b8a6e416d5ad@bruexc101.brumgt.local> (raw)
In-Reply-To: <87lfewl0ue.fsf@mid.deneb.enyo.de>

[-- Attachment #1: Type: text/plain, Size: 1422 bytes --]

Hi Florian,

Thank you, that sounds reasonable. Indeed the library is marked NODELETE due to unique symbols. Is it forbidden in general to write executables which are loaded?

I attached the outputs of strace and LD_DEBUG=all if you're interested.

Thanks!
Jonathan 

-----Ursprüngliche Nachricht-----
Von: Florian Weimer <fw@deneb.enyo.de> 
Gesendet: Freitag, 20. November 2020 12:33
An: Wendeborn, Jonathan via Libc-help <libc-help@sourceware.org>
Cc: Wendeborn, Jonathan <Jonathan.Wendeborn@bruker.com>
Betreff: Re: dlopen: Segfault due to overwriting .so file after it was loaded and loading it again

**EXTERNAL EMAIL**

* Jonathan via Libc-help Wendeborn:

> The destructor ~shared_library() calls dlclose(), but I suspect the 
> library stays loaded. Overwriting the file creates a new file node and 
> my program wants to load the same library again (at the same location 
> but with a different file node/handle).

This crash happens if the file is truncated on disk and rewritten.
All mapped data is reset to zero if that happens and relocations are gone.  The kernel does that, there is nothing that glibc can do about it (Linux does not support MAP_COPY).

So you have two issues here: The library stays loaded (maybe it is marked as NODELETE, LD_DEBUG=all output logs that in recent glibc versions), and the file is rewritten in place (and not a “new file node” is created).

[-- Attachment #2: output.tar.gz --]
[-- Type: application/x-gzip, Size: 253917 bytes --]

  reply	other threads:[~2020-11-20 12:45 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-20  6:52 Wendeborn, Jonathan
2020-11-20  7:17 ` Konstantin Kharlamov
2020-11-20  8:01   ` AW: " Wendeborn, Jonathan
2020-11-20  8:15     ` Konstantin Kharlamov
2020-11-20  9:47       ` AW: " Wendeborn, Jonathan
2020-11-20 10:20         ` Konstantin Kharlamov
2020-11-20 11:33 ` Florian Weimer
2020-11-20 12:45   ` Wendeborn, Jonathan [this message]
2020-11-20 12:48     ` AW: " Florian Weimer
2020-11-20 12:59       ` AW: " Wendeborn, Jonathan
2020-12-04 10:39 Wendeborn, Jonathan
2020-12-04 10:44 ` AW: " Wendeborn, Jonathan

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=c22f96ef84c54b1da2d2b8a6e416d5ad@bruexc101.brumgt.local \
    --to=jonathan.wendeborn@bruker.com \
    --cc=fw@deneb.enyo.de \
    --cc=hi-angel@yandex.ru \
    --cc=libc-help@sourceware.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).