Received: from [140.186.70.92] (port=57865 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PILu7-0002QH-Jg for qemu-devel@nongnu.org; Tue, 16 Nov 2010 08:49:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PILu6-0000EN-2C for qemu-devel@nongnu.org; Tue, 16 Nov 2010 08:48:59 -0500 Received: from mailout-de.gmx.net ([213.165.64.23]:47046 helo=mail.gmx.net) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1PILu5-0000Dj-I2 for qemu-devel@nongnu.org; Tue, 16 Nov 2010 08:48:58 -0500 From: =?utf-8?Q?Llu=C3=ADs?= Subject: Re: [Qemu-devel] How to make shadow memory for a process? and how to trace the data propation from the instruction level in QEMU? References: <87zktan6cd.fsf@ginnungagap.bsc.es> <1ab16.b343.12c490e9675.Coremail.qemustudy@163.com> <1bf16d2.1fa9e.12c5497e3a3.Coremail.qemustudy@163.com> Date: Tue, 16 Nov 2010 14:49:27 +0100 In-Reply-To: <1bf16d2.1fa9e.12c5497e3a3.Coremail.qemustudy@163.com> (F. Zhang's message of "Tue, 16 Nov 2010 20:10:29 +0800 (CST)") Message-ID: <87mxp9l6oo.fsf@ginnungagap.bsc.es> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org F Zhang writes: > This topic includes things that I recognized as critical. Have you any > suggestions? Sorry, I don't understand about what you want suggestions. >>>> =C2=A0Yes.=C2=A0For=C2=A0each=C2=A0process=E2=80=99s=C2=A0memory=C2=A0= space=C2=A0A,=C2=A0I=C2=A0wanna=C2=A0make=C2=A0a=C2=A0shadow=C2=A0memory=C2= =A0B.=C2=A0The >>>> =C2=A0shadow=C2=A0memory=C2=A0is=C2=A0used=C2=A0to=C2=A0store=C2=A0the= =C2=A0tag=C2=A0of=C2=A0data.=C2=A0In=C2=A0other=C2=A0words,=C2=A0if=C2=A0ad= dr=C2=A0in >>>> =C2=A0memory=C2=A0A=C2=A0is=C2=A0tainted,=C2=A0then=C2=A0the=C2=A0corr= esponding=C2=A0byte=C2=A0in=C2=A0B=C2=A0should=C2=A0be=C2=A0marked=C2=A0to >>>> =C2=A0indicate=C2=A0that=C2=A0addr=C2=A0in=C2=A0A=C2=A0is=C2=A0tainted. >>=20 >> The=C2=A0main=C2=A0question=C2=A0here=C2=A0is...=C2=A0what=C2=A0is=C2=A0= the=C2=A0granularity=C2=A0that=C2=A0you=C2=A0want=C2=A0to >> track=C2=A0with?=C2=A0Bytes?=C2=A0Words?=C2=A0Pages?=C2=A0This=C2=A0will= =C2=A0greatly=C2=A0influence=C2=A0which=C2=A0is >> your=C2=A0best=C2=A0approach. > I think one byte per tag is necessary for malware analysis in most cases, > because only a few bytes are used to launch an attack. For example, a few > tainted bytes sent to EIP register will cause CPU to do bad things. [...] >> Now=C2=A0that=C2=A0I=C2=A0think=C2=A0of=C2=A0it,=C2=A0you=C2=A0could=C2= =A0use=C2=A0the=C2=A0tracing=C2=A0points=C2=A0I=C2=A0sent=C2=A0for >> guest=C2=A0virtual=C2=A0memory=C2=A0accesses,=C2=A0and=C2=A0instrument= =C2=A0them=C2=A0instead=C2=A0of=C2=A0calling=C2=A0a >> file-tracing=C2=A0backend=C2=A0(this=C2=A0should=C2=A0provide=C2=A0a=C2= =A0hook=C2=A0for=C2=A0an=C2=A0arbitrary >> granularity).=C2=A0Then,=C2=A0simply=C2=A0keep=C2=A0track=C2=A0also=C2= =A0of=C2=A0address-space=C2=A0changes=C2=A0and >> your=C2=A0instrumentation=C2=A0code=C2=A0can=C2=A0always=C2=A0know=C2=A0= when=C2=A0to=C2=A0activate=C2=A0propagation. >>=20 > Sorry, what is =E2=80=9Ca file-tracing backend=E2=80=9D? Could you be a l= ittle more detailed? I > think I need byte-level granularity. Thanks! Well, the initial patch series I sent were based on macros, so that you can place any code you want on these macros, not only tracing. On its current form (sorry, I don't have spare time right now to finish it), the points generate code for tracing, but there is a patch series that lets the user re-define some of the trace points to call any function provided by the user (look for the "trace-instrument" series). >> This,=C2=A0together=C2=A0with=C2=A0the=C2=A0optimization=C2=A0I=C2=A0sen= t=C2=A0for=C2=A0dynamic=C2=A0control=C2=A0of=C2=A0trace >> generation=C2=A0in=C2=A0TCG=C2=A0emulation=C2=A0code=C2=A0should=C2=A0ge= t=C2=A0you=C2=A0on=C2=A0tracks. >>=20 >> Of=C2=A0course,=C2=A0you=C2=A0should=C2=A0still=C2=A0modify=C2=A0all=C2= =A0register-accessing=C2=A0instructions >> to=C2=A0propagate=C2=A0information=C2=A0passing=C2=A0through=C2=A0the=C2= =A0register=C2=A0set.=C2=A0For=C2=A0that, >> maybe=C2=A0you=C2=A0could=C2=A0start=C2=A0with=C2=A0the=C2=A0"fetch"=C2= =A0tracing/instrumentation=C2=A0point=C2=A0I >> sent=C2=A0long=C2=A0time=C2=A0ago,=C2=A0which=C2=A0keeps=C2=A0track=C2= =A0of=C2=A0general-purpose=C2=A0register >> usage/definition=C2=A0on=C2=A0x86=C2=A0(although=C2=A0I'm=C2=A0sure=C2= =A0I=C2=A0left=C2=A0some=C2=A0astray=C2=A0usages=C2=A0due >> to=C2=A0the=C2=A0decoding=C2=A0complexity=C2=A0in=C2=A0x86). > Thanks! I will read that code first, though I am currently just a newbie.= L >>>> =C2=A0The=C2=A0guest=C2=A0os=C2=A0collects=C2=A0=E2=80=9Chigher=E2=80= =9D=C2=A0semantic >>>> =C2=A0from=C2=A0the=C2=A0OS=C2=A0level,=C2=A0and=C2=A0the=C2=A0QEMU=C2= =A0collects=C2=A0=E2=80=9Clower=E2=80=9D=C2=A0semantic=C2=A0from=C2=A0the >>>> =C2=A0instruction=C2=A0level.=C2=A0Combination=C2=A0of=C2=A0both=C2=A0= semantics=C2=A0is=C2=A0necessary=C2=A0in=C2=A0the >>>> =C2=A0analysis=C2=A0process. >>=20 >>> =C2=A0The=C2=A0question=C2=A0is,=C2=A0in=C2=A0a=C2=A0situation=C2=A0whe= re=C2=A0malware=C2=A0already=C2=A0compromise=C2=A0"the >>> =C2=A0higher=C2=A0semantic",=C2=A0could=C2=A0we=C2=A0trust=C2=A0the=C2= =A0analysis? >>=20 >> Beware,=C2=A0I've=C2=A0read=C2=A0exactly=C2=A0this=C2=A0kind=C2=A0of=C2= =A0scheme=C2=A0on=C2=A0previous=C2=A0top-tier >> conferences=C2=A0(but=C2=A0I=C2=A0think=C2=A0tests=C2=A0were=C2=A0using= =C2=A0an=C2=A0architectural=C2=A0simulator,=C2=A0so >> it's=C2=A0not=C2=A0for=C2=A0a=C2=A0current=C2=A0production=C2=A0environm= ent). >>=20 >> I've=C2=A0found=C2=A0it=C2=A0:) >>=20 >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Secure=C2=A0program=C2=A0execution=C2=A0vi= a=C2=A0dynamic=C2=A0information=C2=A0flow=C2=A0tracking >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0ASPLOS=C2=A02004 >>=20 > That is a significant paper, which is=C2=A0cited for more than 300 times! That's why I said you should be careful. Porting this kind of analysis into QEMU is not significant by itself, although I suppose it should gain some extra relevance if you implement it in such a way that it can be used on a production system. You could start with guest OS taint propagation, and through the "guest OS to QEMU" channel, activate taint propagation checks when a process gains access to tainted information coming from the outer world (e.g., socket read) [*]. Then, you can conditionally generate taint checks like I did in the "trace-gen" series, so that programs without access to tainted information will have no checks at all. Even more, the optimal solution would be to run in KVM-mode when no instruction-based taint checking is needed, and use QEMU emulation otherwise. The down side is that I was told this is not currently possible with multiple CPUs, and only theoretically possible with one CPU. [*] This is just a rough summary of what I remember from the ASPLOS paper >>>> =C2=A0The=C2=A0question=C2=A0is:=C2=A0how=C2=A0to=C2=A0communicate=C2= =A0between=C2=A0the=C2=A0QEMU=C2=A0and=C2=A0the=C2=A0guest=C2=A0OS,=C2=A0so >>>> =C2=A0that=C2=A0they=C2=A0can=C2=A0cooperate=C2=A0with=C2=A0each=C2=A0= other? >>=20 >> A=C2=A0few=C2=A0choices=C2=A0here,=C2=A0but=C2=A0you=C2=A0should=C2=A0fi= rst=C2=A0define=C2=A0if=C2=A0the=C2=A0communication >> must=C2=A0be=C2=A0based=C2=A0just=C2=A0on=C2=A0control=C2=A0signals,=C2= =A0and/or=C2=A0providing=C2=A0memory=C2=A0storage: >> =C2=A0=C2=A0*=C2=A0virtual=C2=A0device=C2=A0:=C2=A0If=C2=A0you=C2=A0need= =C2=A0some=C2=A0kind=C2=A0of=C2=A0storage=C2=A0that=C2=A0the=C2=A0guest=C2= =A0OS >> =C2=A0=C2=A0=C2=A0=C2=A0must=C2=A0access,=C2=A0you=C2=A0could=C2=A0look= =C2=A0at=C2=A0the=C2=A0ivshmem=C2=A0device >> =C2=A0=C2=A0*=C2=A0backdoor=C2=A0instruction=C2=A0:=C2=A0It's=C2=A0the= =C2=A0simplest=C2=A0option;=C2=A0I=C2=A0sent=C2=A0some=C2=A0patch >> =C2=A0=C2=A0=C2=A0=C2=A0series=C2=A0recently=C2=A0with=C2=A0two=C2=A0dif= ferent=C2=A0implementations=C2=A0for=C2=A0x86. >>=20 >>=20 > Both of control signals and (shadow) memory storage are required. So, the > virtual device may be the right choice. Shadow memory is not a problem here, as it can be handled by the intrumented trace points and the guest OS has no need to access it. So from my understanding, just using an instruction-based backdoor is sufficient for the guest OS to tell QEMU when taint analysis propagation must be performed, and on which memory addresses it must start propagating. > In this year=E2=80=99s top security conferences (Oakland, CCS, Usenix Sec= urity, NDSS and > so on), many works are based on virtual technology. So I think QEMU is a = good > choice for future academic research.=20 I'm not much of a security expert, so I don't know what's the current state-of-the-art, but if you go on board on the journey of implementing this in QEMU, first make sure you can provide novel ideas and features on top of this infrastructure. Coding this kind of things is fun, but if it's just for the sake of coding, this won't get you publications (I remember reading that you are doing a PhD); believe me, I've gone through this before :) Lluis --=20 "And it's much the same thing with knowledge, for whenever you learn something new, the whole world becomes that much richer." -- The Princess of Pure Reason, as told by Norton Juster in The Phantom Tollbooth