From: Rajiv Andrade <srajiv@linux.vnet.ibm.com>
To: Mimi Zohar <zohar@linux.vnet.ibm.com>
Cc: Tim Gardner <tim.gardner@canonical.com>,
Seth Forshee <seth.forshee@canonical.com>,
tpmdd-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org,
Marcel Selhorst <m.selhorst@sirrix.com>
Subject: Re: [tpmdd-devel] [PATCH 2/3] TPM: Close data_pending and data_buffer races
Date: Wed, 11 Jan 2012 17:43:31 -0200 [thread overview]
Message-ID: <20120111194331.GB12299@hardened-box.br.ibm.com> (raw)
In-Reply-To: <1325016165.2313.45.camel@falcor>
On Tue, 27 Dec 2011, Mimi Zohar wrote:
> On Fri, 2011-12-23 at 07:25 -0700, Tim Gardner wrote:
> > On 12/22/2011 01:02 PM, Rajiv Andrade wrote:
>
> <snip>
>
> > > It's inside the mutex region.
> > >
> >
> > Actually, the patch you sent (https://lkml.org/lkml/2011/12/22/257) is
> > _outside_ the mutex area, but I got your drift.
>
> Yes, thanks for pointing it out in your original comments. I haven't
> tested the following patch, but perhaps it will help clarify the updated
> version, that I think Rajiv was describing ...
>
That's exactly it Mimi, thanks for writing down the patch.
> diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
> index 6a8771f..7dafd95 100644
> --- a/drivers/char/tpm/tpm.c
> +++ b/drivers/char/tpm/tpm.c
> @@ -1210,7 +1210,6 @@ ssize_t tpm_read(struct file *file, char __user *buf,
> del_singleshot_timer_sync(&chip->user_read_timer);
> flush_work_sync(&chip->work);
> ret_size = atomic_read(&chip->data_pending);
> - atomic_set(&chip->data_pending, 0);
> if (ret_size > 0) { /* relay data */
> if (size < ret_size)
> ret_size = size;
> @@ -1221,8 +1220,10 @@ ssize_t tpm_read(struct file *file, char __user *buf,
> if (rc)
> ret_size = -EFAULT;
>
> + atomic_set(&chip->data_pending, 0);
> mutex_unlock(&chip->buffer_mutex);
> - }
> + } else if (ret_size < 0)
> + atomic_set(&chip->data_pending, 0);
>
> return ret_size;
> }
Tim, do you still see a race with the changes posted above?
Rajiv
>
> > Even clearing chip->data_pending _inside_ the mutex area, I'm not sure
> > it closes all of the race windows. I think its still possible to race
> > with mod_timer() and del_singleshot_timer_sync(). Therein lies my point,
> > if the exclusion code is not _obviously_ correct for something this
> > simple, then its probably not. I think my patch is the correct approach.
>
> With the above patch, tpm_read() resets the data_pending flag only after
> copying the data to userspace, resolving the original race condition
> described.
>
> > > This would require another fix though. tpm_write() doesn't check
> > > tpm_transmit return code (and it should).
> > > In case it returns an error (< 0), chip->data_pending would remain the
> > > same forever with that change.
> > >
> >
> > This observation is also correct, but not relevant to the exclusion
> > races. It deserves a separate patch.
>
> With the above patch, tpm_read() resets the data_pending flag only if
> set, resolving the other race condition(s).
>
> thanks,
>
> Mimi
>
next prev parent reply other threads:[~2012-01-11 19:45 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-06 18:29 [PATCH 0/3] TPM: CVE patch, close a race, atomic cleanup Tim Gardner
2011-12-06 18:29 ` [PATCH 1/3] TPM: Zero buffer whole after copying to userspace Tim Gardner
2012-02-03 17:39 ` Rajiv Andrade
2011-12-06 18:29 ` [PATCH 2/3] TPM: Close data_pending and data_buffer races Tim Gardner
2011-12-20 16:38 ` Rajiv Andrade
2011-12-20 19:39 ` Tim Gardner
2011-12-22 17:42 ` Rajiv Andrade
2011-12-22 18:44 ` Tim Gardner
2011-12-22 20:02 ` Rajiv Andrade
2011-12-23 14:25 ` Tim Gardner
2011-12-27 20:02 ` [tpmdd-devel] " Mimi Zohar
2012-01-11 19:43 ` Rajiv Andrade [this message]
2012-07-25 17:36 ` Kent Yoder
2011-12-06 18:29 ` [PATCH 3/3] TPM: data_pending is no longer atomic Tim Gardner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120111194331.GB12299@hardened-box.br.ibm.com \
--to=srajiv@linux.vnet.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=m.selhorst@sirrix.com \
--cc=seth.forshee@canonical.com \
--cc=tim.gardner@canonical.com \
--cc=tpmdd-devel@lists.sourceforge.net \
--cc=zohar@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®