sunrpc: Test case for clnt_create "unix" buffer overflow (bug 22542)
[glibc.git] / elf / dl-conflict.c
blob769afd581b7a7a79440ed78ee8bd2767467796fd
1 /* Resolve conflicts against already prelinked libraries.
2 Copyright (C) 2001-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If
17 not, see <https://www.gnu.org/licenses/>. */
19 #include <assert.h>
20 #include <errno.h>
21 #include <libintl.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <ldsodefs.h>
25 #include <sys/mman.h>
26 #include <sys/param.h>
27 #include <sys/types.h>
28 #include "dynamic-link.h"
30 /* Used at loading time solely for prelink executable. It is not called
31 concurrently so it is be safe to defined as static. */
32 static struct link_map *resolve_conflict_map __attribute__ ((__unused__));
34 /* This macro is used as a callback from the ELF_DYNAMIC_RELOCATE code. */
35 #define RESOLVE_MAP(map, scope, ref, version, flags) (*ref = NULL, NULL)
36 #define RESOLVE(ref, version, flags) (*ref = NULL, 0)
37 #define RESOLVE_CONFLICT_FIND_MAP(map, r_offset) \
38 do { \
39 while ((resolve_conflict_map->l_map_end < (ElfW(Addr)) (r_offset)) \
40 || (resolve_conflict_map->l_map_start > (ElfW(Addr)) (r_offset))) \
41 resolve_conflict_map = resolve_conflict_map->l_next; \
43 (map) = resolve_conflict_map; \
44 } while (0)
46 #include "dynamic-link.h"
48 void
49 _dl_resolve_conflicts (struct link_map *l, ElfW(Rela) *conflict,
50 ElfW(Rela) *conflictend)
52 #if ! ELF_MACHINE_NO_RELA
53 if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_RELOC))
54 _dl_debug_printf ("\nconflict processing: %s\n", DSO_FILENAME (l->l_name));
57 /* Do the conflict relocation of the object and library GOT and other
58 data. */
60 /* Prelinking makes no sense for anything but the main namespace. */
61 assert (l->l_ns == LM_ID_BASE);
62 resolve_conflict_map = GL(dl_ns)[LM_ID_BASE]._ns_loaded;
64 /* Override these, defined in dynamic-link.h. */
65 #undef CHECK_STATIC_TLS
66 #define CHECK_STATIC_TLS(ref_map, sym_map) ((void) 0)
67 #undef TRY_STATIC_TLS
68 #define TRY_STATIC_TLS(ref_map, sym_map) (0)
70 GL(dl_num_cache_relocations) += conflictend - conflict;
72 for (; conflict < conflictend; ++conflict)
73 elf_machine_rela (l, NULL, conflict, NULL, NULL,
74 (void *) conflict->r_offset, 0);
76 #endif