public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Stas Sergeev via Libc-alpha <libc-alpha@sourceware.org>
Cc: Stas Sergeev <stsp2@yandex.ru>
Subject: Re: [PATCH 2/2] dlfcn,elf: implement dlmem() function [BZ #11767]
Date: Mon, 13 Feb 2023 14:45:43 +0100	[thread overview]
Message-ID: <87y1p1d6go.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <20230213132307.528976-3-stsp2@yandex.ru> (Stas Sergeev via Libc-alpha's message of "Mon, 13 Feb 2023 18:23:07 +0500")

* Stas Sergeev via Libc-alpha:

> This patch adds the following function:
> void *dlmem(const char *buffer, size_t size, int flags);
>
> It is the same as dlopen() but allows to dynamic-link solibs from
> the memory buffer, rather than from a file as dlopen() does.
>
> "buffer" arg is the pointer to the solib image in memory.
> "size" is the solib image size. Must be smaller-or-equal to the
> actual buffer size.
> "flags" is the same flags argument used in dlopen().
>
> The idea behind the implementation is very simple: where the
> dlopen() would mmap() the file, dlmem() does anonymous
> mmap()+memcpy().
> Unfortunately the glibc code was too bound to the file reads,
> so the patch looks bigger than it should. Some refactorings
> were needed to avoid big copy/pasts and code duplications.
> In particular, _dl_map_object_from_fd() was split and now calls
> 2 functions that are also called from __dl_map_object_from_mem().
> The same treatment was applied to open_verify() - the part that
> can be shared, was split into do_open_verify().
>
> This patch adds a test-case named tst-dlmem.
> The test-suite was run on x86_64/64 and showed no regressions.

On the Google branches, there is somewhat similar functionality, in the
form of dlopen_with_offset.  Their approach avoids some ambiguity
inherent to to the dlmem interface, mostly around whose responsibility
is it to set up the page protections.

Your patch seems to allow the creation of fully unnamed link maps
(especially if the shared object being loaded does not come with
DT_SONAME).  I think we need to discuss the consequences of that.  This
feature could be independently useful to some applications, to the
extent that they would use dlmem just for that purposes (even for files
that are stored on disk).

The test case could be extended to cover some failure cases, like a
purposefully misaligned buffer containing a valid ELF object.  Or the
interaction with auditing.

Thanks,
Florian


  reply	other threads:[~2023-02-13 13:45 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-13 13:23 [PATCH v3 0/2] implement dlmem() function Stas Sergeev
2023-02-13 13:23 ` [PATCH 1/2] elf: strdup() l_name if no realname [BZ #30100] Stas Sergeev
2023-02-13 13:23 ` [PATCH 2/2] dlfcn,elf: implement dlmem() function [BZ #11767] Stas Sergeev
2023-02-13 13:45   ` Florian Weimer [this message]
2023-02-13 16:36     ` stsp
2023-02-14  8:43     ` stsp
2023-03-18 17:28     ` stsp
  -- strict thread matches above, loose matches on Subject: below --
2023-02-15 11:21 [PATCH v5 0/2] implement dlmem() with audit extension Stas Sergeev
2023-02-15 11:21 ` [PATCH 2/2] dlfcn,elf: implement dlmem() function [BZ #11767] Stas Sergeev
2023-02-14  8:41 [PATCH v4 0/2] implement dlmem() function Stas Sergeev
2023-02-14  8:41 ` [PATCH 2/2] dlfcn,elf: implement dlmem() function [BZ #11767] Stas Sergeev
2023-02-14  9:51   ` Florian Weimer
2023-02-14 13:13     ` stsp
2023-02-15 11:30     ` stsp
2023-03-18 16:58     ` stsp
2023-02-10 14:07 [PATCH 1/2] elf: strdup() l_name if no realname [BZ #30100] Stas Sergeev
2023-02-10 14:07 ` [PATCH 2/2] dlfcn,elf: implement dlmem() function [BZ #11767] Stas Sergeev
2023-02-10 21:51   ` Joseph Myers
2023-02-11 20:10     ` stsp
2023-02-13 21:46       ` Joseph Myers
2023-02-14  8:42         ` stsp

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=87y1p1d6go.fsf@oldenburg.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=stsp2@yandex.ru \
    /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).