1 /* Support for STV_PROTECTED visibility.  Generic version.
2    Copyright (C) 2021 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4 
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
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9 
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.
14 
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, see
17    <https://www.gnu.org/licenses/>.  */
18 
19 #ifndef _DL_PROTECTED_H
20 #define _DL_PROTECTED_H
21 
22 static inline void __attribute__ ((always_inline))
_dl_check_protected_symbol(const char * undef_name,const struct link_map * undef_map,const ElfW (Sym)* ref,const struct link_map * map,int type_class)23 _dl_check_protected_symbol (const char *undef_name,
24 			    const struct link_map *undef_map,
25 			    const ElfW(Sym) *ref,
26 			    const struct link_map *map,
27 			    int type_class)
28 {
29   if (undef_map != NULL
30       && undef_map->l_type == lt_executable
31       && !(undef_map->l_1_needed
32 	   & GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS)
33       && (map->l_1_needed
34 	  & GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS))
35     {
36       if ((type_class & ELF_RTYPE_CLASS_COPY))
37 	/* Disallow copy relocations in executable against protected
38 	   data symbols in a shared object which needs indirect external
39 	   access.  */
40 	_dl_signal_error (0, map->l_name, undef_name,
41 			  N_("copy relocation against non-copyable protected symbol"));
42       else if (ref->st_value != 0
43 	       && ref->st_shndx == SHN_UNDEF
44 	       && (type_class & ELF_RTYPE_CLASS_PLT))
45 	/* Disallow non-zero symbol values of undefined symbols in
46 	   executable, which are used as the function pointer, against
47 	   protected function symbols in a shared object with indirect
48 	   external access.  */
49 	_dl_signal_error (0, map->l_name, undef_name,
50 			  N_("non-canonical reference to canonical protected function"));
51     }
52 }
53 
54 #endif /* _DL_PROTECTED_H */
55