NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: kern/51514: ptrace(2) fails for 32-bit process on 64-bit kernel
The following reply was made to PR kern/51514; it has been noted by GNATS.
From: David Holland <dholland-bugs%netbsd.org@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc:
Subject: Re: kern/51514: ptrace(2) fails for 32-bit process on 64-bit kernel
Date: Sun, 16 Oct 2016 19:14:21 +0000
On Sun, Oct 16, 2016 at 06:35:00PM +0000, matthew green wrote:
> > /* XXX avoid sign extension problems with unknown upper bits? */
> > + regs->r_gs = tf->tf_gs & 0xffff;
> > + regs->r_fs = tf->tf_fs & 0xffff;
> > + regs->r_es = tf->tf_es & 0xffff;
> > + regs->r_ds = tf->tf_ds & 0xffff;
> > + regs->r_eflags = tf->tf_rflags;
> > @@ -501,9 +501,9 @@ netbsd32_process_read_regs(struct lwp *l
> > - regs->r_cs = tf->tf_cs;
> > + regs->r_cs = tf->tf_cs & 0xffff;
> > regs->r_esp = tf->tf_rsp & 0xffffffff;
> > - regs->r_ss = tf->tf_ss;
> > + regs->r_ss = tf->tf_ss & 0xffff;
>
> i wonder if there should be ASSERT()s that they're not set. there
> really should never be anything set here. x86-heads?
The way the amd64 trapframe structure is built (via cpp abuse) causes
the segment register fields to be uint64_t. Therefore as long as they
have i386 segment selector values in them, which are 16 bits wide,
everything should be ok... unless they're sign-extended 16-bit values.
I have no idea if they manifest that way in hardware (I would think it
unlikely) or if there's a way for them to get sign-extended in the
trapframe before they get here (also seems unlikely) but masking them
is cheap.
It shouldn't be possible for a 32-bit process to get a 64-bit segment
register value and it might be a good idea to assert that. Maybe
something like
assert(regs->r_gs == tf->tf_gs ||
regs->r_gs == ((uint64_t)(int64_t)(int16_t)tf->tf_gs))
The problem is that i386 segment selectors that are negative 16-bit
values only happen if you have that many segments ( >= 4096, i think,
but I can't remember for sure) and that is going to be rare even with
large programs in Wine. So it's probably a good idea to be paranoid
about it as getting it wrong will lead to lurking problems later.
--
David A. Holland
dholland%netbsd.org@localhost
Home |
Main Index |
Thread Index |
Old Index