Merge pull request #4601 from alexnask/fix_3997

Allow wrapping in VDSO lookup
This commit is contained in:
Andrew Kelley 2020-03-03 09:15:40 -05:00 committed by GitHub
commit 387418277a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -22,7 +22,11 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
}) {
const this_ph = @intToPtr(*elf.Phdr, ph_addr);
switch (this_ph.p_type) {
elf.PT_LOAD => base = vdso_addr + this_ph.p_offset - this_ph.p_vaddr,
// On WSL1 as well as older kernels, the VDSO ELF image is pre-linked in the upper half
// of the memory space (e.g. p_vaddr = 0xffffffffff700000 on WSL1).
// Wrapping operations are used on this line as well as subsequent calculations relative to base
// (lines 47, 78) to ensure no overflow check is tripped.
elf.PT_LOAD => base = vdso_addr +% this_ph.p_offset -% this_ph.p_vaddr,
elf.PT_DYNAMIC => maybe_dynv = @intToPtr([*]usize, vdso_addr + this_ph.p_offset),
else => {},
}
@ -40,7 +44,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
{
var i: usize = 0;
while (dynv[i] != 0) : (i += 2) {
const p = base + dynv[i + 1];
const p = base +% dynv[i + 1];
switch (dynv[i]) {
elf.DT_STRTAB => maybe_strings = @intToPtr([*]u8, p),
elf.DT_SYMTAB => maybe_syms = @intToPtr([*]elf.Sym, p),
@ -71,7 +75,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
if (!checkver(maybe_verdef.?, versym[i], vername, strings))
continue;
}
return base + syms[i].st_value;
return base +% syms[i].st_value;
}
return 0;