From owner-freebsd-arch@FreeBSD.ORG Mon Apr 20 17:54:59 2015 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id BC82E492; Mon, 20 Apr 2015 17:54:59 +0000 (UTC) Received: from mail-pd0-x235.google.com (mail-pd0-x235.google.com [IPv6:2607:f8b0:400e:c02::235]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 8C5A08CB; Mon, 20 Apr 2015 17:54:59 +0000 (UTC) Received: by pdbnk13 with SMTP id nk13so214586174pdb.0; Mon, 20 Apr 2015 10:54:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=BzQ2EDGwWtpvze1UGBSVKQ79bAvFKTqxACeNzxpg2/0=; b=Cg4SKavCUPdNXM1FvlvClp1tjVxitQvI1xvwPd7fs0MWpKrF+FILLytgMczYhUV5ih JRTyTBUtm3STGTV3HElSWFFZ+v0ZwdbVR1Lb+EF+EtcufN49W9kgqGf1iSWfm42ZpCP0 9qDbgO2zsZxS3AGaMiUxE1863OzOn+YnqPZujUJqIfZzCqxCydA7IdvUHji3Jvm/7LQK sDM0PjKBf0dz05i56CiwUk/UB9WudUX0Y6UG7kPB2EJ/ziS2Y4uyf+DvNcCYbX1A0ZIT ZbbDNSqUUSN7UqDh3JeWzm5N87+Hw45bNSA88tPA0plJ+S64pU2TTM+w38cYn6sr1K19 ZM8A== X-Received: by 10.68.198.36 with SMTP id iz4mr30326080pbc.167.1429552499005; Mon, 20 Apr 2015 10:54:59 -0700 (PDT) MIME-Version: 1.0 Sender: ycyc321@gmail.com Received: by 10.67.2.42 with HTTP; Mon, 20 Apr 2015 10:54:28 -0700 (PDT) In-Reply-To: <2177000.nIlZYR4khO@ralph.baldwin.cx> References: <6048769.xVxqkDkTGK@ralph.baldwin.cx> <20150417134348.GR2390@kib.kiev.ua> <2177000.nIlZYR4khO@ralph.baldwin.cx> From: Yue Chen Date: Mon, 20 Apr 2015 13:54:28 -0400 X-Google-Sender-Auth: isyFUP2m2B1Ueftn4cDC44aZPs0 Message-ID: Subject: Re: Situations about PC values in kernel data segments To: John Baldwin Cc: Konstantin Belousov , freebsd-arch@freebsd.org Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.20 X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Apr 2015 17:54:59 -0000 > Are you asking if you can figure out if a given PC value used as the value > of $rip for an arbitrary instruction is valid, or are you trying to enumerate > all the words in memory that hold a pointer to a .text value (like > pcb_onfault)? > I assumed the former. So sorry for the confusion. I mean any other situations of the *latter* one, which *excludes* function pointers. And this does not have to be a full-word pointer. This can be a half-word displacement/offset to the address in .text, or a special encoding of the address as well. On Mon, Apr 20, 2015 at 11:00 AM, John Baldwin wrote: > On Friday, April 17, 2015 04:43:48 PM Konstantin Belousov wrote: > > On Fri, Apr 17, 2015 at 09:22:43AM -0400, John Baldwin wrote: > > > On Saturday, April 11, 2015 05:18:28 AM Yue Chen wrote: > > > > Dear all, > > > > > > > > We are working on a project about OS security. > > > > We wonder in which situations the program counter (PC) value (e.g., > the > > > > value in %RIP on x86_64, i.e, instruction address) could be in kernel > > > > (module) data segments (including stack, heap, etc.). > > > > > > > > Here we mainly care about the address/value that are NOT function > entry > > > > points since there exist a number of function pointers. Also, we only > > > > consider the normal cases because one can write arbitrary values > into a > > > > variable/pointer. And we mainly consider i386, AMD64 and ARM. > > > > > > > > Here are some situations I can think about: > > > > function/interrupt/exception/syscall return address on stack; > switch/case > > > > jump table target; page fault handler (pcb_onfault on *BSD); > restartable > > > > atomic sequences (RAS) registry; thread/process context structure > like Task > > > > state segment (TSS), process control block (PCB) and thread control > block > > > > (TCB); situations for debugging purposes (e.g., like those in > ``segment not > > > > present'' exception handler). > > > > > > > > Additionally, does any of these addresses have offset formats or > special > > > > encodings? For example, on x86_64, we may use 32-bit RIP-relative > > > > (addressing) offset to represent a 64-bit full address. In glibc's > > > > setjmp/longjmp jmp_buf, they use a special encoding (PTR_MANGLE) for > saved > > > > register values. > > > > > > For i386 and amd64, I think all of the code that is executed does live > in a > > > .text segment. When pcb_onfault is used it is set to point to code in > a .text > > > segment, not anywhere else. Similarly, fault and exception handlers > as well > > > as the stub for new threads/processes after fork/thread_create is in > .text > > > as well. There are multiple text segments present when modules are > loaded > > > of course, but you should be able to enumerate all of those in the > linker. > > > > Wasn't bpf enhanced to compile filters to the native code, on x86 ? > > Also, what about BIOS code ? Esp. since the spread of UEFI and hope that > > our kernel starts using UEFI runtime services one day. My point is that > > _relying_ on enumeration of the text segments for kernel and modules to > > determine all executable memory is not correct. > > It depends on the scope. If this is for a graduate research project to > build > a prototype to see if this is feasible, then some cavets are acceptable if > they are known. One could be to disallow the bpf JIT option (I believe it > is > not in GENERIC)? EFI is actually fairly easily handled since the EFI > memory > map gives you the bounds of the executable code and you can just treat > that as > an additional .text segment. > > -- > John Baldwin >