1 /* Support for GNU properties. x86 version.
2 Copyright (C) 2018-2020 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
7 License as published by the Free Software Foundation; either
8 version 2.1 of the 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; if not, see
17 <https://www.gnu.org/licenses/>. */
22 extern void _dl_cet_check (struct link_map
*, const char *)
24 extern void _dl_cet_open_check (struct link_map
*)
27 static inline void __attribute__ ((always_inline
))
28 _rtld_main_check (struct link_map
*m
, const char *program
)
31 _dl_cet_check (m
, program
);
35 static inline void __attribute__ ((always_inline
))
36 _dl_open_check (struct link_map
*m
)
39 _dl_cet_open_check (m
);
43 static inline void __attribute__ ((unused
))
44 _dl_process_cet_property_note (struct link_map
*l
,
45 const ElfW(Nhdr
) *note
,
46 const ElfW(Addr
) size
,
47 const ElfW(Addr
) align
)
50 /* Skip if we have seen a NT_GNU_PROPERTY_TYPE_0 note before. */
51 if (l
->l_cet
!= lc_unknown
)
54 /* The NT_GNU_PROPERTY_TYPE_0 note must be aliged to 4 bytes in
55 32-bit objects and to 8 bytes in 64-bit objects. Skip notes
56 with incorrect alignment. */
57 if (align
!= (__ELF_NATIVE_CLASS
/ 8))
60 const ElfW(Addr
) start
= (ElfW(Addr
)) note
;
62 unsigned int feature_1
= 0;
63 unsigned int last_type
= 0;
65 while ((ElfW(Addr
)) (note
+ 1) - start
< size
)
67 /* Find the NT_GNU_PROPERTY_TYPE_0 note. */
68 if (note
->n_namesz
== 4
69 && note
->n_type
== NT_GNU_PROPERTY_TYPE_0
70 && memcmp (note
+ 1, "GNU", 4) == 0)
72 /* Stop if we see more than one GNU property note which may
73 be generated by the older linker. */
74 if (l
->l_cet
!= lc_unknown
)
77 /* Check CET status now. */
80 /* Check for invalid property. */
81 if (note
->n_descsz
< 8
82 || (note
->n_descsz
% sizeof (ElfW(Addr
))) != 0)
85 /* Start and end of property array. */
86 unsigned char *ptr
= (unsigned char *) (note
+ 1) + 4;
87 unsigned char *ptr_end
= ptr
+ note
->n_descsz
;
91 unsigned int type
= *(unsigned int *) ptr
;
92 unsigned int datasz
= *(unsigned int *) (ptr
+ 4);
94 /* Property type must be in ascending order. */
99 if ((ptr
+ datasz
) > ptr_end
)
104 if (type
== GNU_PROPERTY_X86_FEATURE_1_AND
)
106 /* The size of GNU_PROPERTY_X86_FEATURE_1_AND is 4
107 bytes. When seeing GNU_PROPERTY_X86_FEATURE_1_AND,
108 we stop the search regardless if its size is correct
109 or not. There is no point to continue if this note
114 feature_1
= *(unsigned int *) ptr
;
116 /* Keep searching for the next GNU property note
117 generated by the older linker. */
120 else if (type
> GNU_PROPERTY_X86_FEATURE_1_AND
)
122 /* Stop since property type is in ascending order. */
126 /* Check the next property item. */
127 ptr
+= ALIGN_UP (datasz
, sizeof (ElfW(Addr
)));
129 while ((ptr_end
- ptr
) >= 8);
132 /* NB: Note sections like .note.ABI-tag and .note.gnu.build-id are
133 aligned to 4 bytes in 64-bit ELF objects. */
134 note
= ((const void *) note
135 + ELF_NOTE_NEXT_OFFSET (note
->n_namesz
, note
->n_descsz
,
139 /* We get here only if there is one or no GNU property note. */
140 if ((feature_1
& GNU_PROPERTY_X86_FEATURE_1_IBT
))
142 if ((feature_1
& GNU_PROPERTY_X86_FEATURE_1_SHSTK
))
143 l
->l_cet
|= lc_shstk
;
147 static inline void __attribute__ ((unused
))
148 _dl_process_pt_note (struct link_map
*l
, const ElfW(Phdr
) *ph
)
150 const ElfW(Nhdr
) *note
= (const void *) (ph
->p_vaddr
+ l
->l_addr
);
151 _dl_process_cet_property_note (l
, note
, ph
->p_memsz
, ph
->p_align
);
154 static inline int __attribute__ ((always_inline
))
155 _dl_process_gnu_property (struct link_map
*l
, uint32_t type
, uint32_t datasz
,
161 #endif /* _DL_PROP_H */