public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v4 0/2] implement dlmem() function
@ 2023-02-14  8:41 Stas Sergeev
  2023-02-14  8:41 ` [PATCH 1/2] elf: strdup() l_name if no realname [BZ #30100] Stas Sergeev
  2023-02-14  8:41 ` [PATCH 2/2] dlfcn,elf: implement dlmem() function [BZ #11767] Stas Sergeev
  0 siblings, 2 replies; 18+ messages in thread
From: Stas Sergeev @ 2023-02-14  8:41 UTC (permalink / raw)
  To: libc-alpha; +Cc: Stas Sergeev

Changes in v4:
- re-target to GLIBC_2.38
- add tst-auditdlmem.c test-case to test auditing
- drop length page-aligning in tst-dlmem: mmap() aligns length on its own
- bugfix: in do_mmapcpy() allow mmaps past end of buffer

Changes in v3:
- Changed prototype of dlmem() (and all the internal machinery) to
  use "const unsigned char *buffer" instead of "const char *buffer".

Changes in v2:
- use <support/test-driver.c> instead of "../test-skeleton.c"
- re-target to GLIBC_2.37
- update all libc.abilist files


Patch 1: fix memory management bug in _dl_new_object()
Patch 2: implement dlmem() itself

Stas Sergeev (2):
  elf: strdup() l_name if no realname [BZ #30100]
  dlfcn,elf: implement dlmem() function [BZ #11767]

 dlfcn/Makefile                                |   5 +-
 dlfcn/Versions                                |   3 +
 dlfcn/dlmem.c                                 | 105 +++
 dlfcn/tst-dlmem.c                             |  92 ++
 elf/dl-load.c                                 | 862 +++++++++++-------
 elf/dl-load.h                                 |   8 +-
 elf/dl-main.h                                 |  20 +
 elf/dl-map-segments.h                         |  23 +-
 elf/dl-object.c                               |   2 +-
 elf/dl-open.c                                 |  37 +-
 elf/rtld.c                                    |   1 +
 include/dlfcn.h                               |   4 +
 manual/dynlink.texi                           |   1 +
 sysdeps/generic/ldsodefs.h                    |   7 +
 sysdeps/mach/hurd/i386/libc.abilist           |   1 +
 sysdeps/unix/sysv/linux/aarch64/libc.abilist  |   1 +
 sysdeps/unix/sysv/linux/alpha/libc.abilist    |   1 +
 sysdeps/unix/sysv/linux/arc/libc.abilist      |   1 +
 sysdeps/unix/sysv/linux/arm/be/libc.abilist   |   1 +
 sysdeps/unix/sysv/linux/arm/le/libc.abilist   |   1 +
 sysdeps/unix/sysv/linux/csky/libc.abilist     |   1 +
 sysdeps/unix/sysv/linux/hppa/libc.abilist     |   1 +
 sysdeps/unix/sysv/linux/i386/libc.abilist     |   1 +
 sysdeps/unix/sysv/linux/ia64/libc.abilist     |   1 +
 .../sysv/linux/loongarch/lp64/libc.abilist    |   1 +
 .../sysv/linux/m68k/coldfire/libc.abilist     |   1 +
 .../unix/sysv/linux/m68k/m680x0/libc.abilist  |   1 +
 .../sysv/linux/microblaze/be/libc.abilist     |   1 +
 .../sysv/linux/microblaze/le/libc.abilist     |   1 +
 .../sysv/linux/mips/mips32/fpu/libc.abilist   |   1 +
 .../sysv/linux/mips/mips32/nofpu/libc.abilist |   1 +
 .../sysv/linux/mips/mips64/n32/libc.abilist   |   1 +
 .../sysv/linux/mips/mips64/n64/libc.abilist   |   1 +
 sysdeps/unix/sysv/linux/nios2/libc.abilist    |   1 +
 sysdeps/unix/sysv/linux/or1k/libc.abilist     |   1 +
 .../linux/powerpc/powerpc32/fpu/libc.abilist  |   1 +
 .../powerpc/powerpc32/nofpu/libc.abilist      |   1 +
 .../linux/powerpc/powerpc64/be/libc.abilist   |   1 +
 .../linux/powerpc/powerpc64/le/libc.abilist   |   1 +
 .../unix/sysv/linux/riscv/rv32/libc.abilist   |   1 +
 .../unix/sysv/linux/riscv/rv64/libc.abilist   |   1 +
 .../unix/sysv/linux/s390/s390-32/libc.abilist |   1 +
 .../unix/sysv/linux/s390/s390-64/libc.abilist |   1 +
 sysdeps/unix/sysv/linux/sh/be/libc.abilist    |   1 +
 sysdeps/unix/sysv/linux/sh/le/libc.abilist    |   1 +
 .../sysv/linux/sparc/sparc32/libc.abilist     |   1 +
 .../sysv/linux/sparc/sparc64/libc.abilist     |   1 +
 .../unix/sysv/linux/x86_64/64/libc.abilist    |   1 +
 .../unix/sysv/linux/x86_64/x32/libc.abilist   |   1 +
 49 files changed, 860 insertions(+), 345 deletions(-)
 create mode 100644 dlfcn/dlmem.c
 create mode 100644 dlfcn/tst-dlmem.c

-- 
2.37.2


^ permalink raw reply	[flat|nested] 18+ messages in thread
* [PATCH v5 0/2] implement dlmem() with audit extension
@ 2023-02-15 11:21 Stas Sergeev
  2023-02-15 11:21 ` [PATCH 2/2] dlfcn,elf: implement dlmem() function [BZ #11767] Stas Sergeev
  0 siblings, 1 reply; 18+ messages in thread
From: Stas Sergeev @ 2023-02-15 11:21 UTC (permalink / raw)
  To: libc-alpha; +Cc: Stas Sergeev

Changes in v5:
- added _dl_audit_premap_dlmem audit extension for dlmem
- added tst-auditmod-dlmem.c test-case that feeds shm fd to dlmem()

Changes in v4:
- re-target to GLIBC_2.38
- add tst-auditdlmem.c test-case to test auditing
- drop length page-aligning in tst-dlmem: mmap() aligns length on its own
- bugfix: in do_mmapcpy() allow mmaps past end of buffer

Changes in v3:
- Changed prototype of dlmem() (and all the internal machinery) to
  use "const unsigned char *buffer" instead of "const char *buffer".

Changes in v2:
- use <support/test-driver.c> instead of "../test-skeleton.c"
- re-target to GLIBC_2.37
- update all libc.abilist files


Patch 1: fix memory management bug in _dl_new_object()
Patch 2: implement dlmem() and its audit extension

-- 
2.37.2


^ permalink raw reply	[flat|nested] 18+ messages in thread
* [PATCH v3 0/2] implement dlmem() function
@ 2023-02-13 13:23 Stas Sergeev
  2023-02-13 13:23 ` [PATCH 2/2] dlfcn,elf: implement dlmem() function [BZ #11767] Stas Sergeev
  0 siblings, 1 reply; 18+ messages in thread
From: Stas Sergeev @ 2023-02-13 13:23 UTC (permalink / raw)
  To: libc-alpha; +Cc: Stas Sergeev

Changes in v3:
- Changed prototype of dlmem() (and all the internal machinery) to
  use "const unsigned char *buffer" instead of "const char *buffer".

Changes in v2:
- use <support/test-driver.c> instead of "../test-skeleton.c"
- re-target to GLIBC_2.37
- update all libc.abilist files


Patch 1: fix memory management bug in _dl_new_object()
Patch 2: implement dlmem() itself

Stas Sergeev (2):
  elf: strdup() l_name if no realname [BZ #30100]
  dlfcn,elf: implement dlmem() function [BZ #11767]

 dlfcn/Makefile                                |   5 +-
 dlfcn/Versions                                |   3 +
 dlfcn/dlmem.c                                 | 105 +++
 dlfcn/tst-dlmem.c                             |  92 ++
 elf/dl-load.c                                 | 862 +++++++++++-------
 elf/dl-load.h                                 |   8 +-
 elf/dl-main.h                                 |  20 +
 elf/dl-map-segments.h                         |  23 +-
 elf/dl-object.c                               |   2 +-
 elf/dl-open.c                                 |  37 +-
 elf/rtld.c                                    |   1 +
 include/dlfcn.h                               |   4 +
 manual/dynlink.texi                           |   1 +
 sysdeps/generic/ldsodefs.h                    |   7 +
 sysdeps/mach/hurd/i386/libc.abilist           |   1 +
 sysdeps/unix/sysv/linux/aarch64/libc.abilist  |   1 +
 sysdeps/unix/sysv/linux/alpha/libc.abilist    |   1 +
 sysdeps/unix/sysv/linux/arc/libc.abilist      |   1 +
 sysdeps/unix/sysv/linux/arm/be/libc.abilist   |   1 +
 sysdeps/unix/sysv/linux/arm/le/libc.abilist   |   1 +
 sysdeps/unix/sysv/linux/csky/libc.abilist     |   1 +
 sysdeps/unix/sysv/linux/hppa/libc.abilist     |   1 +
 sysdeps/unix/sysv/linux/i386/libc.abilist     |   1 +
 sysdeps/unix/sysv/linux/ia64/libc.abilist     |   1 +
 .../sysv/linux/loongarch/lp64/libc.abilist    |   1 +
 .../sysv/linux/m68k/coldfire/libc.abilist     |   1 +
 .../unix/sysv/linux/m68k/m680x0/libc.abilist  |   1 +
 .../sysv/linux/microblaze/be/libc.abilist     |   1 +
 .../sysv/linux/microblaze/le/libc.abilist     |   1 +
 .../sysv/linux/mips/mips32/fpu/libc.abilist   |   1 +
 .../sysv/linux/mips/mips32/nofpu/libc.abilist |   1 +
 .../sysv/linux/mips/mips64/n32/libc.abilist   |   1 +
 .../sysv/linux/mips/mips64/n64/libc.abilist   |   1 +
 sysdeps/unix/sysv/linux/nios2/libc.abilist    |   1 +
 sysdeps/unix/sysv/linux/or1k/libc.abilist     |   1 +
 .../linux/powerpc/powerpc32/fpu/libc.abilist  |   1 +
 .../powerpc/powerpc32/nofpu/libc.abilist      |   1 +
 .../linux/powerpc/powerpc64/be/libc.abilist   |   1 +
 .../linux/powerpc/powerpc64/le/libc.abilist   |   1 +
 .../unix/sysv/linux/riscv/rv32/libc.abilist   |   1 +
 .../unix/sysv/linux/riscv/rv64/libc.abilist   |   1 +
 .../unix/sysv/linux/s390/s390-32/libc.abilist |   1 +
 .../unix/sysv/linux/s390/s390-64/libc.abilist |   1 +
 sysdeps/unix/sysv/linux/sh/be/libc.abilist    |   1 +
 sysdeps/unix/sysv/linux/sh/le/libc.abilist    |   1 +
 .../sysv/linux/sparc/sparc32/libc.abilist     |   1 +
 .../sysv/linux/sparc/sparc64/libc.abilist     |   1 +
 .../unix/sysv/linux/x86_64/64/libc.abilist    |   1 +
 .../unix/sysv/linux/x86_64/x32/libc.abilist   |   1 +
 49 files changed, 860 insertions(+), 345 deletions(-)
 create mode 100644 dlfcn/dlmem.c
 create mode 100644 dlfcn/tst-dlmem.c

-- 
2.37.2


^ permalink raw reply	[flat|nested] 18+ messages in thread
* [PATCH 1/2] elf: strdup() l_name if no realname [BZ #30100]
@ 2023-02-10 14:07 Stas Sergeev
  2023-02-10 14:07 ` [PATCH 2/2] dlfcn,elf: implement dlmem() function [BZ #11767] Stas Sergeev
  0 siblings, 1 reply; 18+ messages in thread
From: Stas Sergeev @ 2023-02-10 14:07 UTC (permalink / raw)
  To: libc-alpha; +Cc: Stas Sergeev

_dl_close_worker() has this code:
      /* This name always is allocated.  */
      free (imap->l_name);

But in that particular case, while indeed being allocated, l_name
doesn't point to the start of an allocation:
  new = (struct link_map *) calloc (sizeof (*new) + audit_space
                                    + sizeof (struct link_map *)
                                    + sizeof (*newname) + libname_len, 1);
  ...
  new->l_symbolic_searchlist.r_list = (struct link_map **) ((char *) (new + 1)
                                                            + audit_space);

  new->l_libname = newname
    = (struct libname_list *) (new->l_symbolic_searchlist.r_list + 1);
  newname->name = (char *) memcpy (newname + 1, libname, libname_len);
  ...
  new->l_name = (char *) newname->name + libname_len - 1;

It therefore cannot be freed separately.
Use strdup() as a simple fix.

Signed-off-by: Stas Sergeev <stsp2@yandex.ru>
---
 elf/dl-object.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/elf/dl-object.c b/elf/dl-object.c
index f1f2ec956c..c92daf37d1 100644
--- a/elf/dl-object.c
+++ b/elf/dl-object.c
@@ -122,7 +122,7 @@ _dl_new_object (char *realname, const char *libname, int type,
 #endif
     new->l_name = realname;
   else
-    new->l_name = (char *) newname->name + libname_len - 1;
+    new->l_name = __strdup ((char *) newname->name + libname_len - 1);
 
   new->l_type = type;
   /* If we set the bit now since we know it is never used we avoid
-- 
2.37.2


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2023-03-18 17:28 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-14  8:41 [PATCH v4 0/2] implement dlmem() function Stas Sergeev
2023-02-14  8:41 ` [PATCH 1/2] elf: strdup() l_name if no realname [BZ #30100] 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
  -- 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-13 13:23 [PATCH v3 0/2] implement dlmem() function 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
2023-02-13 16:36     ` stsp
2023-02-14  8:43     ` stsp
2023-03-18 17:28     ` 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

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).