public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug dynamic-link/26634] New: ld.so stats raw file names, bypassing the audit module
@ 2020-09-18 21:44 ludo at gnu dot org
  2020-09-18 23:55 ` [Bug dynamic-link/26634] " mark at klomp dot org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: ludo at gnu dot org @ 2020-09-18 21:44 UTC (permalink / raw)
  To: glibc-bugs

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

            Bug ID: 26634
           Summary: ld.so stats raw file names, bypassing the audit module
           Product: glibc
           Version: 2.31
            Status: NEW
          Severity: normal
          Priority: P2
         Component: dynamic-link
          Assignee: unassigned at sourceware dot org
          Reporter: ludo at gnu dot org
  Target Milestone: ---

Created attachment 12850
  --> https://sourceware.org/bugzilla/attachment.cgi?id=12850&action=edit
Audit module that can be used as a reproducer

Unless I'm mistaken, the loader can end up stat'ing raw directory names
(DT_RUNPATH entries) instead of stat'ing names returned by the audit module's
'la_objsearch'.

The attached audit module illustrates that.  It's supposed to add "/PREFIX"
anytime 'name' has a leading slash (typically LA_SER_RUNPATH); yet, strace'ing
it shows that it calls 'stat' on the original file name, without "/PREFIX":

> $ strace -E LD_AUDIT=$PWD/audit.so -e stat expr --version
> [...]
> la_objsearch 4 '/gnu/store/35afkywncrr5xsb4cxcljf6rpjcb7f61-gmp-6.2.0/lib/haswell/libgmp.so.10' -> '/PREFIX/gnu/store/35afkywncrr5xsb4cxcljf6rpjcb7f61-gmp-6.2.0/lib/haswell/libgmp.so.10'
> stat("/gnu/store/35afkywncrr5xsb4cxcljf6rpjcb7f61-gmp-6.2.0/lib/haswell", 0x7ffe9f84c240) = -1 ENOENT (Dosiero aŭ dosierujo ne ekzistas)
> la_objsearch 4 '/gnu/store/35afkywncrr5xsb4cxcljf6rpjcb7f61-gmp-6.2.0/lib/x86_64/libgmp.so.10' -> '/PREFIX/gnu/store/35afkywncrr5xsb4cxcljf6rpjcb7f61-gmp-6.2.0/lib/x86_64/libgmp.so.10'
> stat("/gnu/store/35afkywncrr5xsb4cxcljf6rpjcb7f61-gmp-6.2.0/lib/x86_64", 0x7ffe9f84c240) = -1 ENOENT (Dosiero aŭ dosierujo ne ekzistas)
> la_objsearch 4 '/gnu/store/35afkywncrr5xsb4cxcljf6rpjcb7f61-gmp-6.2.0/lib/libgmp.so.10' -> '/PREFIX/gnu/store/35afkywncrr5xsb4cxcljf6rpjcb7f61-gmp-6.2.0/lib/libgmp.so.10'
> stat("/gnu/store/35afkywncrr5xsb4cxcljf6rpjcb7f61-gmp-6.2.0/lib", {st_mode=S_IFDIR|0555, st_size=4096, ...}) = 0
> [...]

(Here the /gnu/store directory is from expr's DT_RUNPATH; notice that 'stat'
ignores "/PREFIX".)

The consequence is that some search path entries get marked as 'nonexisting'
even though they potentially shouldn't.

The culprit appears to be 'open_path' in 'dl-load.c':

          fd = open_verify (buf, -1, fbp, loader, whatcode, mode,
                            found_other_class, false);
          if (this_dir->status[cnt] == unknown)
            {
              if (fd != -1)
                this_dir->status[cnt] = existing;
              /* Do not update the directory information when loading
                 auditing code.  We must try to disturb the program as
                 little as possible.  */
              else if (loader == NULL
                       || GL(dl_ns)[loader->l_ns]._ns_loaded->l_auditing == 0)
                {
                  /* We failed to open machine dependent library.  Let's
                     test whether there is any directory at all.  */
                  struct stat64 st;

                  buf[buflen - namelen - 1] = '\0';

                  if (__xstat64 (_STAT_VER, buf, &st) != 0
                      || ! S_ISDIR (st.st_mode))
                    /* The directory does not exist or it is no directory.  */
                    this_dir->status[cnt] = nonexisting;
                  else
                    this_dir->status[cnt] = existing;
                }
            }

Here 'buf' contains the original name.  'open_verify' is passed that original
name, calls the audit module's 'objsearch' function, and works on that. 
However, the '__xstat64' call right below is passed 'buf'--i.e., the original
name.

Does that make sense?

(This stems from <https://issues.guix.gnu.org/43491>.)

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

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

end of thread, other threads:[~2020-09-24 15:04 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-18 21:44 [Bug dynamic-link/26634] New: ld.so stats raw file names, bypassing the audit module ludo at gnu dot org
2020-09-18 23:55 ` [Bug dynamic-link/26634] " mark at klomp dot org
2020-09-24  9:54 ` ludo at gnu dot org
2020-09-24 10:29 ` fweimer at redhat dot com
2020-09-24 13:31 ` ludo at gnu dot org
2020-09-24 13:35 ` fweimer at redhat dot com
2020-09-24 13:50 ` ludo at gnu dot org
2020-09-24 13:56 ` fweimer at redhat dot com
2020-09-24 14:11 ` ludo at gnu dot org
2020-09-24 14:14 ` fweimer at redhat dot com
2020-09-24 14:37 ` ludo at gnu dot org
2020-09-24 14:39 ` fweimer at redhat dot com
2020-09-24 15:01 ` ludo at gnu dot org
2020-09-24 15:04 ` fweimer 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).