# RTLD-AUDIT(7) - man - phpMan

[RTLD-AUDIT(7)](https://www.chedong.com/phpMan.php/man/RTLD-AUDIT/7/markdown)                         Linux Programmer's Manual                        [RTLD-AUDIT(7)](https://www.chedong.com/phpMan.php/man/RTLD-AUDIT/7/markdown)



## NAME
       rtld-audit - auditing API for the dynamic linker

## SYNOPSIS
       **#define** ___**GNU**___**SOURCE**             /* See [feature_test_macros(7)](https://www.chedong.com/phpMan.php/man/featuretestmacros/7/markdown) */
### #include <link.h>

## DESCRIPTION
       The  GNU dynamic linker (run-time linker) provides an auditing API that allows an application
       to be notified when various dynamic linking events occur.  This API is very  similar  to  the
       auditing interface provided by the Solaris run-time linker.  The necessary constants and pro‐
       totypes are defined by including _<link.h>_.

       To use this interface, the programmer creates a shared library that implements a standard set
       of  function  names.   Not all of the functions need to be implemented: in most cases, if the
       programmer is not interested in a particular class of auditing event, then no  implementation
       needs to be provided for the corresponding auditing function.

       To  employ  the auditing interface, the environment variable **LD**___**AUDIT** must be defined to con‐
       tain a colon-separated list of shared libraries, each of which can implement (parts  of)  the
       auditing  API.  When an auditable event occurs, the corresponding function is invoked in each
       library, in the order that the libraries are listed.

   **la**___**version()**

       **unsigned** **int** **la**___**version(unsigned** **int** _version_**);**

       This is the only function that _must_ be defined by an auditing library: it performs  the  ini‐
       tial handshake between the dynamic linker and the auditing library.  When invoking this func‐
       tion, the dynamic linker passes, in _version_, the highest version of  the  auditing  interface
       that the linker supports.

       A  typical implementation of this function simply returns the constant **LAV**___**CURRENT**, which in‐
       dicates the version of _<link.h>_ that was used to build the  audit  module.   If  the  dynamic
       linker  does not support this version of the audit interface, it will refuse to activate this
       audit module.  If the function returns zero, the dynamic linker also does not  activate  this
       audit module.

       In  order  to  enable backwards compatibility with older dynamic linkers, an audit module can
       examine the _version_ argument and return an earlier version  than  **LAV**___**CURRENT**,  assuming  the
       module can adjust its implementation to match the requirements of the previous version of the
       audit interface.  The **la**___**version** function should not return the value of _version_ without fur‐
       ther checks because it could correspond to an interface that does not match the _<link.h>_ def‐
       initions used to build the audit module.

   **la**___**objsearch()**

       **char** ***la**___**objsearch(const** **char** *****_name_**,** **uintptr**___**t** *****_cookie_**,**
                          **unsigned** **int** _flag_**);**

       The dynamic linker invokes this function to inform the auditing library that it is  about  to
       search  for  a  shared  object.   The _name_ argument is the filename or pathname that is to be
       searched for.  _cookie_ identifies the shared object that initiated the search.  _flag_ is set to
       one of the following values:

       **LA**___**SER**___**ORIG**      This  is the original name that is being searched for.  Typically, this name
                        comes from an ELF **DT**___**NEEDED** entry, or is  the  _filename_  argument  given  to
                        [**dlopen**(3)](https://www.chedong.com/phpMan.php/man/dlopen/3/markdown).

       **LA**___**SER**___**LIBPATH**   _name_ was created using a directory specified in **LD**___**LIBRARY**___**PATH**.

       **LA**___**SER**___**RUNPATH**   _name_  was  created using a directory specified in an ELF **DT**___**RPATH** or **DT**___**RUN**‐‐
                        **PATH** list.

       **LA**___**SER**___**CONFIG**    _name_ was found via the [**ldconfig**(8)](https://www.chedong.com/phpMan.php/man/ldconfig/8/markdown) cache (_/etc/ld.so.cache_).

       **LA**___**SER**___**DEFAULT**   _name_ was found via a search of one of the default directories.

       **LA**___**SER**___**SECURE**    _name_ is specific to a secure object (unused on Linux).

       As its function result, **la**___**objsearch**() returns the pathname that the  dynamic  linker  should
       use  for  further processing.  If NULL is returned, then this pathname is ignored for further
       processing.  If this audit library simply intends to monitor search paths, then  _name_  should
       be returned.

   **la**___**activity()**

       **void** **la**___**activity(** **uintptr**___**t** *****_cookie_**,** **unsigned** **int** _flag_**);**

       The  dynamic linker calls this function to inform the auditing library that link-map activity
       is occurring.  _cookie_ identifies the object at the head of the link map.   When  the  dynamic
       linker invokes this function, _flag_ is set to one of the following values:

       **LA**___**ACT**___**ADD**         New objects are being added to the link map.

       **LA**___**ACT**___**DELETE**      Objects are being removed from the link map.

       **LA**___**ACT**___**CONSISTENT**  Link-map activity has been completed: the map is once again consistent.

   **la**___**objopen()**

       **unsigned** **int** **la**___**objopen(struct** **link**___**map** *****_map_**,** **Lmid**___**t** _lmid_**,**
                               **uintptr**___**t** *****_cookie_**);**

       The  dynamic linker calls this function when a new shared object is loaded.  The _map_ argument
       is a pointer to a link-map structure that describes the object.  The _lmid_ field  has  one  of
       the following values

       **LM**___**ID**___**BASE**       Link map is part of the initial namespace.

       **LM**___**ID**___**NEWLM**      Link map is part of a new namespace requested via [**dlmopen**(3)](https://www.chedong.com/phpMan.php/man/dlmopen/3/markdown).

       _cookie_  is  a  pointer to an identifier for this object.  The identifier is provided to later
       calls to functions in the auditing library in order to identify this object.  This identifier
       is initialized to point to object's link map, but the audit library can change the identifier
       to some other value that it may prefer to use to identify the object.

       As its return value, **la**___**objopen**() returns a bit mask created by ORing zero  or  more  of  the
       following  constants,  which allow the auditing library to select the objects to be monitored
       by **la**___**symbind***():

       **LA**___**FLG**___**BINDTO**    Audit symbol bindings to this object.

       **LA**___**FLG**___**BINDFROM**  Audit symbol bindings from this object.

       A return value of 0 from **la**___**objopen**() indicates that no symbol bindings should be audited for
       this object.

   **la**___**objclose()**

       **unsigned** **int** **la**___**objclose(uintptr**___**t** *****_cookie_**);**

       The  dynamic linker invokes this function after any finalization code for the object has been
       executed, before the object is unloaded.  The _cookie_ argument is the identifier obtained from
       a previous invocation of **la**___**objopen**().

       In the current implementation, the value returned by **la**___**objclose**() is ignored.

   **la**___**preinit()**

       **void** **la**___**preinit(uintptr**___**t** *****_cookie_**);**

       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)](https://www.chedong.com/phpMan.php/man/dlopen/3/markdown).

   **la**___**symbind*()**

       **uintptr**___**t** **la**___**symbind32(Elf32**___**Sym** *****_sym_**,** **unsigned** **int** _ndx_**,**
                              **uintptr**___**t** *****_refcook_**,** **uintptr**___**t** *****_defcook_**,**
                              **unsigned** **int** *****_flags_**,** **const** **char** *****_symname_**);**
       **uintptr**___**t** **la**___**symbind64(Elf64**___**Sym** *****_sym_**,** **unsigned** **int** _ndx_**,**
                              **uintptr**___**t** *****_refcook_**,** **uintptr**___**t** *****_defcook_**,**
                              **unsigned** **int** *****_flags_**,** **const** **char** *****_symname_**);**

       The  dynamic  linker  invokes one of these functions when a symbol binding occurs between two
       shared objects that have been marked for auditing notification by **la**___**objopen**().  The  **la**___**sym**‐‐
       **bind32**() function is employed on 32-bit platforms; the **la**___**symbind64**() function is employed on
       64-bit platforms.

       The _sym_ argument is a pointer to a structure that provides information about the symbol being
       bound.   The  structure  definition is shown in _<elf.h>_.  Among the fields of this structure,
       _st_value_ indicates the address to which the symbol is bound.

       The _ndx_ argument gives the index of the symbol in the symbol table of the  bound  shared  ob‐
       ject.

       The  _refcook_  argument identifies the shared object that is making the symbol reference; this
       is the  same  identifier  that  is  provided  to  the  **la**___**objopen**()  function  that  returned
       **LA**___**FLG**___**BINDFROM**.   The  _defcook_ argument identifies the shared object that defines the refer‐
       enced symbol; this is the same identifier that is provided to the **la**___**objopen**() function  that
       returned **LA**___**FLG**___**BINDTO**.

       The _symname_ argument points a string containing the name of the symbol.

       The  _flags_  argument is a bit mask that both provides information about the symbol and can be
       used to modify further auditing of this PLT (Procedure Linkage  Table)  entry.   The  dynamic
       linker may supply the following bit values in this argument:

       **LA**___**SYMB**___**DLSYM**         The binding resulted from a call to [**dlsym**(3)](https://www.chedong.com/phpMan.php/man/dlsym/3/markdown).

       **LA**___**SYMB**___**ALTVALUE**      A previous **la**___**symbind***() call returned an alternate value for this sym‐
                             bol.

       By default, if the auditing library implements **la**___**pltenter**() and **la**___**pltexit**() functions  (see
       below),  then these functions are invoked, after **la**___**symbind**(), for PLT entries, each time the
       symbol is referenced.  The following flags can be ORed into _*flags_ to change this default be‐
       havior:

       **LA**___**SYMB**___**NOPLTENTER**    Don't call **la**___**pltenter**() for this symbol.

       **LA**___**SYMB**___**NOPLTEXIT**     Don't call **la**___**pltexit**() for this symbol.

       The  return value of **la**___**symbind32**() and **la**___**symbind64**() is the address to which control should
       be passed after the function returns.  If the auditing library is  simply  monitoring  symbol
       bindings,  then it should return _sym->st_value_.  A different value may be returned if the li‐
       brary wishes to direct control to an alternate location.

   **la**___**pltenter()**
       The precise name and argument types for this function depend on the hardware platform.   (The
       appropriate definition is supplied by _<link.h>_.)  Here is the definition for x86-32:

       **Elf32**___**Addr** **la**___**i86**___**gnu**___**pltenter(Elf32**___**Sym** *****_sym_**,** **unsigned** **int** _ndx_**,**
                        **uintptr**___**t** *****_refcook_**,** **uintptr**___**t** *****_defcook_**,**
                        **La**___**i86**___**regs** *****_regs_**,** **unsigned** **int** *****_flags_**,**
                        **const** **char** *****_symname_**,** **long** *****_framesizep_**);**

       This  function  is invoked just before a PLT entry is called, between two shared objects that
       have been marked for binding notification.

       The _sym_, _ndx_, _refcook_, _defcook_, and _symname_ are as for **la**___**symbind***().

       The _regs_ argument points to a structure (defined in _<link.h>_) containing the values of regis‐
       ters to be used for the call to this PLT entry.

       The  _flags_  argument  points to a bit mask that conveys information about, and can be used to
       modify subsequent auditing of, this PLT entry, as for **la**___**symbind***().

       The _framesizep_ argument points to a _long_ _int_ buffer that can be used to  explicitly  set  the
       frame  size  used for the call to this PLT entry.  If different **la**___**pltenter**() invocations for
       this symbol return different values, then the maximum returned value  is  used.   The  **la**___**pl**‐‐
       **texit**() function is called only if this buffer is explicitly set to a suitable value.

       The return value of **la**___**pltenter**() is as for **la**___**symbind***().

   **la**___**pltexit()**
       The  precise name and argument types for this function depend on the hardware platform.  (The
       appropriate definition is supplied by _<link.h>_.)  Here is the definition for x86-32:

       **unsigned** **int** **la**___**i86**___**gnu**___**pltexit(Elf32**___**Sym** *****_sym_**,** **unsigned** **int** _ndx_**,**
                        **uintptr**___**t** *****_refcook_**,** **uintptr**___**t** *****_defcook_**,**
                        **const** **La**___**i86**___**regs** *****_inregs_**,** **La**___**i86**___**retval** *****_outregs_**,**
                        **const** **char** *****_symname_**);**

       This function is called when a PLT entry, made between two  shared  objects  that  have  been
       marked for binding notification, returns.  The function is called just before control returns
       to the caller of the PLT entry.

       The _sym_, _ndx_, _refcook_, _defcook_, and _symname_ are as for **la**___**symbind***().

       The _inregs_ argument points to a structure (defined in _<link.h>_) containing the values of reg‐
       isters  used for the call to this PLT entry.  The _outregs_ argument points to a structure (de‐
       fined in _<link.h>_) containing return values for the call to this PLT entry.  These values can
       be modified by the caller, and the changes will be visible to the caller of the PLT entry.

       In the current GNU implementation, the return value of **la**___**pltexit**() is ignored.

## CONFORMING TO
       This API is nonstandard, but very similar to the Solaris API, described in the Solaris _Linker_
       _and_ _Libraries_ _Guide_, in the chapter _Runtime_ _Linker_ _Auditing_ _Interface_.

## NOTES
       Note the following differences from the Solaris dynamic linker auditing API:

       *  The Solaris **la**___**objfilter**() interface is not supported by the GNU implementation.

       *  The Solaris **la**___**symbind32**() and **la**___**pltexit**() functions do not provide a _symname_ argument.

       *  The Solaris **la**___**pltexit**() function does not provide _inregs_ and _outregs_ arguments (but  does
          provide a _retval_ argument with the function return value).

## BUGS
       In  glibc  versions up to and include 2.9, specifying more than one audit library in **LD**___**AUDIT**
       results in a run-time crash.  This is reportedly fixed in glibc 2.10.

## EXAMPLES
       #include <link.h>
       #include <stdio.h>

       unsigned int
       la_version(unsigned int version)
       {
           printf("la_version(): version = %u; LAV_CURRENT = %u\n",
                   version, LAV_CURRENT);

           return LAV_CURRENT;
       }

       char *
       la_objsearch(const char *name, uintptr_t *cookie, unsigned int flag)
       {
           printf("la_objsearch(): name = %s; cookie = %p", name, cookie);
           printf("; flag = %s\n",
                   (flag == LA_SER_ORIG) ?    "LA_SER_ORIG" :
                   (flag == LA_SER_LIBPATH) ? "LA_SER_LIBPATH" :
                   (flag == LA_SER_RUNPATH) ? "LA_SER_RUNPATH" :
                   (flag == LA_SER_DEFAULT) ? "LA_SER_DEFAULT" :
                   (flag == LA_SER_CONFIG) ?  "LA_SER_CONFIG" :
                   (flag == LA_SER_SECURE) ?  "LA_SER_SECURE" :
                   "???");

           return name;
       }

       void
       la_activity (uintptr_t *cookie, unsigned int flag)
       {
           printf("la_activity(): cookie = %p; flag = %s\n", cookie,
                   (flag == LA_ACT_CONSISTENT) ? "LA_ACT_CONSISTENT" :
                   (flag == LA_ACT_ADD) ?        "LA_ACT_ADD" :
                   (flag == LA_ACT_DELETE) ?     "LA_ACT_DELETE" :
                   "???");
       }

       unsigned int
       la_objopen(struct link_map *map, Lmid_t lmid, uintptr_t *cookie)
       {
           printf("la_objopen(): loading \"%s\"; lmid = %s; cookie=%p\n",
                   map->l_name,
                   (lmid == LM_ID_BASE) ?  "LM_ID_BASE" :
                   (lmid == LM_ID_NEWLM) ? "LM_ID_NEWLM" :
                   "???",
                   cookie);

           return LA_FLG_BINDTO | LA_FLG_BINDFROM;
       }

       unsigned int
       la_objclose (uintptr_t *cookie)
       {
           printf("la_objclose(): %p\n", cookie);

           return 0;
       }

       void
       la_preinit(uintptr_t *cookie)
       {
           printf("la_preinit(): %p\n", cookie);
       }

       uintptr_t
       la_symbind32(Elf32_Sym *sym, unsigned int ndx, uintptr_t *refcook,
               uintptr_t *defcook, unsigned int *flags, const char *symname)
       {
           printf("la_symbind32(): symname = %s; sym->st_value = %p\n",
                   symname, sym->st_value);
           printf("        ndx = %u; flags = %#x", ndx, *flags);
           printf("; refcook = %p; defcook = %p\n", refcook, defcook);

           return sym->st_value;
       }

       uintptr_t
       la_symbind64(Elf64_Sym *sym, unsigned int ndx, uintptr_t *refcook,
               uintptr_t *defcook, unsigned int *flags, const char *symname)
       {
           printf("la_symbind64(): symname = %s; sym->st_value = %p\n",
                   symname, sym->st_value);
           printf("        ndx = %u; flags = %#x", ndx, *flags);
           printf("; refcook = %p; defcook = %p\n", refcook, defcook);

           return sym->st_value;
       }

       Elf32_Addr
       la_i86_gnu_pltenter(Elf32_Sym *sym, unsigned int ndx,
               uintptr_t *refcook, uintptr_t *defcook, La_i86_regs *regs,
               unsigned int *flags, const char *symname, long *framesizep)
       {
           printf("la_i86_gnu_pltenter(): %s (%p)\n", symname, sym->st_value);

           return sym->st_value;
       }

## SEE ALSO
       [**ldd**(1)](https://www.chedong.com/phpMan.php/man/ldd/1/markdown), [**dlopen**(3)](https://www.chedong.com/phpMan.php/man/dlopen/3/markdown), [**ld.so**(8)](https://www.chedong.com/phpMan.php/man/ld.so/8/markdown), [**ldconfig**(8)](https://www.chedong.com/phpMan.php/man/ldconfig/8/markdown)

## COLOPHON
       This page is part of release 5.10 of the Linux  _man-pages_  project.   A  description  of  the
       project,  information about reporting bugs, and the latest version of this page, can be found
       at <https://www.kernel.org/doc/man-pages/>.



Linux                                        2020-11-01                                [RTLD-AUDIT(7)](https://www.chedong.com/phpMan.php/man/RTLD-AUDIT/7/markdown)
