[2/3] dl-audit: avoid closing fake ld.so [BZ #30127]

Message ID 20230302194051.3677691-3-stsp2@yandex.ru
State Superseded
Headers
Series minimal run-time audit support |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

stsp March 2, 2023, 7:40 p.m. UTC
  When new namespace is created, the fake ld.so object is created
that refers to main one via l_real pointer. Such object is not
passed to la_objopen() but is passed to la_objclose(), resulting
in an unrecognized cookie.
This patch avoids passing such objects to la_objclose().

The test-case for this is presented in a next patch.

Signed-off-by: Stas Sergeev <stsp2@yandex.ru>
---
 elf/dl-audit.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
  

Patch

diff --git a/elf/dl-audit.c b/elf/dl-audit.c
index 00e794aa26..ebfca887aa 100644
--- a/elf/dl-audit.c
+++ b/elf/dl-audit.c
@@ -96,7 +96,9 @@  void
 _dl_audit_objclose (struct link_map *l)
 {
   if (__glibc_likely (GLRO(dl_naudit) == 0)
-      || GL(dl_ns)[l->l_ns]._ns_loaded->l_auditing)
+      || GL(dl_ns)[l->l_ns]._ns_loaded->l_auditing
+      /* In non-base NS skip closing "fake" ld.so as it was not opened. */
+      || l->l_real != l)
     return;
 
   struct audit_ifaces *afct = GLRO(dl_audit);