Lines Matching refs:dso
24 * functions. These two functions will be called before visiting other dso's resources. The responsibility is to
25 * calculate the __cfi_check() of the target dso, and call it. So use CFI shadow and shadow value to store the
26 * relationship between dso and its __cfi_check addr while loading a dso. CFI shadow is an array which stores shadow
28 * each dso will be mapped to one or more shadow values in the CFI shadow, this depends on the address range of the
29 * dso.
31 * - invalid(0) : the target addr does not belongs to any loaded dso.
32 * - uncheck(1) : this LIBRARY_ALIGNMENT memory range belongs to a dso but it is no need to do the CFI check.
33 * - valid(2 - 0xFFFF) : this LIBRARY_ALIGNMENT memory range belongs to a dso and need to do the CFI check.
35 * of the dso (The unit is 4096, because the __cfi_check is aligned with 4096).
39 * N : starts at 0, is the index of LIBRARY_ALIGNMENT memory range that belongs to a dso.
42 * Below is a example for calculating shadow values of a dso.
66 * In order for the algorithm to work well, the start addr of each dso should be aligned with LIBRARY_ALIGNMENT. */
92 static struct dso *dso_list_head = NULL;
94 static struct dso *pldso = NULL;
95 static struct dso *r_app = NULL;
96 static struct dso *r_vdso = NULL;
101 * - removing a dso. */
105 * - the DSO enabled CFI Cross-Dso, but this DSO is larger than 16G, for the part of the dso that exceeds 16G,
122 static int add_dso_to_cfi_shadow(struct dso *dso);
125 /* Find the __cfi_check() of target dso and call it */
136 static struct symdef find_cfi_check_sym(struct dso *p)
146 static int addr_in_dso(struct dso *dso, size_t addr)
148 Phdr *ph = dso->phdr;
149 size_t phcnt = dso->phnum;
150 size_t entsz = dso->phentsize;
151 size_t base = (size_t)dso->base;
187 LD_LOGD("[CFI] [%{public}s] cfi_check_func_addr[%{public}p] in dso[%{public}s]\n",
188 __FUNCTION__, cfi_check_func_addr, ((struct dso *)addr2dso((size_t)cfi_check_func_addr))->name);
227 ((struct dso *)addr2dso((size_t)__builtin_return_address(0)))->name,
228 ((struct dso *)addr2dso((size_t)func_ptr))->name,
231 struct dso *dso = NULL;
249 dso = (struct dso *)addr2dso((size_t)__builtin_return_address(0));
250 if (dso == NULL) {
251 LD_LOGE("[CFI] [%{public}s] can not find matched dso of %{public}p !\n",
255 LD_LOGD("[CFI] [%{public}s] dso name[%{public}s]!\n", __FUNCTION__, dso->name);
257 struct symdef cfi_check_sym = find_cfi_check_sym(dso);
259 LD_LOGE("[CFI] [%{public}s] can not find the __cfi_check in the dso!\n", __FUNCTION__);
263 LADDR(cfi_check_sym.dso, cfi_check_sym.sym->st_value));
264 ((cfi_check_t)LADDR(cfi_check_sym.dso, cfi_check_sym.sym->st_value))(call_site_type_id, func_ptr, diag_data);
276 int init_cfi_shadow(struct dso *dso_list, struct dso *ldso, struct dso *app, struct dso *vdso)
285 /* Save the head node of dso list */
294 int map_dso_to_cfi_shadow(struct dso *dso)
298 if (dso == NULL) {
305 /* Find __cfi_check symbol in dso list */
306 for (struct dso *p = dso; p; p = p->next) {
308 LD_LOGD("[CFI] [%{public}s] find __cfi_check function in dso %{public}s!\n", __FUNCTION__, p->name);
326 /* If the cfi shadow exists, map the current dso and its dependents to it. */
328 if (add_dso_to_cfi_shadow(dso) == CFI_FAILED) {
337 void unmap_dso_from_cfi_shadow(struct dso *dso)
339 if (dso == NULL) {
344 LD_LOGD("[CFI] [%{public}s] unmap dso %{public}s from shadow!\n", __FUNCTION__, dso->name);
349 if (dso->map == 0 || dso->map_len == 0)
352 if (dso->is_mapped_to_shadow == false)
355 if (((size_t)dso->map & (LIBRARY_ALIGNMENT - 1)) != 0) {
356 if (!(dso == pldso || dso == r_app || dso == r_vdso)) {
359 dso->name, LIBRARY_ALIGNMENT, dso->map, dso->map + dso->map_len, 0, sv_invalid);
363 /* Set the dso's shadow value as invalid. */
364 fill_shadow_value_to_shadow(dso->map, dso->map + dso->map_len, 0, sv_invalid);
365 dso->is_mapped_to_shadow = false;
392 static int add_dso_to_cfi_shadow(struct dso *dso)
394 LD_LOGD("[CFI] [%{public}s] start with %{public}s !\n", __FUNCTION__, dso->name);
395 for (struct dso *p = dso; p; p = p->next) {
398 LD_LOGW("[CFI] [%{public}s] the dso has no data! map[%{public}p] map_len[0x%{public}x]\n",
409 /* If the dso doesn't have __cfi_check(), set it's shadow value unchecked. */
413 if (((size_t)dso->map & (LIBRARY_ALIGNMENT - 1)) != 0) {
414 if (!(dso == pldso || dso == r_app || dso == r_vdso)) {
417 dso->name, LIBRARY_ALIGNMENT, dso->map, dso->map + dso->map_len, 0, sv_uncheck);
422 LD_LOGE("[CFI] [%{public}s] add dso to cfi shadow failed!\n", __FUNCTION__);
425 /* If the dso has __cfi_check(), set it's shadow value valid. */
429 uintptr_t cfi_check = LADDR(cfi_check_sym.dso, cfi_check_sym.sym->st_value);
449 if (((size_t)dso->map & (LIBRARY_ALIGNMENT - 1)) != 0) {
450 if (!(dso == pldso || dso == r_app || dso == r_vdso)) {
453 dso->name, LIBRARY_ALIGNMENT, dso->map, dso->map + dso->map_len, cfi_check, sv_valid_min);
465 LD_LOGD("[CFI] [%{public}s] %{public}s done.\n", __FUNCTION__, dso->name);
509 /* If the dso has __cfi_check(), calculate valid shadow value */
557 LD_LOGD("[CFI] [%{public}s] called from dso[%{public}s] to dso[%{public}s] func_ptr[%{public}p]\n",
559 ((struct dso *)addr2dso((size_t)__builtin_return_address(0)))->name,
560 ((struct dso *)addr2dso((size_t)func_ptr))->name,
569 LD_LOGD("[CFI] [%{public}s] called from dso[%{public}s] to dso[%{public}s] func_ptr[%{public}p]\n",
571 ((struct dso *)addr2dso((size_t)__builtin_return_address(0)))->name,
572 ((struct dso *)addr2dso((size_t)func_ptr))->name,