From owner-freebsd-arch@FreeBSD.ORG Fri Apr 17 20:20:26 2015 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id DC6DAF1A; Fri, 17 Apr 2015 20:20:25 +0000 (UTC) Received: from mail-pd0-x22f.google.com (mail-pd0-x22f.google.com [IPv6:2607:f8b0:400e:c02::22f]) (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 ACE02849; Fri, 17 Apr 2015 20:20:25 +0000 (UTC) Received: by pdea3 with SMTP id a3so138484155pde.3; Fri, 17 Apr 2015 13:20:25 -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=Ym8QgtL5GIOuGOaoawUEKXcc0egt8RlUTwkYksP2btk=; b=kiTlutxAHST1qmUibmiEaZqpRNQJFXDcwZO8ZfJQdDOrofBf2YJheY3acHVmha3Bm2 EUVnmjgN+V13UxbpWc4R1wufBgJ1gY5BYsYDzAyRFHavavKL8pmyovQTglZJ3TWs+zpv 5fz2xT+WU58tIzCn1siBQ9/Zn6EBeKs3PX/g06Z8NqFVWMYGKdROvaLx4UvfRwnSUi1+ a6wC0ax3PPJHHhs2xu5SMOrigR3xR8UPpjKVV4Etgy/RaP2lV9o9Th3rH4/T85L8vJGZ dXl7AP8P2WFo9Xj2Q7jhu5rZR4WIfqVs4Lduxz6H8dqk31iy0zpV8pA+g+aGjNTuocKT lg5g== X-Received: by 10.70.95.228 with SMTP id dn4mr5311018pdb.89.1429302025203; Fri, 17 Apr 2015 13:20:25 -0700 (PDT) MIME-Version: 1.0 Sender: ycyc321@gmail.com Received: by 10.67.2.42 with HTTP; Fri, 17 Apr 2015 13:19:54 -0700 (PDT) In-Reply-To: <6048769.xVxqkDkTGK@ralph.baldwin.cx> References: <6048769.xVxqkDkTGK@ralph.baldwin.cx> From: Yue Chen Date: Fri, 17 Apr 2015 16:19:54 -0400 X-Google-Sender-Auth: F283DNDIXriyceavx1YIYuCWjgI Message-ID: Subject: Re: Situations about PC values in kernel data segments To: John Baldwin Cc: 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: Fri, 17 Apr 2015 20:20:26 -0000 I mean, the PC values in non-.text segments like .data, .rodata, stack, heap, etc. Usually this is for comparison purposes. E.g., compare the faulting PC against some range already stored in a table/handler. > When pcb_onfault is used it is set to point to code in a .text segment, not anywhere else. The pointer value stored in non-.text segments is a PC value (instruction address in .text), like 0xffffffff12345678, and may not be a function entry point address, right? On Fri, Apr 17, 2015 at 9:22 AM, 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. > > -- > John Baldwin >