From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Stefan Berger" Subject: Re: [RFC PATCH 3/4] Implement driver for supporting multiple emulated TPMs Date: Thu, 21 Jan 2016 14:02:17 -0500 Message-ID: <201601211912.u0LJCTxv029932@d03av04.boulder.ibm.com> References: <1452787318-29610-1-git-send-email-stefanb@us.ibm.com> <1452787318-29610-4-git-send-email-stefanb@us.ibm.com> <20160119235107.GA4307@obsidianresearch.com> <201601201439.u0KEdFao027907@d03av05.boulder.ibm.com> <20160121011701.GA20361@obsidianresearch.com> <201601210301.u0L31h5r012187@d03av03.boulder.ibm.com> <20160121032115.GA26266@obsidianresearch.com> <201601210356.u0L3uP1n029818@d03av05.boulder.ibm.com> <20160121174243.GD3064@obsidianresearch.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============7396022361502378255==" Return-path: In-Reply-To: <20160121174243.GD3064-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: tpmdd-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org To: Jason Gunthorpe Cc: dhowells-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org, tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org, dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org List-Id: tpmdd-devel@lists.sourceforge.net --===============7396022361502378255== Content-Type: multipart/alternative; boundary="=_alternative 006895CA85257F41_=" --=_alternative 006895CA85257F41_= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="US-ASCII" Jason Gunthorpe wrote on 01/21/2016=20 12:42:43 PM: >=20 > On Wed, Jan 20, 2016 at 10:56:21PM -0500, Stefan Berger wrote: > > The IMA namespace is created as part of clone(). You cannot pass=20 > anything via > > clone(). So you either have to do it before or immediately after.=20 > If after is > > too later for whatever reason, you have to do it before. >=20 > Follow the pattern of something like the net ns. >=20 > clone creates an 'empty' IMA namespace. After clone the child waits > for the parent to complete its work. >=20 > The parent creates a new vtpm /dev/tpm1 in it's namespace >=20 > The parent does a kernel call to make tpm1 visiable in the child's > IMA namespace as tpm0. (eg look at the 'ip link set .. netns ..' kind > of scheme for inspiration) What is IMA namespace in relation to a device's name? The method is to=20 read the major/minor numbers on the host and created /dev/tpm0 with the=20 same major/minor numbers in the container's filesystem. The name doesn't=20 matter I guess, but major/minor are important. >=20 > Hook the tpm core's id to struct tpm=5Fchip code into the IMA namespace > so that /dev/tpm0 and all other places actually access tpm1 when used > in the child's IMA namespace >=20 > The parent signals the child to continue to run. The child has a > /dev/tpm0 that is actually routed to /dev/tpm1. The child is prevented > from accessing other tpms. The problem I have run into in particular with Docker and golang is that=20 Docker invokes the golang function to run an external program. The golang=20 function does a clone(), a whole lot of other stuff after it, and in the=20 end the execve(). The code is here: https://golang.org/src/syscall/exec=5Flinux.go Look at the function forkAndExecInChild on line 56++. The problem with that is that the execve() will trigger IMA measurements.=20 IMA will refuse being hooked up with a vTPM driver if it couldn't put its=20 first measurement(s) into a vTPM. I don't think we should queue PCR=20 extensions until a device may eventually become available. So, the=20 conclusion is, to accomodate golang (for example) we can create the device = pair, sit the vTPM on top of the master, and reserve the device pair befor = the next clone() so that IMA finds it and can hook up to it.=20 What is wrong with this scheme? The ioctl for 'reservation' before the=20 clone()? >=20 >=20 > > > Then just return the fd like I said. > >=20 > > Any driver that can be used as an example ? >=20 > The stuff in include/linux/anon=5Finodes.h is used to do this, eg > a sequence of anon=5Finode=5Fgetfile, get=5Funused=5Ffd=5Fflags, fd=5Fins= tall > will create a file descriptor in the calling process associated with a > struct file=5Foperations >=20 So let me show how things work currently. fd =3D open("/dev/vtpmx", ...); ioctl(fd, 'create device pair; TPM will be a TPM 2 version device') /* conveying that the device is a TPM 2 or 1.2 is important so that the=20 kernel sends the right commands to the device and possibly also for sysfs=20 handling */ /* at this point /dev/vtpmc0 and /dev/vtpms0 have been created */ clientfd =3D open("/dev/vtpmc0",...) serverfd =3D open("/dev/vtpms0",...); ... close(serverfd); /* /dev/vtpmc0 and /dev/vtpms0 disappeared */ Should it work like this? serverfd =3D open("/dev/vtpmx", ...); /* at this point /dev/vtpmc0 has been created and serverfd is used for the = server side */ ioctl(fd, 'TPM will be a TPM 2 version device') /* setting flags on the=20 chip->flags 'late' should be possible */ ... close(serverfd); /* /dev/vtpmc0 disappeared */ Regards, Stefan > > > auto-delete a master char dev on close is a very strange API, don't=20 do > > > that. > >=20 > > What I called cleanup can be trigger by the vTPM closing /dev/ > vtpms%d, so the > > server-side. What is the master for you? /dev/vtpmx where we run=20 > the ioctls on? >=20 > Sorry, master/slave is the ptx nomenclature for this scheme. Master > would be your server side I think.=20 >=20 > Jason >=20 --=_alternative 006895CA85257F41_= Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="US-ASCII" Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org> wrote on 01/21/2016 12:42:43 PM:

>
> On Wed, Jan 20, 2016 = at 10:56:21PM -0500, Stefan Berger wrote:
> > The IMA namespace is= created as part of clone(). You cannot pass
> anything via
> > clone(). So you either have to do it bef= ore or immediately after.
> If after is
> > too later for whatever reason, you have t= o do it before.
>
> Follow the pattern of something like the n= et ns.
>
> clone creates an 'empty' IMA namespace. After clone= the child waits
> for the parent to complete its work.
>
&= gt; The parent creates a new vtpm /dev/tpm1 in it's namespace
>
&= gt; The parent does a kernel call to make tpm1 visiable in the child's
&= gt; IMA namespace as tpm0. (eg look at the 'ip link set .. netns ..' kind> of scheme for inspiration)


Wha= t is IMA namespace in relation to a device's name? The method is to read the major/minor numbers on the host and created /dev/= tpm0 with the same major/minor numbers in the container's filesystem. The name doesn't matter I guess, but major/minor are important.
<= font size=3D2>
>
> Hook the tpm core's id to struct tpm=5Fchip= code into the IMA namespace
> so that /dev/tpm0 and all other places= actually access tpm1 when used
> in the child's IMA namespace
>= ;
> The parent signals the child to continue to run. The child has a=
> /dev/tpm0 that is actually routed to /dev/tpm1. The child is preve= nted
> from accessing other tpms.



The problem I have run into in particular with Docker and golang is that Docker invokes the golang function to run an external program. The golang function does a clone(), a whole lot of other stuff after it, and in the end the execve().

The code is here:

https://golang.org/src= /syscall/exec=5Flinux.go

Look at = the function forkAndExecInChild<= tt>on line 56++.

The p= roblem with that is that the execve() will trigger IMA measurements. IMA will refuse being hooked up with a vTPM driver if it couldn't put its first measurement(s) into a vTPM. I don't think we should queue PCR extensions until a device may eventually become available. So, the conclusion is, to accomodate golang (for example) we can create the device pair, sit the vTPM on top of the master, and reserve the device pair befor the next clone() so that IMA finds it and can hook up to it.

What is wrong with this scheme? The = ioctl for 'reservation' before the clone()?


>
>=
> > > Then just return the fd like I said.
> >
&= gt; > Any driver that can be used as an example ?
>
> The s= tuff in include/linux/anon=5Finodes.h is used to do this, eg
> a sequ= ence of anon=5Finode=5Fgetfile, get=5Funused=5Ffd=5Fflags, fd=5Finstall
= > will create a file descriptor in the calling process associated with a
> struct file=5Foperations
>


So let me show how things work currently.

fd =3D open("/dev/vtpmx", ...);
ioctl(fd, 'create device pair; TPM will be a TPM 2 version device')
/* conveying that the de= vice is a TPM 2 or 1.2 is important so that the kernel sends the right commands to the device and possibly also for sysfs handling */

/= * at this point /dev/vtpmc0 and /dev/vtpms0 have been created */
clientfd =3D open("/= dev/vtpmc0",...)
serverfd =3D open(&= quot;/dev/vtpms0",...);

...

close(serverfd); /* /dev/vtpmc0 and /dev/= vtpms0 disappeared */




Should it work like th= is?

serverfd =3D open("/dev/vtpm= x", ...);
/* at this point /dev/vtpm= c0 has been created and serverfd is used for the server side */

ioctl(fd, 'TPM will be a TPM 2 version device') /* setting flags on the chip->flags 'late' should be possible */

...

close= (serverfd); /* /dev/vtpmc0 disappeared */


Regards,
   Stefan


> > > auto-delete a master = char dev on close is a very strange API, don't do
> > > that.
> >
> > What I cal= led cleanup can be trigger by the vTPM closing /dev/
> vtpms%d, so th= e
> > server-side. What is the master for you? /dev/vtpmx where we run
> the ioctls on?
>
> Sorry, master/slave is the ptx= nomenclature for this scheme. Master
> would be your server side I t= hink.
>
> Jason
>

--=_alternative 006895CA85257F41_=-- --===============7396022361502378255== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------------ Site24x7 APM Insight: Get Deep Visibility into Application Performance APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month Monitor end-to-end web transactions and take corrective actions now Troubleshoot faster and improve end-user experience. Signup Now! http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140 --===============7396022361502378255== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ tpmdd-devel mailing list tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org https://lists.sourceforge.net/lists/listinfo/tpmdd-devel --===============7396022361502378255==--