From owner-freebsd-hackers@FreeBSD.ORG Thu Feb 23 01:06:22 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7AE3D106566C for ; Thu, 23 Feb 2012 01:06:22 +0000 (UTC) (envelope-from rysto32@gmail.com) Received: from mail-ww0-f50.google.com (mail-ww0-f50.google.com [74.125.82.50]) by mx1.freebsd.org (Postfix) with ESMTP id D37448FC13 for ; Thu, 23 Feb 2012 01:06:21 +0000 (UTC) Received: by wgbdq11 with SMTP id dq11so574972wgb.31 for ; Wed, 22 Feb 2012 17:06:20 -0800 (PST) Received-SPF: pass (google.com: domain of rysto32@gmail.com designates 10.216.137.147 as permitted sender) client-ip=10.216.137.147; Authentication-Results: mr.google.com; spf=pass (google.com: domain of rysto32@gmail.com designates 10.216.137.147 as permitted sender) smtp.mail=rysto32@gmail.com; dkim=pass header.i=rysto32@gmail.com Received: from mr.google.com ([10.216.137.147]) by 10.216.137.147 with SMTP id y19mr328654wei.5.1329959180811 (num_hops = 1); Wed, 22 Feb 2012 17:06:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=2EbzRYbNw/g7GOhOH6cG9zyP/nDgZbz9BboofwvdOnU=; b=VGNeaJWTn+9vq4o0PhyLRV3YZCKUVoO1R8Q0hJyY0y53uDDZf5ew6nQhQjAW2ASDSe GyYmdceae4jA9GgpVopI0p298Xz0NOL/rQFei8zdTG/9wIBebhWx4X1zyjLRekVONIJL aseNZD9DetRKHOqSYUMgtA3wkmCF9pzZBZMYk= MIME-Version: 1.0 Received: by 10.216.137.147 with SMTP id y19mr271904wei.5.1329959180717; Wed, 22 Feb 2012 17:06:20 -0800 (PST) Received: by 10.180.75.41 with HTTP; Wed, 22 Feb 2012 17:06:20 -0800 (PST) In-Reply-To: <1329938141.21804.4.camel@revolution.hippie.lan> References: <1329938141.21804.4.camel@revolution.hippie.lan> Date: Wed, 22 Feb 2012 20:06:20 -0500 Message-ID: From: Ryan Stone To: Ian Lepore Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: freebsd-hackers@freebsd.org, Svetlin Manavski Subject: Re: How to access kernel memory from user space X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Feb 2012 01:06:22 -0000 On Wed, Feb 22, 2012 at 2:15 PM, Ian Lepore wrote: > I've never done this, but if I needed to, I think the first thing I'd > try is to use an mmap(2) of /dev/kmem to map the memory you need into > userspace (of course your userspace app will need to be running with > root privs to do this). > > That leaves the interesting problem of locating what offset within the > kernel virtual address space you need to map to get at your data. =A0Two > things come to mind... have your kernel module export the address in a > sysctl (that feels kind of hack-ish but it should be quick and easy to > do), or use libkvm's kvm_nlist() function to locate the symbol within > your module (I think that should be possible; again I've never actually > done any of this). A far easier way to do this is to have the module create its own device in /dev that exports the memory by implementing the mmap interface in the cdev.