Manual Pages for Linux CentOS command on man rtld-audit
MyWebUniversity

Manual Pages for Linux CentOS command on man rtld-audit

RTLD-AUDIT(7) Linux Programmer's Manual RTLD-AUDIT(7)

NAME

rtld-audit - auditing API for the dynamic linker SYNOPSIS

#define GNUSOURCE /* See featuretestmacros(7) */

#include 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 pro‐

vided by the Solaris run-time linker. The necessary constants and pro‐ totypes are defined by including . 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 inter‐ ested 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 LDAUDIT

must be defined to contain 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. laversion() unsigned int laversion(unsigned int version); This is the only function that must be defined by an auditing library: it performs the initial handshake between the dynamic linker and the auditing library. When invoking this function, the dynamic linker passes, in version, the highest version of the auditing interface that the linker supports. If necessary, the auditing library can check that this version is sufficient for its requirements. As its function result, this function should return the version of the auditing interface that this auditing library expects to use (returning version is acceptable). If the returned value is 0, or a version that is greater than that supported by the dynamic linker, then the audit library is ignored. laobjsearch() char *laobjsearch(const char *name, uintptrt *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: LASERORIG This is the original name that is being searched for. Typically, this name comes from an ELF DTNEEDED entry, or is the filename argument given to dlopen(3). LASERLIBPATH name was created using a directory specified in LDLIBRARYPATH. LASERRUNPATH name was created using a directory specified in an ELF DTRPATH or DTRUNPATH list. LASERCONFIG name was found via the ldconfig(8) cache (/etc/ld.so.cache). LASERDEFAULT name was found via a search of one of the default directories. LASERSECURE name is specific to a secure object (unused on Linux). As its function result, laobjsearch() 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. laactivity() void laactivity( uintptrt *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 func‐ tion, flag is set to one of the following values: LAACTADD New objects are being added to the link map. LAACTDELETE Objects are being removed from the link map.

LAACTCONSISTENT Link-map activity has been completed: the map is once again consistent. laobjopen() unsigned int laobjopen(struct linkmap *map, Lmidt lmid, uintptrt *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 LMIDBASE Link map is part of the initial namespace. LMIDNEWLM Link map is part of a new namespace requested via dlmopen(3). 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, laobjopen() 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 lasymbind*(): LAFLGBINDTO Audit symbol bindings to this object. LAFLGBINDFROM Audit symbol bindings from this object. A return value of 0 from laobjopen() indicates that no symbol bindings should be audited for this object. laobjclose() unsigned int laobjclose(uintptrt *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 laobjopen(). In the current implementation, the value returned by laobjclose() is ignored. lapreinit() void lapreinit(uintptrt *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). lasymbind*() uintptrt lasymbind32(Elf32Sym *sym, unsigned int ndx, uintptrt *refcook, uintptrt *defcook, unsigned int *flags, const char *symname); uintptrt lasymbind64(Elf64Sym *sym, unsigned int ndx, uintptrt *refcook, uintptrt *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 laobjopen(). The lasymbind32() function is employed

on 32-bit platforms; the lasymbind64() 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 . Among the fields of this structure, stvalue 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 object. The refcook argument identifies the shared object that is making the symbol reference; this is the same identifier that is provided to the laobjopen() function that returned LAFLGBINDFROM. The defcook argu‐ ment identifies the shared object that defines the referenced symbol; this is the same identifier that is provided to the laobjopen() func‐ tion that returned LAFLGBINDTO. 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 (Pro‐ cedure Linkage Table) entry. The dynamic linker may supply the follow‐ ing bit values in this argument: LASYMBDLSYM The binding resulted from a call to dlsym(3). LASYMBALTVALUE A previous lasymbind*() call returned an alter‐ nate value for this symbol. By default, if the auditing library implements lapltenter() and lapltexit() functions (see below), then these functions are invoked, after lasymbind(), for PLT entries, each time the symbol is refer‐ enced. The following flags can be ORed into *flags to change this default behavior: LASYMBNOPLTENTER Don't call lapltenter() for this symbol. LASYMBNOPLTEXIT Don't call lapltexit() for this symbol. The return value of lasymbind32() and lasymbind64() 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->stvalue. A different value may be returned if the library wishes to direct control to an alternate location. lapltenter() The precise name and argument types for this function depend on the hardware platform. (The appropriate definition is supplied by

.) Here is the definition for x86-32: Elf32Addr lai86gnupltenter(Elf32Sym *sym, unsigned int ndx, uintptrt *refcook, uintptrt *defcook, Lai86regs *regs, unsigned int *flags, const char *symname, long int *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 lasymbind*(). The regs argument points to a structure (defined in ) contain‐ ing the values of registers 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 lasymbind*(). 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 lapltenter() invocations for this symbol return different values, then the maximum returned value is used. The lapltenter() function is called only if this buffer is explicitly set to a suitable value. The return value of lapltenter() is as for lasymbind*(). lapltexit() The precise name and argument types for this function depend on the hardware platform. (The appropriate definition is supplied by

.) Here is the definition for x86-32: unsigned int lai86gnupltexit(Elf32Sym *sym, unsigned int ndx, uintptrt *refcook, uintptrt *defcook, const Lai86regs *inregs, Lai86retval *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 lasymbind*(). The inregs argument points to a structure (defined in ) con‐ taining the values of registers used for the call to this PLT entry. The outregs argument points to a structure (defined in ) con‐ taining 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 call‐ er of the PLT entry. In the current GNU implementation, the return value of lapltexit() 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 laobjfilter() interface is not supported by the GNU implementation. * The Solaris lasymbind32() and lapltexit() functions do not provide a symname argument. * The Solaris lapltexit() function does not provide inregs and out‐ regs 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 LDAUDIT results in a run-time crash. This is reportedly fixed in glibc 2.10. EXAMPLE

#include

#include unsigned int laversion(unsigned int version) {

printf("laversion(): %d\n", version); return version; } char * laobjsearch(const char *name, uintptrt *cookie, unsigned int flag) {

printf("laobjsearch(): name = %s; cookie = %p", name, cookie);

printf("; flag = %s\n", (flag == LASERORIG) ? "LASERORIG" : (flag == LASERLIBPATH) ? "LASERLIBPATH" : (flag == LASERRUNPATH) ? "LASERRUNPATH" : (flag == LASERDEFAULT) ? "LASERDEFAULT" : (flag == LASERCONFIG) ? "LASERCONFIG" : (flag == LASERSECURE) ? "LASERSECURE" : "???"); return name; } void laactivity (uintptrt *cookie, unsigned int flag) {

printf("laactivity(): cookie = %p; flag = %s\n", cookie, (flag == LAACTCONSISTENT) ? "LAACTCONSISTENT" : (flag == LAACTADD) ? "LAACTADD" : (flag == LAACTDELETE) ? "LAACTDELETE" : "???"); } unsigned int laobjopen(struct linkmap *map, Lmidt lmid, uintptrt *cookie) {

printf("laobjopen(): loading \"%s\"; lmid = %s; cookie=%p\n",

map->lname, (lmid == LMIDBASE) ? "LMIDBASE" : (lmid == LMIDNEWLM) ? "LMIDNEWLM" : "???", cookie); return LAFLGBINDTO | LAFLGBINDFROM; } unsigned int laobjclose (uintptrt *cookie) {

printf("laobjclose(): %p\n", cookie); return 0; } void lapreinit(uintptrt *cookie) {

printf("lapreinit(): %p\n", cookie); } uintptrt lasymbind32(Elf32Sym *sym, unsigned int ndx, uintptrt *refcook, uintptrt *defcook, unsigned int *flags, const char *symname) {

printf("lasymbind32(): symname = %s; sym->stvalue = %p\n",

symname, sym->stvalue);

printf(" ndx = %d; flags = 0x%x", ndx, *flags);

printf("; refcook = %p; defcook = %p\n", refcook, defcook);

return sym->stvalue; } uintptrt lasymbind64(Elf64Sym *sym, unsigned int ndx, uintptrt *refcook, uintptrt *defcook, unsigned int *flags, const char *symname) {

printf("lasymbind64(): symname = %s; sym->stvalue = %p\n",

symname, sym->stvalue);

printf(" ndx = %d; flags = 0x%x", ndx, *flags);

printf("; refcook = %p; defcook = %p\n", refcook, defcook);

return sym->stvalue; } Elf32Addr lai86gnupltenter(Elf32Sym *sym, unsigned int ndx, uintptrt *refcook, uintptrt *defcook, Lai86regs *regs, unsigned int *flags, const char *symname, long int *framesizep) {

printf("lai86gnupltenter(): %s (%p)\n", symname, sym->stvalue);

return sym->stvalue; } SEE ALSO ldd(1), dlopen(3), ld.so(8), ldconfig(8) COLOPHON

This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can

be found at http://www.kernel.org/doc/man-pages/.

Linux 2012-07-07 RTLD-AUDIT(7)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™