From owner-freebsd-arch@FreeBSD.ORG Fri Apr 17 13:43:54 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 4D42519D; Fri, 17 Apr 2015 13:43:54 +0000 (UTC) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D07E42FC; Fri, 17 Apr 2015 13:43:53 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.9/8.14.9) with ESMTP id t3HDhmgh052652 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Fri, 17 Apr 2015 16:43:48 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.9.2 kib.kiev.ua t3HDhmgh052652 Received: (from kostik@localhost) by tom.home (8.14.9/8.14.9/Submit) id t3HDhmQv052651; Fri, 17 Apr 2015 16:43:48 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Fri, 17 Apr 2015 16:43:48 +0300 From: Konstantin Belousov To: John Baldwin Cc: freebsd-arch@freebsd.org, Yue Chen Subject: Re: Situations about PC values in kernel data segments Message-ID: <20150417134348.GR2390@kib.kiev.ua> References: <6048769.xVxqkDkTGK@ralph.baldwin.cx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6048769.xVxqkDkTGK@ralph.baldwin.cx> User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on tom.home 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 13:43:54 -0000 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.