public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/31992] New: Dynamic loading from within 2nd auditor is not reported to the 1st auditor properly
@ 2024-07-18 23:53 woodard at redhat dot com
  2024-08-08 13:12 ` [Bug dynamic-link/31992] " fweimer at redhat dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: woodard at redhat dot com @ 2024-07-18 23:53 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=31992

            Bug ID: 31992
           Summary: Dynamic loading from within 2nd auditor is not
                    reported to the 1st auditor properly
           Product: glibc
           Version: 2.39
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: woodard at redhat dot com
                CC: drepper.fsp at gmail dot com
  Target Milestone: ---

Created attachment 15633
  --> https://sourceware.org/bugzilla/attachment.cgi?id=15633&action=edit
reproducer

Attached a reproducer that demonstrates these problems. To run this reproducer
simply:

tar xvzf auditor-namespace-notification-silence.tar.gz
cd auditor-namespace-notification-silence
make

The output will look something like this:
Running test, success requires OK (not FAIL):
LD_AUDIT=./auditor.so:./victim.so ./main
[audit] la_objopen for ./victim.so, OK.
[audit] la_objopen for ./lib-base.so, OK.
[audit] la_symbind binding __cxa_finalize from ./lib-base.so to
/lib64/libc.so.6, OK.
[audit] la_symbind binding foo from ./victim.so to ./lib-base.so, OK.
[audit] la_objclose for ./lib-base.so, OK.
[audit] la_symbind binding foo to unknown binary ./lib-victim.so, FAIL.

[audit] Expected la_objsearch for victim.so, FAIL.
[audit] Expected la_objclose for victim.so, FAIL.
[audit] Expected la_objsearch for lib-base.so, FAIL.
[audit] Expected la_objsearch for lib-victim.so, FAIL.
[audit] Expected la_objopen for lib-victim.so, FAIL.
[audit] Expected la_objclose for lib-victim.so, FAIL.

It takes a bit to understand the output though. The key command after it builds
the source is:
LD_AUDIT=./auditor.so:./victim.so ./main

The outer auditor.so should see all dynamic loader events even those that
happen in the second auditor. 
The second auditor is called victim.so and it has a void la_preinit(uintptr_t*
cookie) function.  Which according to the rtld-audit man page "The dynamic
linker invokes this function after all shared objects have been loaded, before
control is passed to the application (i.e., before calling main()).  Note that
main()  may still later dynamically load objects using dlopen(3)."

So it will be run before the process. That function does some dynamic loading:
1) it loads a library into the process's name space
2) it loads another library into its own name space.

Both of these are standard auditor behavior. The way that the dynamic linking
process is supposed to work is first there is an la_objsearch() call this
allows an auditor to replace the object being loaded with something of its
selection. Then there is an la_objopen() which provides the link_map, the
namespace, and the cookie to that object.

The bugs are as follows:
1)  The first auditor is never given the opportunity to replace the second
auditor because there is no la_objsearch() for the second audtor's library.
This is indicated by the output:
[audit] Expected la_objsearch for victim.so, FAIL.

2) When the second auditor loads an object into the process's namespace,  the
la_objsearch() function in the first auditor doesn't get called. However, the
la_objopen() function is called. This prevents the first auditor from replacing
the library that the second auditor is placing in the process's namespace. This
is what is indicated by the failures at the end of the output:
[audit] Expected la_objsearch for lib-base.so, FAIL.
[audit] Expected la_objsearch for lib-victim.so, FAIL.

3) When the second auditor loads an object into its own namespace the situation
is even worse. Neither la_objsearch() nor la_objopen() are called.  Without the
objsearch, the first auditor can't replace the library being loaded by the
second auditor. Then without the objopen when the function is bound with the
dlsym() call, and ld.so calls la_symbind() the first auditor doesn't know about
the object that this function is associated with. This is what is indicated by:
[audit] la_symbind binding foo to unknown binary ./lib-victim.so, FAIL.

4) When the second auditor closes the library that it loaded into its own
namespace, the first auditor doesn't get the expected la_objclose(). This is
indicated by the line in the output:
 [audit] Expected la_objclose for lib-victim.so, FAIL.

5) Likewise when the process exits and the second auditor is removed, the first
auditor doesn't get notified. The line in the output that indicates this is:
[audit] Expected la_objclose for victim.so, FAIL.

These are all filed together because, I believe that all of these problems are
very closely related and the underlying problem is that the necessary callbacks
have not been added to the auditor handling code.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

end of thread, other threads:[~2024-09-18 23:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-18 23:53 [Bug libc/31992] New: Dynamic loading from within 2nd auditor is not reported to the 1st auditor properly woodard at redhat dot com
2024-08-08 13:12 ` [Bug dynamic-link/31992] " fweimer at redhat dot com
2024-08-08 14:01 ` fweimer at redhat dot com
2024-08-08 22:11 ` woodard at redhat dot com
2024-09-18 23:59 ` [Bug dynamic-link/31992] Dynamic linker auditors need to be able to audit each other woodard at redhat dot com

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