Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i#7229: Fix --fsanitize=pointer-overflow reports #7234

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion clients/drcachesim/tracer/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,8 +831,10 @@ output_buffer(void *drcontext, per_thread_t *data, byte *buf_base, byte *buf_ptr
if (mode != BBDUP_MODE_L0_FILTER)
data->bytes_written += buf_ptr - pipe_start;
bool is_v2p = false;
if (buf_base >= data->v2p_buf && buf_base < data->v2p_buf + get_v2p_buffer_size())
if (buf_base >= data->v2p_buf &&
static_cast<size_t>(buf_base - data->v2p_buf) < get_v2p_buffer_size()) {
is_v2p = true;
}
if (is_v2p)
++data->num_v2p_writeouts;
else
Expand Down
6 changes: 3 additions & 3 deletions core/arch/x86/mangle.c
Original file line number Diff line number Diff line change
Expand Up @@ -3710,7 +3710,7 @@ sandbox_top_of_bb(dcontext_t *dcontext, instrlist_t *ilist, bool s2ro, uint flag
#endif
PRE(ilist, instr,
INSTR_CREATE_mov_imm(dcontext, opnd_create_reg(REG_XCX),
OPND_CREATE_INTPTR(end_pc - (start_pc + 1))));
OPND_CREATE_INTPTR(end_pc - start_pc + 1)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be end_pc - start_pc - 1.
It's also the cause for (at least some) Github CI tests failing/timing-out (e.g., security-common.selfmod2).

/* i#2155: In the case where the direction flag is set, xsi will be lesser
* than start_pc after cmps, and the jump branch will not be taken.
*/
Expand Down Expand Up @@ -3933,8 +3933,8 @@ set_selfmod_sandbox_offsets(dcontext_t *dcontext)
sandbox_top_of_bb(dcontext, &ilist, selfmod_s2ro[i], selfmod_eflags[j],
/* we must have a >1-byte region to get
* both patch points */
app_start, app_start + 2, false, &patch, &start_pc,
&end_pc);
app_start, (app_pc)((ptr_uint_t)app_start + 2), false,
&patch, &start_pc, &end_pc);
/* The exit cti's may not reachably encode (normally
* they'd be mangled away) so we munge them first
*/
Expand Down
16 changes: 8 additions & 8 deletions core/unix/module_elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ elf_dt_abs_addr(ELF_DYNAMIC_ENTRY_TYPE *dyn, app_pc base, size_t size, size_t vi
app_pc tgt = (app_pc)dyn->d_un.d_ptr;
if (at_map || !dyn_reloc || tgt < base || tgt > base + size) {
/* not relocated, adjust by load_delta */
tgt = (app_pc)dyn->d_un.d_ptr + load_delta;
tgt = (app_pc)(dyn->d_un.d_ptr + load_delta);
}

/* sanity check location */
Expand Down Expand Up @@ -220,7 +220,7 @@ module_fill_os_data(ELF_PROGRAM_HEADER_TYPE *prog_hdr, /* PT_DYNAMIC entry */
bool res = true;
ELF_DYNAMIC_ENTRY_TYPE *dyn =
(ELF_DYNAMIC_ENTRY_TYPE *)(at_map ? base + prog_hdr->p_offset
: (app_pc)prog_hdr->p_vaddr + load_delta);
: (app_pc)(prog_hdr->p_vaddr + load_delta));
ASSERT(prog_hdr->p_type == PT_DYNAMIC);
dcontext_t *dcontext = get_thread_private_dcontext();
/* i#489, DT_SONAME is optional, init soname to NULL first */
Expand Down Expand Up @@ -384,7 +384,7 @@ module_walk_program_headers(app_pc base, size_t view_size, bool at_map, bool dyn
last_seg_align = prog_hdr->p_align;
module_add_segment_data(
out_data, elf_hdr->e_phnum,
(app_pc)prog_hdr->p_vaddr + load_delta, prog_hdr->p_memsz,
(app_pc)(prog_hdr->p_vaddr + load_delta), prog_hdr->p_memsz,
module_segment_prot_to_osprot(prog_hdr), prog_hdr->p_align,
false /*!shared*/, prog_hdr->p_offset);
}
Expand Down Expand Up @@ -570,7 +570,7 @@ module_entry_point(app_pc base, ptr_int_t load_delta)
{
ELF_HEADER_TYPE *elf_hdr = (ELF_HEADER_TYPE *)base;
ASSERT(is_elf_so_header(base, 0));
return (app_pc)elf_hdr->e_entry + load_delta;
return (app_pc)(elf_hdr->e_entry + load_delta);
}

bool
Expand Down Expand Up @@ -835,8 +835,8 @@ module_has_text_relocs(app_pc base, bool at_map)
for (i = 0; i < elf_hdr->e_phnum; i++) {
if (prog_hdr->p_type == PT_DYNAMIC) {
dyn = (ELF_DYNAMIC_ENTRY_TYPE *)(at_map ? (base + prog_hdr->p_offset)
: ((app_pc)prog_hdr->p_vaddr +
load_delta));
: (app_pc)(prog_hdr->p_vaddr +
load_delta));
break;
}
prog_hdr++;
Expand Down Expand Up @@ -1033,7 +1033,7 @@ module_get_os_privmod_data(app_pc base, size_t size, bool dyn_reloc,
/* TLS (Thread Local Storage) relocation information */
pd->tls_block_size = prog_hdr->p_memsz;
pd->tls_align = prog_hdr->p_align;
pd->tls_image = (app_pc)prog_hdr->p_vaddr + load_delta;
pd->tls_image = (app_pc)(prog_hdr->p_vaddr + load_delta);
pd->tls_image_size = prog_hdr->p_filesz;
if (pd->tls_align == 0)
pd->tls_first_byte = 0;
Expand Down Expand Up @@ -1092,7 +1092,7 @@ module_get_relro(app_pc base, DR_PARAM_OUT app_pc *relro_base,
mod_base =
module_vaddr_from_prog_header(base + ehdr->e_phoff, ehdr->e_phnum, NULL, NULL);
load_delta = base - mod_base;
*relro_base = (app_pc)phdr->p_vaddr + load_delta;
*relro_base = (app_pc)(phdr->p_vaddr + load_delta);
*relro_size = phdr->p_memsz;
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion core/unix/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -5072,7 +5072,8 @@ record_pending_signal(dcontext_t *dcontext, int sig, kernel_ucontext_t *ucxt,
}
}
}
} else if (get_at_syscall(dcontext) && pc == vsyscall_sysenter_return_pc - syslen &&
} else if (get_at_syscall(dcontext) &&
(ptr_uint_t)pc == ((ptr_uint_t)vsyscall_sysenter_return_pc - syslen) &&
/* See i#2995 comment above: rule out sigreturn */
!is_sigreturn_syscall_number(sc->SC_SYSNUM_REG)) {
LOG(THREAD, LOG_ASYNCH, 2,
Expand Down
3 changes: 2 additions & 1 deletion core/vmareas.c
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,8 @@ static bool
lookup_addr(vm_area_vector_t *v, app_pc addr, vm_area_t **area)
{
/* binary search asserts v is protected */
return binary_search(v, addr, addr + 1 /*open end*/, area, NULL, false);
return binary_search(v, addr, (app_pc)((ptr_uint_t)addr + 1) /*open end*/, area, NULL,
false);
}

/* returns true if the passed in area overlaps any known executable areas
Expand Down
4 changes: 2 additions & 2 deletions ext/drcovlib/modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ event_module_load(void *drcontext, const module_data_t *data, bool loaded)
if (module_load_cb != NULL)
sub_entry->custom = module_load_cb(sub_entry->data, j);
sub_entry->offset = data->segments[j].offset;
sub_entry->preferred_base =
(sub_entry->start - entry->start) + entry->preferred_base;
sub_entry->preferred_base = (app_pc)((sub_entry->start - entry->start) +
(ptr_uint_t)entry->preferred_base);
drvector_append(&module_table.vector, sub_entry);
global_module_cache_add(module_table.cache, sub_entry);
}
Expand Down
Loading