Debian Codegraph @

upstream/debian-unstable/man7/rtld-audit.7

raw
1 .\" Copyright, the authors of the Linux man-pages project
2 .\"
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
4 .\"
5 .TH RTLD-AUDIT 7 2025-05-17 "Linux man-pages 6.18"
6 .SH NAME
7 rtld\-audit \- auditing API for the dynamic linker
8 .SH SYNOPSIS
9 .nf
10 .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
11 .B #include <link.h>
12 .fi
13 .SH DESCRIPTION
14 The GNU dynamic linker (run-time linker)
15 provides an auditing API that allows an application
16 to be notified when various dynamic linking events occur.
17 This API is very similar to the auditing interface provided by the
18 Solaris run-time linker.
19 The necessary constants and prototypes are defined by including
20 .IR <link.h> .
21 .P
22 To use this interface, the programmer creates a shared library
23 that implements a standard set of function names.
24 Not all of the functions need to be implemented: in most cases,
25 if the programmer is not interested in a particular class of auditing event,
26 then no implementation needs to be provided for the corresponding
27 auditing function.
28 .P
29 To employ the auditing interface, the environment variable
30 .B LD_AUDIT
31 must be defined to contain a colon-separated list of shared libraries,
32 each of which can implement (parts of) the auditing API.
33 When an auditable event occurs,
34 the corresponding function is invoked in each library,
35 in the order that the libraries are listed.
36 .SS la_version()
37 \&
38 .nf
39 .BI "unsigned int la_version(unsigned int " version );
40 .fi
41 .P
42 This is the only function that
43 .I must
44 be defined by an auditing library:
45 it performs the initial handshake between the dynamic linker and
46 the auditing library.
47 When invoking this function, the dynamic linker passes, in
48 .IR version ,
49 the highest version of the auditing interface that the linker supports.
50 .P
51 A typical implementation of this function simply returns the constant
52 .BR LAV_CURRENT ,
53 which indicates the version of
54 .I <link.h>
55 that was used to build the audit module.
56 If the dynamic linker does
57 not support this version of the audit interface, it will refuse to
58 activate this audit module.
59 If the function returns zero, the dynamic
60 linker also does not activate this audit module.
61 .P
62 In order to enable backwards compatibility with older dynamic linkers,
63 an audit module can examine the
64 .I version
65 argument and return an earlier version than
66 .BR LAV_CURRENT ,
67 assuming the module can adjust its implementation to match the
68 requirements of the previous version of the audit interface.
69 The
70 .B la_version
71 function should not return the value of
72 .I version
73 without further checks because it could correspond to an interface
74 that does not match the
75 .I <link.h>
76 definitions used to build the audit module.
77 .SS la_objsearch()
78 \&
79 .nf
80 .BI "char *la_objsearch(const char *" name ", uintptr_t *" cookie ,
81 .BI " unsigned int " flag );
82 .fi
83 .P
84 The dynamic linker invokes this function to inform the auditing library
85 that it is about to search for a shared object.
86 The
87 .I name
88 argument is the filename or pathname that is to be searched for.
89 .I cookie
90 identifies the shared object that initiated the search.
91 .I flag
92 is set to one of the following values:
93 .TP 17
94 .B LA_SER_ORIG
95 This is the original name that is being searched for.
96 Typically, this name comes from an ELF
97 .B DT_NEEDED
98 entry, or is the
99 .I filename
100 argument given to
101 .BR dlopen (3).
102 .TP
103 .B LA_SER_LIBPATH
104 .I name
105 was created using a directory specified in
106 .BR LD_LIBRARY_PATH .
107 .TP
108 .B LA_SER_RUNPATH
109 .I name
110 was created using a directory specified in an ELF
111 .B DT_RPATH
112 or
113 .B DT_RUNPATH
114 list.
115 .TP
116 .B LA_SER_CONFIG
117 .I name
118 was found via the
119 .BR ldconfig (8)
120 cache
121 .RI ( /etc/ld.so.cache ).
122 .TP
123 .B LA_SER_DEFAULT
124 .I name
125 was found via a search of one of the default directories.
126 .TP
127 .B LA_SER_SECURE
128 .I name
129 is specific to a secure object (unused on Linux).
130 .P
131 As its function result,
132 .BR la_objsearch ()
133 returns the pathname that the dynamic linker should use
134 for further processing.
135 If NULL is returned, then this pathname is ignored for further processing.
136 If this audit library simply intends to monitor search paths, then
137 .I name
138 should be returned.
139 .SS la_activity()
140 \&
141 .nf
142 .BI "void la_activity( uintptr_t *" cookie ", unsigned int "flag );
143 .fi
144 .P
145 The dynamic linker calls this function to inform the auditing library
146 that link-map activity is occurring.
147 .I cookie
148 identifies the object at the head of the link map.
149 When the dynamic linker invokes this function,
150 .I flag
151 is set to one of the following values:
152 .TP 19
153 .B LA_ACT_ADD
154 New objects are being added to the link map.
155 .TP
156 .B LA_ACT_DELETE
157 Objects are being removed from the link map.
158 .TP
159 .B LA_ACT_CONSISTENT
160 Link-map activity has been completed: the map is once again consistent.
161 .SS la_objopen()
162 \&
163 .nf
164 .BI "unsigned int la_objopen(struct link_map *" map ", Lmid_t " lmid ,
165 .BI " uintptr_t *" cookie );
166 .fi
167 .P
168 The dynamic linker calls this function when a new shared object is loaded.
169 The
170 .I map
171 argument is a pointer to a link-map structure that describes the object.
172 The
173 .I lmid
174 field has one of the following values
175 .TP 17
176 .B LM_ID_BASE
177 Link map is part of the initial namespace.
178 .TP
179 .B LM_ID_NEWLM
180 Link map is part of a new namespace requested via
181 .BR dlmopen (3).
182 .P
183 .I cookie
184 is a pointer to an identifier for this object.
185 The identifier is provided to later calls to functions
186 in the auditing library in order to identify this object.
187 This identifier is initialized to point to object's link map,
188 but the audit library can change the identifier to some other value
189 that it may prefer to use to identify the object.
190 .P
191 As its return value,
192 .BR la_objopen ()
193 returns a bit mask created by ORing zero or more of the
194 following constants,
195 which allow the auditing library to select the objects to be monitored by
196 .BR la_symbind* ():
197 .TP 17
198 .B LA_FLG_BINDTO
199 Audit symbol bindings to this object.
200 .TP
201 .B LA_FLG_BINDFROM
202 Audit symbol bindings from this object.
203 .P
204 A return value of 0 from
205 .BR la_objopen ()
206 indicates that no symbol bindings should be audited for this object.
207 .SS la_objclose()
208 \&
209 .nf
210 .BI "unsigned int la_objclose(uintptr_t *" cookie );
211 .fi
212 .P
213 The dynamic linker invokes this function after any finalization
214 code for the object has been executed,
215 before the object is unloaded.
216 The
217 .I cookie
218 argument is the identifier obtained from a previous invocation of
219 .BR la_objopen ().
220 .P
221 In the current implementation, the value returned by
222 .BR la_objclose ()
223 is ignored.
224 .SS la_preinit()
225 \&
226 .nf
227 .BI "void la_preinit(uintptr_t *" cookie );
228 .fi
229 .P
230 The dynamic linker invokes this function after all shared objects
231 have been loaded, before control is passed to the application
232 (i.e., before calling
233 .IR main ()).
234 Note that
235 .IR main ()
236 may still later dynamically load objects using
237 .BR dlopen (3).
238 .SS la_symbind*()
239 \&
240 .nf
241 .BI "uintptr_t la_symbind32(Elf32_Sym *" sym ", unsigned int " ndx ,
242 .BI " uintptr_t *" refcook ", uintptr_t *" defcook ,
243 .BI " unsigned int *" flags ", const char *" symname );
244 .BI "uintptr_t la_symbind64(Elf64_Sym *" sym ", unsigned int " ndx ,
245 .BI " uintptr_t *" refcook ", uintptr_t *" defcook ,
246 .BI " unsigned int *" flags ", const char *" symname );
247 .fi
248 .P
249 The dynamic linker invokes one of these functions
250 when a symbol binding occurs between two shared objects
251 that have been marked for auditing notification by
252 .BR la_objopen ().
253 The
254 .BR la_symbind32 ()
255 function is employed on 32-bit platforms;
256 the
257 .BR la_symbind64 ()
258 function is employed on 64-bit platforms.
259 .P
260 The
261 .I sym
262 argument is a pointer to a structure
263 that provides information about the symbol being bound.
264 The structure definition is shown in
265 .IR <elf.h> .
266 Among the fields of this structure,
267 .I st_value
268 indicates the address to which the symbol is bound.
269 .P
270 The
271 .I ndx
272 argument gives the index of the symbol in the symbol table
273 of the bound shared object.
274 .P
275 The
276 .I refcook
277 argument identifies the shared object that is making the symbol reference;
278 this is the same identifier that is provided to the
279 .BR la_objopen ()
280 function that returned
281 .BR LA_FLG_BINDFROM .
282 The
283 .I defcook
284 argument identifies the shared object that defines the referenced symbol;
285 this is the same identifier that is provided to the
286 .BR la_objopen ()
287 function that returned
288 .BR LA_FLG_BINDTO .
289 .P
290 The
291 .I symname
292 argument points a string containing the name of the symbol.
293 .P
294 The
295 .I flags
296 argument is a bit mask that both provides information about the symbol
297 and can be used to modify further auditing of this
298 PLT (Procedure Linkage Table) entry.
299 The dynamic linker may supply the following bit values in this argument:
300 .\" LA_SYMB_STRUCTCALL appears to be unused
301 .TP 22
302 .B LA_SYMB_DLSYM
303 The binding resulted from a call to
304 .BR dlsym (3).
305 .TP
306 .B LA_SYMB_ALTVALUE
307 A previous
308 .BR la_symbind* ()
309 call returned an alternate value for this symbol.
310 .P
311 By default, if the auditing library implements
312 .BR la_pltenter ()
313 and
314 .BR la_pltexit ()
315 functions (see below), then these functions are invoked, after
316 .BR la_symbind (),
317 for PLT entries, each time the symbol is referenced.
318 .\" pltenter/pltexit are called for non-dynamically loaded libraries,
319 .\" but don't seem to be called for dynamically loaded libs?
320 .\" Is this the same on Solaris?
321 The following flags can be ORed into
322 .I *flags
323 to change this default behavior:
324 .TP 22
325 .B LA_SYMB_NOPLTENTER
326 Don't call
327 .BR la_pltenter ()
328 for this symbol.
329 .TP 22
330 .B LA_SYMB_NOPLTEXIT
331 Don't call
332 .BR la_pltexit ()
333 for this symbol.
334 .P
335 The return value of
336 .BR la_symbind32 ()
337 and
338 .BR la_symbind64 ()
339 is the address to which control should be passed after the function returns.
340 If the auditing library is simply monitoring symbol bindings,
341 then it should return
342 .IR sym\->st_value .
343 A different value may be returned if the library wishes to direct control
344 to an alternate location.
345 .SS la_pltenter()
346 The precise name and argument types for this function
347 depend on the hardware platform.
348 (The appropriate definition is supplied by
349 .IR <link.h> .)
350 Here is the definition for x86-32:
351 .P
352 .nf
353 .BI "Elf32_Addr la_i86_gnu_pltenter(Elf32_Sym *" sym ", unsigned int " ndx ,
354 .BI " uintptr_t *" refcook ", uintptr_t *" defcook ,
355 .BI " La_i86_regs *" regs ", unsigned int *" flags ,
356 .BI " const char *" symname ", long *" framesizep );
357 .fi
358 .P
359 This function is invoked just before a PLT entry is called,
360 between two shared objects that have been marked for binding notification.
361 .P
362 The
363 .IR sym ,
364 .IR ndx ,
365 .IR refcook ,
366 .IR defcook ,
367 and
368 .I symname
369 are as for
370 .BR la_symbind* ().
371 .P
372 The
373 .I regs
374 argument points to a structure (defined in
375 .IR <link.h> )
376 containing the values of registers to be used for
377 the call to this PLT entry.
378 .P
379 The
380 .I flags
381 argument points to a bit mask that conveys information about,
382 and can be used to modify subsequent auditing of, this PLT entry, as for
383 .BR la_symbind* ().
384 .P
385 .\" FIXME . Is the following correct?
386 The
387 .I framesizep
388 argument points to a
389 .I long\~int
390 buffer that can be used to explicitly set the frame size
391 used for the call to this PLT entry.
392 If different
393 .BR la_pltenter ()
394 invocations for this symbol return different values,
395 then the maximum returned value is used.
396 The
397 .BR la_pltexit ()
398 function is called only if this buffer is
399 explicitly set to a suitable value.
400 .P
401 The return value of
402 .BR la_pltenter ()
403 is as for
404 .BR la_symbind* ().
405 .SS la_pltexit()
406 The precise name and argument types for this function
407 depend on the hardware platform.
408 (The appropriate definition is supplied by
409 .IR <link.h> .)
410 Here is the definition for x86-32:
411 .P
412 .nf
413 .BI "unsigned int la_i86_gnu_pltexit(Elf32_Sym *" sym ", unsigned int " ndx ,
414 .BI " uintptr_t *" refcook ", uintptr_t *" defcook ,
415 .BI " const La_i86_regs *" inregs ", La_i86_retval *" outregs ,
416 .BI " const char *" symname );
417 .fi
418 .P
419 This function is called when a PLT entry,
420 made between two shared objects that have been marked
421 for binding notification, returns.
422 The function is called just before control returns to the caller
423 of the PLT entry.
424 .P
425 The
426 .IR sym ,
427 .IR ndx ,
428 .IR refcook ,
429 .IR defcook ,
430 and
431 .I symname
432 are as for
433 .BR la_symbind* ().
434 .P
435 The
436 .I inregs
437 argument points to a structure (defined in
438 .IR <link.h> )
439 containing the values of registers used for the call to this PLT entry.
440 The
441 .I outregs
442 argument points to a structure (defined in
443 .IR <link.h> )
444 containing return values for the call to this PLT entry.
445 These values can be modified by the caller,
446 and the changes will be visible to the caller of the PLT entry.
447 .P
448 In the current GNU implementation, the return value of
449 .BR la_pltexit ()
450 is ignored.
451 .\" This differs from Solaris, where an audit library that monitors
452 .\" symbol binding should return the value of the 'retval' argument
453 .\" (not provided by GNU, but equivalent to returning outregs->lrv_eax
454 .\" on (say) x86-32).
455 .SH VERSIONS
456 This API is very similar to the Solaris API
457 described in the Solaris
458 .IR "Linker and Libraries Guide" ,
459 in the chapter
460 .IR "Runtime Linker Auditing Interface" .
461 .SH STANDARDS
462 None.
463 .SH NOTES
464 Note the following differences from the Solaris dynamic linker
465 auditing API:
466 .IP \[bu] 3
467 The Solaris
468 .BR la_objfilter ()
469 interface is not supported by the GNU implementation.
470 .IP \[bu]
471 The Solaris
472 .BR la_symbind32 ()
473 and
474 .BR la_pltexit ()
475 functions do not provide a
476 .I symname
477 argument.
478 .IP \[bu]
479 The Solaris
480 .BR la_pltexit ()
481 function does not provide
482 .I inregs
483 and
484 .I outregs
485 arguments (but does provide a
486 .I retval
487 argument with the function return value).
488 .SH BUGS
489 In glibc versions up to and include 2.9,
490 specifying more than one audit library in
491 .B LD_AUDIT
492 results in a run-time crash.
493 This is reportedly fixed in glibc 2.10.
494 .\" FIXME . Specifying multiple audit libraries doesn't work on GNU.
495 .\" My simple tests on Solaris work okay, but not on Linux -- mtk, Jan 2009
496 .\" glibc bug filed: http://sourceware.org/bugzilla/show_bug.cgi?id=9733
497 .\" Reportedly, this is fixed on 16 Mar 2009 (i.e., for glibc 2.10)
498 .SH EXAMPLES
499 .EX
500 #include <link.h>
501 #include <stdio.h>
502 \&
503 unsigned int
504 la_version(unsigned int version)
505 {
506 printf("la_version(): version = %u; LAV_CURRENT = %u\[rs]n",
507 version, LAV_CURRENT);
508 \&
509 return LAV_CURRENT;
510 }
511 \&
512 char *
513 la_objsearch(const char *name, uintptr_t *cookie, unsigned int flag)
514 {
515 printf("la_objsearch(): name = %s; cookie = %p", name, cookie);
516 printf("; flag = %s\[rs]n",
517 (flag == LA_SER_ORIG) ? "LA_SER_ORIG" :
518 (flag == LA_SER_LIBPATH) ? "LA_SER_LIBPATH" :
519 (flag == LA_SER_RUNPATH) ? "LA_SER_RUNPATH" :
520 (flag == LA_SER_DEFAULT) ? "LA_SER_DEFAULT" :
521 (flag == LA_SER_CONFIG) ? "LA_SER_CONFIG" :
522 (flag == LA_SER_SECURE) ? "LA_SER_SECURE" :
523 "???");
524 \&
525 return name;
526 }
527 \&
528 void
529 la_activity (uintptr_t *cookie, unsigned int flag)
530 {
531 printf("la_activity(): cookie = %p; flag = %s\[rs]n", cookie,
532 (flag == LA_ACT_CONSISTENT) ? "LA_ACT_CONSISTENT" :
533 (flag == LA_ACT_ADD) ? "LA_ACT_ADD" :
534 (flag == LA_ACT_DELETE) ? "LA_ACT_DELETE" :
535 "???");
536 }
537 \&
538 unsigned int
539 la_objopen(struct link_map *map, Lmid_t lmid, uintptr_t *cookie)
540 {
541 printf("la_objopen(): loading \[rs]"%s\[rs]"; lmid = %s; cookie=%p\[rs]n",
542 map\->l_name,
543 (lmid == LM_ID_BASE) ? "LM_ID_BASE" :
544 (lmid == LM_ID_NEWLM) ? "LM_ID_NEWLM" :
545 "???",
546 cookie);
547 \&
548 return LA_FLG_BINDTO | LA_FLG_BINDFROM;
549 }
550 \&
551 unsigned int
552 la_objclose (uintptr_t *cookie)
553 {
554 printf("la_objclose(): %p\[rs]n", cookie);
555 \&
556 return 0;
557 }
558 \&
559 void
560 la_preinit(uintptr_t *cookie)
561 {
562 printf("la_preinit(): %p\[rs]n", cookie);
563 }
564 \&
565 uintptr_t
566 la_symbind32(Elf32_Sym *sym, unsigned int ndx, uintptr_t *refcook,
567 uintptr_t *defcook, unsigned int *flags, const char *symname)
568 {
569 printf("la_symbind32(): symname = %s; sym\->st_value = %p\[rs]n",
570 symname, sym\->st_value);
571 printf(" ndx = %u; flags = %#x", ndx, *flags);
572 printf("; refcook = %p; defcook = %p\[rs]n", refcook, defcook);
573 \&
574 return sym\->st_value;
575 }
576 \&
577 uintptr_t
578 la_symbind64(Elf64_Sym *sym, unsigned int ndx, uintptr_t *refcook,
579 uintptr_t *defcook, unsigned int *flags, const char *symname)
580 {
581 printf("la_symbind64(): symname = %s; sym\->st_value = %p\[rs]n",
582 symname, sym\->st_value);
583 printf(" ndx = %u; flags = %#x", ndx, *flags);
584 printf("; refcook = %p; defcook = %p\[rs]n", refcook, defcook);
585 \&
586 return sym\->st_value;
587 }
588 \&
589 Elf32_Addr
590 la_i86_gnu_pltenter(Elf32_Sym *sym, unsigned int ndx,
591 uintptr_t *refcook, uintptr_t *defcook, La_i86_regs *regs,
592 unsigned int *flags, const char *symname, long *framesizep)
593 {
594 printf("la_i86_gnu_pltenter(): %s (%p)\[rs]n", symname, sym\->st_value);
595 \&
596 return sym\->st_value;
597 }
598 .EE
599 .SH SEE ALSO
600 .BR ldd (1),
601 .BR dlopen (3),
602 .BR ld.so (8),
603 .BR ldconfig (8)